@lightningjs/renderer 3.0.0-beta2 → 3.0.0-beta4
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/COPYING +1 -0
- package/LICENSE +202 -202
- package/NOTICE +3 -3
- package/README.md +147 -147
- package/dist/exports/index.d.ts +1 -0
- package/dist/exports/index.js +1 -0
- package/dist/exports/index.js.map +1 -1
- package/dist/src/core/CoreNode.d.ts +3 -2
- package/dist/src/core/CoreNode.js +13 -7
- package/dist/src/core/CoreNode.js.map +1 -1
- package/dist/src/core/CoreShaderManager.d.ts +3 -5
- package/dist/src/core/CoreShaderManager.js.map +1 -1
- package/dist/src/core/CoreTextNode.d.ts +2 -0
- package/dist/src/core/CoreTextNode.js +7 -0
- package/dist/src/core/CoreTextNode.js.map +1 -1
- package/dist/src/core/CoreTextureManager.d.ts +2 -0
- package/dist/src/core/CoreTextureManager.js +7 -5
- package/dist/src/core/CoreTextureManager.js.map +1 -1
- package/dist/src/core/Stage.d.ts +5 -0
- package/dist/src/core/Stage.js +10 -5
- package/dist/src/core/Stage.js.map +1 -1
- package/dist/src/core/lib/validateImageBitmap.d.ts +2 -1
- package/dist/src/core/lib/validateImageBitmap.js +4 -4
- package/dist/src/core/lib/validateImageBitmap.js.map +1 -1
- package/dist/src/core/platforms/Platform.d.ts +37 -0
- package/dist/src/{main-api/IRenderDriver.js → core/platforms/Platform.js} +4 -2
- package/dist/src/core/platforms/Platform.js.map +1 -0
- package/dist/src/core/platforms/web/WebPlatform.d.ts +9 -0
- package/dist/src/core/platforms/web/WebPlatform.js +58 -0
- package/dist/src/core/platforms/web/WebPlatform.js.map +1 -0
- package/dist/src/core/renderers/CoreRenderer.d.ts +3 -1
- package/dist/src/core/renderers/CoreRenderer.js.map +1 -1
- package/dist/src/core/renderers/CoreShaderNode.d.ts +1 -1
- package/dist/src/core/renderers/CoreShaderNode.js.map +1 -1
- package/dist/src/core/renderers/canvas/CanvasRenderer.js.map +1 -1
- package/dist/src/core/renderers/webgl/WebGlRenderer.d.ts +3 -1
- package/dist/src/core/renderers/webgl/WebGlRenderer.js +86 -60
- package/dist/src/core/renderers/webgl/WebGlRenderer.js.map +1 -1
- package/dist/src/core/renderers/webgl/internal/ShaderUtils.js +35 -35
- package/dist/src/core/renderers/webgl/shaders/DefaultShader.js +45 -45
- package/dist/src/core/renderers/webgl/shaders/DefaultShaderBatched.js +61 -61
- package/dist/src/core/renderers/webgl/shaders/DynamicShader.js +93 -93
- package/dist/src/core/renderers/webgl/shaders/RoundedRectangle.js +63 -63
- package/dist/src/core/renderers/webgl/shaders/SdfShader.js +62 -62
- package/dist/src/core/renderers/webgl/shaders/effects/BorderBottomEffect.js +15 -15
- package/dist/src/core/renderers/webgl/shaders/effects/BorderEffect.js +6 -6
- package/dist/src/core/renderers/webgl/shaders/effects/BorderLeftEffect.js +15 -15
- package/dist/src/core/renderers/webgl/shaders/effects/BorderRightEffect.js +15 -15
- package/dist/src/core/renderers/webgl/shaders/effects/BorderTopEffect.js +15 -15
- package/dist/src/core/renderers/webgl/shaders/effects/FadeOutEffect.js +42 -42
- package/dist/src/core/renderers/webgl/shaders/effects/GlitchEffect.js +44 -44
- package/dist/src/core/renderers/webgl/shaders/effects/GrayscaleEffect.js +3 -3
- package/dist/src/core/renderers/webgl/shaders/effects/HolePunchEffect.js +22 -22
- package/dist/src/core/renderers/webgl/shaders/effects/LinearGradientEffect.js +28 -28
- package/dist/src/core/renderers/webgl/shaders/effects/RadialGradientEffect.js +10 -10
- package/dist/src/core/renderers/webgl/shaders/effects/RadialProgressEffect.js +37 -37
- package/dist/src/core/renderers/webgl/shaders/effects/RadiusEffect.js +19 -19
- package/dist/src/core/shaders/webgl/Border.js +59 -59
- package/dist/src/core/shaders/webgl/Default.js +47 -47
- package/dist/src/core/shaders/webgl/DefaultBatched.js +61 -61
- package/dist/src/core/shaders/webgl/HolePunch.js +32 -32
- package/dist/src/core/shaders/webgl/LinearGradient.js +36 -36
- package/dist/src/core/shaders/webgl/RadialGradient.js +33 -33
- package/dist/src/core/shaders/webgl/Rounded.js +71 -71
- package/dist/src/core/shaders/webgl/RoundedWithBorder.js +66 -66
- package/dist/src/core/shaders/webgl/RoundedWithBorderAndShadow.js +79 -79
- package/dist/src/core/shaders/webgl/RoundedWithShadow.js +54 -54
- package/dist/src/core/shaders/webgl/SdfShader.js +62 -62
- package/dist/src/core/shaders/webgl/Shadow.js +83 -83
- package/dist/src/core/temp.js +77 -0
- package/dist/src/core/temp.js.map +1 -0
- package/dist/src/core/text-rendering/renderers/CanvasTextRenderer.js +5 -0
- package/dist/src/core/text-rendering/renderers/CanvasTextRenderer.js.map +1 -1
- package/dist/src/core/text-rendering/renderers/LightningTextTextureRenderer.d.ts +1 -1
- package/dist/src/core/text-rendering/renderers/LightningTextTextureRenderer.js +50 -2
- package/dist/src/core/text-rendering/renderers/LightningTextTextureRenderer.js.map +1 -1
- package/dist/src/core/text-rendering/renderers/SdfTextRenderer/SdfTextRenderer.js +6 -2
- package/dist/src/core/text-rendering/renderers/SdfTextRenderer/SdfTextRenderer.js.map +1 -1
- package/dist/src/core/text-rendering/renderers/SdfTextRenderer/internal/layoutText.d.ts +1 -1
- package/dist/src/core/text-rendering/renderers/SdfTextRenderer/internal/layoutText.js +66 -8
- package/dist/src/core/text-rendering/renderers/SdfTextRenderer/internal/layoutText.js.map +1 -1
- package/dist/src/core/text-rendering/renderers/TextRenderer.d.ts +13 -0
- package/dist/src/core/text-rendering/renderers/TextRenderer.js +3 -0
- package/dist/src/core/text-rendering/renderers/TextRenderer.js.map +1 -1
- package/dist/src/core/textures/ImageTexture.d.ts +1 -0
- package/dist/src/core/textures/ImageTexture.js +5 -3
- package/dist/src/core/textures/ImageTexture.js.map +1 -1
- package/dist/src/core/textures/Texture.d.ts +9 -2
- package/dist/src/core/textures/Texture.js +18 -6
- package/dist/src/core/textures/Texture.js.map +1 -1
- package/dist/src/main-api/INode.d.ts +2 -2
- package/dist/src/main-api/Renderer.d.ts +13 -1
- package/dist/src/main-api/Renderer.js +14 -2
- package/dist/src/main-api/Renderer.js.map +1 -1
- package/dist/tsconfig.dist.tsbuildinfo +1 -1
- package/exports/canvas-shaders.ts +28 -28
- package/exports/canvas.ts +45 -45
- package/exports/index.ts +90 -89
- package/exports/inspector.ts +24 -24
- package/exports/utils.ts +44 -44
- package/exports/webgl-shaders.ts +28 -28
- package/exports/webgl.ts +50 -50
- package/package.json +2 -3
- package/scripts/please-use-pnpm.js +13 -13
- package/src/common/CommonTypes.ts +146 -146
- package/src/common/EventEmitter.ts +77 -77
- package/src/common/IAnimationController.ts +92 -92
- package/src/common/IEventEmitter.ts +28 -28
- package/src/core/CoreNode.test.ts +203 -203
- package/src/core/CoreNode.ts +2494 -2486
- package/src/core/CoreShaderManager.ts +188 -193
- package/src/core/CoreTextNode.ts +448 -439
- package/src/core/CoreTextureManager.ts +601 -597
- package/src/core/Stage.ts +754 -738
- package/src/core/TextureMemoryManager.ts +395 -395
- package/src/core/animations/AnimationManager.ts +38 -38
- package/src/core/animations/CoreAnimation.ts +284 -284
- package/src/core/animations/CoreAnimationController.ts +157 -157
- package/src/core/lib/ContextSpy.ts +41 -41
- package/src/core/lib/ImageWorker.ts +280 -280
- package/src/core/lib/Matrix3d.ts +244 -244
- package/src/core/lib/RenderCoords.ts +71 -71
- package/src/core/lib/WebGlContextWrapper.ts +1374 -1374
- package/src/core/lib/textureCompression.ts +152 -152
- package/src/core/lib/textureSvg.ts +78 -78
- package/src/core/lib/utils.ts +386 -386
- package/src/core/lib/validateImageBitmap.ts +87 -76
- package/src/core/platform.ts +64 -64
- package/src/core/platforms/Platform.ts +77 -0
- package/src/core/platforms/web/WebPlatform.ts +84 -0
- package/src/core/renderers/CoreContextTexture.ts +43 -43
- package/src/core/renderers/CoreRenderOp.ts +22 -22
- package/src/core/renderers/CoreRenderer.ts +109 -107
- package/src/core/renderers/CoreShaderNode.ts +165 -167
- package/src/core/renderers/CoreShaderProgram.ts +23 -23
- package/src/core/renderers/canvas/CanvasRenderer.ts +298 -298
- package/src/core/renderers/canvas/CanvasShaderNode.ts +99 -99
- package/src/core/renderers/canvas/CanvasTexture.ts +156 -156
- package/src/core/renderers/canvas/internal/C2DShaderUtils.ts +220 -220
- package/src/core/renderers/canvas/internal/ColorUtils.ts +85 -85
- package/src/core/renderers/webgl/WebGlCtxRenderTexture.ts +86 -86
- package/src/core/renderers/webgl/WebGlCtxSubTexture.ts +50 -50
- package/src/core/renderers/webgl/WebGlCtxTexture.ts +301 -301
- package/src/core/renderers/webgl/WebGlRenderOp.ts +161 -161
- package/src/core/renderers/webgl/WebGlRenderer.ts +750 -720
- package/src/core/renderers/webgl/WebGlShaderNode.ts +437 -437
- package/src/core/renderers/webgl/WebGlShaderProgram.ts +318 -318
- package/src/core/renderers/webgl/internal/BufferCollection.ts +54 -54
- package/src/core/renderers/webgl/internal/RendererUtils.ts +155 -155
- package/src/core/renderers/webgl/internal/ShaderUtils.ts +281 -281
- package/src/core/renderers/webgl/internal/WebGlUtils.ts +35 -35
- package/src/core/shaders/canvas/Border.ts +78 -78
- package/src/core/shaders/canvas/HolePunch.ts +62 -62
- package/src/core/shaders/canvas/LinearGradient.ts +69 -69
- package/src/core/shaders/canvas/RadialGradient.ts +113 -113
- package/src/core/shaders/canvas/Rounded.ts +55 -55
- package/src/core/shaders/canvas/RoundedWithBorder.ts +68 -68
- package/src/core/shaders/canvas/RoundedWithBorderAndShadow.ts +88 -88
- package/src/core/shaders/canvas/RoundedWithShadow.ts +69 -69
- package/src/core/shaders/canvas/Shadow.ts +52 -52
- package/src/core/shaders/canvas/utils/render.ts +151 -151
- package/src/core/shaders/templates/BorderTemplate.ts +115 -115
- package/src/core/shaders/templates/HolePunchTemplate.ts +82 -82
- package/src/core/shaders/templates/LinearGradientTemplate.ts +71 -71
- package/src/core/shaders/templates/RadialGradientTemplate.ts +81 -81
- package/src/core/shaders/templates/RoundedTemplate.ts +98 -98
- package/src/core/shaders/templates/RoundedWithBorderAndShadowTemplate.ts +38 -38
- package/src/core/shaders/templates/RoundedWithBorderTemplate.ts +35 -35
- package/src/core/shaders/templates/RoundedWithShadowTemplate.ts +35 -35
- package/src/core/shaders/templates/ShadowTemplate.ts +106 -106
- package/src/core/shaders/templates/shaderUtils.ts +47 -47
- package/src/core/shaders/webgl/Border.ts +96 -96
- package/src/core/shaders/webgl/Default.ts +89 -89
- package/src/core/shaders/webgl/DefaultBatched.ts +129 -129
- package/src/core/shaders/webgl/HolePunch.ts +78 -78
- package/src/core/shaders/webgl/LinearGradient.ts +81 -81
- package/src/core/shaders/webgl/RadialGradient.ts +84 -84
- package/src/core/shaders/webgl/Rounded.ts +117 -117
- package/src/core/shaders/webgl/RoundedWithBorder.ts +114 -114
- package/src/core/shaders/webgl/RoundedWithBorderAndShadow.ts +133 -133
- package/src/core/shaders/webgl/RoundedWithShadow.ts +98 -98
- package/src/core/shaders/webgl/SdfShader.ts +134 -134
- package/src/core/shaders/webgl/Shadow.ts +115 -115
- package/src/core/text-rendering/TextRenderingUtils.ts +36 -36
- package/src/core/text-rendering/TextTextureRendererUtils.ts +263 -263
- package/src/core/text-rendering/TrFontManager.ts +183 -183
- package/src/core/text-rendering/font-face-types/SdfTrFontFace/SdfTrFontFace.ts +176 -176
- package/src/core/text-rendering/font-face-types/SdfTrFontFace/internal/FontShaper.ts +139 -139
- package/src/core/text-rendering/font-face-types/SdfTrFontFace/internal/SdfFontShaper.test.ts +173 -173
- package/src/core/text-rendering/font-face-types/SdfTrFontFace/internal/SdfFontShaper.ts +171 -171
- package/src/core/text-rendering/font-face-types/TrFontFace.ts +187 -187
- package/src/core/text-rendering/font-face-types/WebTrFontFace.ts +94 -94
- package/src/core/text-rendering/font-face-types/utils.ts +39 -39
- package/src/core/text-rendering/renderers/CanvasTextRenderer.ts +514 -509
- package/src/core/text-rendering/renderers/LightningTextTextureRenderer.ts +863 -815
- package/src/core/text-rendering/renderers/SdfTextRenderer/SdfTextRenderer.ts +846 -840
- package/src/core/text-rendering/renderers/SdfTextRenderer/internal/PeekableGenerator.test.ts +48 -48
- package/src/core/text-rendering/renderers/SdfTextRenderer/internal/PeekableGenerator.ts +66 -66
- package/src/core/text-rendering/renderers/SdfTextRenderer/internal/SpecialCodepoints.ts +52 -52
- package/src/core/text-rendering/renderers/SdfTextRenderer/internal/constants.ts +32 -32
- package/src/core/text-rendering/renderers/SdfTextRenderer/internal/getStartConditions.ts +117 -117
- package/src/core/text-rendering/renderers/SdfTextRenderer/internal/getUnicodeCodepoints.test.ts +133 -133
- package/src/core/text-rendering/renderers/SdfTextRenderer/internal/getUnicodeCodepoints.ts +38 -38
- package/src/core/text-rendering/renderers/SdfTextRenderer/internal/layoutText.ts +497 -408
- package/src/core/text-rendering/renderers/SdfTextRenderer/internal/measureText.test.ts +49 -49
- package/src/core/text-rendering/renderers/SdfTextRenderer/internal/measureText.ts +52 -52
- package/src/core/text-rendering/renderers/SdfTextRenderer/internal/setRenderWindow.test.ts +205 -205
- package/src/core/text-rendering/renderers/SdfTextRenderer/internal/setRenderWindow.ts +93 -93
- package/src/core/text-rendering/renderers/SdfTextRenderer/internal/util.ts +40 -40
- package/src/core/text-rendering/renderers/TextRenderer.ts +567 -550
- package/src/core/textures/ColorTexture.ts +102 -102
- package/src/core/textures/ImageTexture.ts +410 -399
- package/src/core/textures/NoiseTexture.ts +104 -104
- package/src/core/textures/RenderTexture.ts +85 -85
- package/src/core/textures/SubTexture.ts +205 -205
- package/src/core/textures/Texture.ts +358 -337
- package/src/core/utils.ts +227 -227
- package/src/env.d.ts +7 -7
- package/src/main-api/INode.ts +100 -99
- package/src/main-api/Inspector.ts +522 -522
- package/src/main-api/Renderer.ts +675 -649
- package/src/main-api/utils.ts +45 -45
- package/src/utils.ts +267 -267
- package/dist/exports/core-api.d.ts +0 -74
- package/dist/exports/core-api.js +0 -96
- package/dist/exports/core-api.js.map +0 -1
- package/dist/exports/main-api.d.ts +0 -30
- package/dist/exports/main-api.js +0 -45
- package/dist/exports/main-api.js.map +0 -1
- package/dist/src/core/CoreExtension.d.ts +0 -12
- package/dist/src/core/CoreExtension.js +0 -29
- package/dist/src/core/CoreExtension.js.map +0 -1
- package/dist/src/core/CoreStuff.js +0 -138
- package/dist/src/core/CoreStuff.js.map +0 -1
- package/dist/src/core/CoreTexturizer.d.ts +0 -14
- package/dist/src/core/CoreTexturizer.js +0 -47
- package/dist/src/core/CoreTexturizer.js.map +0 -1
- package/dist/src/core/LngNode.d.ts +0 -736
- package/dist/src/core/LngNode.js +0 -1174
- package/dist/src/core/LngNode.js.map +0 -1
- package/dist/src/core/Matrix2DContext.d.ts +0 -15
- package/dist/src/core/Matrix2DContext.js +0 -45
- package/dist/src/core/Matrix2DContext.js.map +0 -1
- package/dist/src/core/ShaderNode.d.ts +0 -10
- package/dist/src/core/ShaderNode.js +0 -30
- package/dist/src/core/ShaderNode.js.map +0 -1
- package/dist/src/core/TextNode.d.ts +0 -103
- package/dist/src/core/TextNode.js +0 -331
- package/dist/src/core/TextNode.js.map +0 -1
- package/dist/src/core/lib/Coords.d.ts +0 -14
- package/dist/src/core/lib/Coords.js +0 -55
- package/dist/src/core/lib/Coords.js.map +0 -1
- package/dist/src/core/lib/glm/common.d.ts +0 -162
- package/dist/src/core/lib/glm/common.js +0 -81
- package/dist/src/core/lib/glm/common.js.map +0 -1
- package/dist/src/core/lib/glm/index.d.ts +0 -11
- package/dist/src/core/lib/glm/index.js +0 -30
- package/dist/src/core/lib/glm/index.js.map +0 -1
- package/dist/src/core/lib/glm/mat2.d.ts +0 -219
- package/dist/src/core/lib/glm/mat2.js +0 -396
- package/dist/src/core/lib/glm/mat2.js.map +0 -1
- package/dist/src/core/lib/glm/mat2d.d.ts +0 -237
- package/dist/src/core/lib/glm/mat2d.js +0 -442
- package/dist/src/core/lib/glm/mat2d.js.map +0 -1
- package/dist/src/core/lib/glm/mat3.d.ts +0 -283
- package/dist/src/core/lib/glm/mat3.js +0 -680
- package/dist/src/core/lib/glm/mat3.js.map +0 -1
- package/dist/src/core/lib/glm/mat4.d.ts +0 -550
- package/dist/src/core/lib/glm/mat4.js +0 -1802
- package/dist/src/core/lib/glm/mat4.js.map +0 -1
- package/dist/src/core/lib/glm/quat.d.ts +0 -363
- package/dist/src/core/lib/glm/quat.js +0 -693
- package/dist/src/core/lib/glm/quat.js.map +0 -1
- package/dist/src/core/lib/glm/quat2.d.ts +0 -356
- package/dist/src/core/lib/glm/quat2.js +0 -754
- package/dist/src/core/lib/glm/quat2.js.map +0 -1
- package/dist/src/core/lib/glm/vec2.d.ts +0 -365
- package/dist/src/core/lib/glm/vec2.js +0 -569
- package/dist/src/core/lib/glm/vec2.js.map +0 -1
- package/dist/src/core/lib/glm/vec3.d.ts +0 -406
- package/dist/src/core/lib/glm/vec3.js +0 -720
- package/dist/src/core/lib/glm/vec3.js.map +0 -1
- package/dist/src/core/lib/glm/vec4.d.ts +0 -330
- package/dist/src/core/lib/glm/vec4.js +0 -608
- package/dist/src/core/lib/glm/vec4.js.map +0 -1
- package/dist/src/core/renderers/CoreShaderManager.d.ts +0 -19
- package/dist/src/core/renderers/CoreShaderManager.js +0 -33
- package/dist/src/core/renderers/CoreShaderManager.js.map +0 -1
- package/dist/src/core/renderers/webgl/WebGlCoreShaderManager.d.ts +0 -27
- package/dist/src/core/renderers/webgl/WebGlCoreShaderManager.js +0 -82
- package/dist/src/core/renderers/webgl/WebGlCoreShaderManager.js.map +0 -1
- package/dist/src/core/renderers/webgl/WebGlCoreShaderProgram.d.ts +0 -11
- package/dist/src/core/renderers/webgl/WebGlCoreShaderProgram.js +0 -34
- package/dist/src/core/renderers/webgl/WebGlCoreShaderProgram.js.map +0 -1
- package/dist/src/core/scene/Scene.d.ts +0 -59
- package/dist/src/core/scene/Scene.js +0 -106
- package/dist/src/core/scene/Scene.js.map +0 -1
- package/dist/src/core/text-rendering/renderers/SdfTextRenderer/internal/makeRenderWindow.d.ts +0 -20
- package/dist/src/core/text-rendering/renderers/SdfTextRenderer/internal/makeRenderWindow.js +0 -55
- package/dist/src/core/text-rendering/renderers/SdfTextRenderer/internal/makeRenderWindow.js.map +0 -1
- package/dist/src/main-api/ICoreDriver.d.ts +0 -27
- package/dist/src/main-api/ICoreDriver.js +0 -20
- package/dist/src/main-api/ICoreDriver.js.map +0 -1
- package/dist/src/main-api/IRenderDriver.d.ts +0 -20
- package/dist/src/main-api/IRenderDriver.js.map +0 -1
- package/dist/src/main-api/IShaderController.d.ts +0 -14
- package/dist/src/main-api/IShaderController.js +0 -30
- package/dist/src/main-api/IShaderController.js.map +0 -1
- package/dist/src/main-api/IShaderNode.d.ts +0 -17
- package/dist/src/main-api/IShaderNode.js +0 -19
- package/dist/src/main-api/IShaderNode.js.map +0 -1
- package/dist/src/main-api/RendererMain.d.ts +0 -375
- package/dist/src/main-api/RendererMain.js +0 -365
- package/dist/src/main-api/RendererMain.js.map +0 -1
- package/dist/src/main-api/texture-usage-trackers/FinalizationRegistryTextureUsageTracker.d.ts +0 -9
- package/dist/src/main-api/texture-usage-trackers/FinalizationRegistryTextureUsageTracker.js +0 -38
- package/dist/src/main-api/texture-usage-trackers/FinalizationRegistryTextureUsageTracker.js.map +0 -1
- package/dist/src/main-api/texture-usage-trackers/ManualCountTextureUsageTracker.d.ts +0 -56
- package/dist/src/main-api/texture-usage-trackers/ManualCountTextureUsageTracker.js +0 -101
- package/dist/src/main-api/texture-usage-trackers/ManualCountTextureUsageTracker.js.map +0 -1
- package/dist/src/main-api/texture-usage-trackers/TextureUsageTracker.d.ts +0 -32
- package/dist/src/main-api/texture-usage-trackers/TextureUsageTracker.js +0 -28
- package/dist/src/main-api/texture-usage-trackers/TextureUsageTracker.js.map +0 -1
- package/dist/src/render-drivers/main/MainCoreDriver.d.ts +0 -24
- package/dist/src/render-drivers/main/MainCoreDriver.js +0 -118
- package/dist/src/render-drivers/main/MainCoreDriver.js.map +0 -1
- package/dist/src/render-drivers/main/MainOnlyNode.d.ts +0 -99
- package/dist/src/render-drivers/main/MainOnlyNode.js +0 -396
- package/dist/src/render-drivers/main/MainOnlyNode.js.map +0 -1
- package/dist/src/render-drivers/main/MainOnlyShaderController.d.ts +0 -6
- package/dist/src/render-drivers/main/MainOnlyShaderController.js +0 -15
- package/dist/src/render-drivers/main/MainOnlyShaderController.js.map +0 -1
- package/dist/src/render-drivers/main/MainOnlyShaderNode.d.ts +0 -7
- package/dist/src/render-drivers/main/MainOnlyShaderNode.js +0 -34
- package/dist/src/render-drivers/main/MainOnlyShaderNode.js.map +0 -1
- package/dist/src/render-drivers/main/MainOnlyTextNode.d.ts +0 -47
- package/dist/src/render-drivers/main/MainOnlyTextNode.js +0 -205
- package/dist/src/render-drivers/main/MainOnlyTextNode.js.map +0 -1
- package/dist/src/render-drivers/main/MainRenderDriver.d.ts +0 -17
- package/dist/src/render-drivers/main/MainRenderDriver.js +0 -88
- package/dist/src/render-drivers/main/MainRenderDriver.js.map +0 -1
- package/dist/src/render-drivers/threadx/NodeStruct.d.ts +0 -90
- package/dist/src/render-drivers/threadx/NodeStruct.js +0 -281
- package/dist/src/render-drivers/threadx/NodeStruct.js.map +0 -1
- package/dist/src/render-drivers/threadx/SharedNode.d.ts +0 -39
- package/dist/src/render-drivers/threadx/SharedNode.js +0 -60
- package/dist/src/render-drivers/threadx/SharedNode.js.map +0 -1
- package/dist/src/render-drivers/threadx/TextNodeStruct.d.ts +0 -44
- package/dist/src/render-drivers/threadx/TextNodeStruct.js +0 -201
- package/dist/src/render-drivers/threadx/TextNodeStruct.js.map +0 -1
- package/dist/src/render-drivers/threadx/ThreadXCoreDriver.d.ts +0 -28
- package/dist/src/render-drivers/threadx/ThreadXCoreDriver.js +0 -234
- package/dist/src/render-drivers/threadx/ThreadXCoreDriver.js.map +0 -1
- package/dist/src/render-drivers/threadx/ThreadXMainAnimationController.d.ts +0 -20
- package/dist/src/render-drivers/threadx/ThreadXMainAnimationController.js +0 -84
- package/dist/src/render-drivers/threadx/ThreadXMainAnimationController.js.map +0 -1
- package/dist/src/render-drivers/threadx/ThreadXMainNode.d.ts +0 -44
- package/dist/src/render-drivers/threadx/ThreadXMainNode.js +0 -154
- package/dist/src/render-drivers/threadx/ThreadXMainNode.js.map +0 -1
- package/dist/src/render-drivers/threadx/ThreadXMainShaderController.d.ts +0 -6
- package/dist/src/render-drivers/threadx/ThreadXMainShaderController.js +0 -16
- package/dist/src/render-drivers/threadx/ThreadXMainShaderController.js.map +0 -1
- package/dist/src/render-drivers/threadx/ThreadXMainShaderNode.d.ts +0 -7
- package/dist/src/render-drivers/threadx/ThreadXMainShaderNode.js +0 -15
- package/dist/src/render-drivers/threadx/ThreadXMainShaderNode.js.map +0 -1
- package/dist/src/render-drivers/threadx/ThreadXMainTextNode.d.ts +0 -28
- package/dist/src/render-drivers/threadx/ThreadXMainTextNode.js +0 -55
- package/dist/src/render-drivers/threadx/ThreadXMainTextNode.js.map +0 -1
- package/dist/src/render-drivers/threadx/ThreadXRenderDriver.d.ts +0 -21
- package/dist/src/render-drivers/threadx/ThreadXRenderDriver.js +0 -198
- package/dist/src/render-drivers/threadx/ThreadXRenderDriver.js.map +0 -1
- package/dist/src/render-drivers/threadx/ThreadXRendererMessage.d.ts +0 -70
- package/dist/src/render-drivers/threadx/ThreadXRendererMessage.js +0 -32
- package/dist/src/render-drivers/threadx/ThreadXRendererMessage.js.map +0 -1
- package/dist/src/render-drivers/threadx/worker/ThreadXRendererNode.d.ts +0 -19
- package/dist/src/render-drivers/threadx/worker/ThreadXRendererNode.js +0 -177
- package/dist/src/render-drivers/threadx/worker/ThreadXRendererNode.js.map +0 -1
- package/dist/src/render-drivers/threadx/worker/ThreadXRendererTextNode.d.ts +0 -27
- package/dist/src/render-drivers/threadx/worker/ThreadXRendererTextNode.js +0 -108
- package/dist/src/render-drivers/threadx/worker/ThreadXRendererTextNode.js.map +0 -1
- package/dist/src/render-drivers/threadx/worker/renderer.d.ts +0 -1
- package/dist/src/render-drivers/threadx/worker/renderer.js +0 -145
- package/dist/src/render-drivers/threadx/worker/renderer.js.map +0 -1
- package/dist/src/render-drivers/utils.d.ts +0 -12
- package/dist/src/render-drivers/utils.js +0 -69
- package/dist/src/render-drivers/utils.js.map +0 -1
- /package/dist/src/core/{CoreStuff.d.ts → temp.d.ts} +0 -0
|
@@ -1,437 +1,437 @@
|
|
|
1
|
-
import type { CoreNode } from '../../CoreNode.js';
|
|
2
|
-
import { getNormalizedRgbaComponents } from '../../lib/utils.js';
|
|
3
|
-
import type { WebGlContextWrapper } from '../../lib/WebGlContextWrapper.js';
|
|
4
|
-
import type { Stage } from '../../Stage.js';
|
|
5
|
-
import type { QuadOptions } from '../CoreRenderer.js';
|
|
6
|
-
import { CoreShaderNode, type CoreShaderType } from '../CoreShaderNode.js';
|
|
7
|
-
import type {
|
|
8
|
-
UniformCollection,
|
|
9
|
-
Vec2,
|
|
10
|
-
Vec3,
|
|
11
|
-
Vec4,
|
|
12
|
-
} from './internal/ShaderUtils.js';
|
|
13
|
-
import type { WebGlRenderer } from './WebGlRenderer.js';
|
|
14
|
-
import type { WebGlRenderOp } from './WebGlRenderOp.js';
|
|
15
|
-
import type { WebGlShaderProgram } from './WebGlShaderProgram.js';
|
|
16
|
-
|
|
17
|
-
export type ShaderSource<T> =
|
|
18
|
-
| string
|
|
19
|
-
| ((renderer: WebGlRenderer, props: T) => string);
|
|
20
|
-
|
|
21
|
-
/**
|
|
22
|
-
* This is the WebGL specific ShaderType @mixes CoreShaderType
|
|
23
|
-
*/
|
|
24
|
-
export type WebGlShaderType<T extends object = Record<string, unknown>> =
|
|
25
|
-
CoreShaderType<T> & {
|
|
26
|
-
/**
|
|
27
|
-
* fragment shader source for WebGl or WebGl2
|
|
28
|
-
*/
|
|
29
|
-
fragment: ShaderSource<T>;
|
|
30
|
-
/**
|
|
31
|
-
* vertex shader source for WebGl or WebGl2
|
|
32
|
-
*/
|
|
33
|
-
vertex?: ShaderSource<T>;
|
|
34
|
-
/**
|
|
35
|
-
* This function is called when one of the props is changed, here you can update the uniforms you use in the fragment / vertex shader.
|
|
36
|
-
* @param node WebGlContextWrapper with utilities to update uniforms, and other actions.
|
|
37
|
-
*/
|
|
38
|
-
update?: (this: WebGlShaderNode<T>, node: CoreNode) => void;
|
|
39
|
-
|
|
40
|
-
/**
|
|
41
|
-
* only used for SDF shader, will be removed in the future.
|
|
42
|
-
*
|
|
43
|
-
* @warning don't use this in your shader type
|
|
44
|
-
*/
|
|
45
|
-
onSdfBind?: (this: WebGlContextWrapper, props: T) => void;
|
|
46
|
-
/**
|
|
47
|
-
* This function is used to check if the shader can be reused based on quad info
|
|
48
|
-
* @param props
|
|
49
|
-
*/
|
|
50
|
-
canBatch?: (
|
|
51
|
-
incomingQuad: QuadOptions,
|
|
52
|
-
currentRenderOp: WebGlRenderOp,
|
|
53
|
-
) => boolean;
|
|
54
|
-
/**
|
|
55
|
-
* extensions required for specific shader?
|
|
56
|
-
*/
|
|
57
|
-
webgl1Extensions?: string[];
|
|
58
|
-
webgl2Extensions?: string[];
|
|
59
|
-
supportsIndexedTextures?: boolean;
|
|
60
|
-
};
|
|
61
|
-
|
|
62
|
-
export class WebGlShaderNode<
|
|
63
|
-
Props extends object = Record<string, unknown>,
|
|
64
|
-
> extends CoreShaderNode<Props> {
|
|
65
|
-
readonly program: WebGlShaderProgram;
|
|
66
|
-
private updater: ((node: CoreNode, props?: Props) => void) | undefined =
|
|
67
|
-
undefined;
|
|
68
|
-
private valueKey: string = '';
|
|
69
|
-
uniforms: UniformCollection = {
|
|
70
|
-
single: {},
|
|
71
|
-
vec2: {},
|
|
72
|
-
vec3: {},
|
|
73
|
-
vec4: {},
|
|
74
|
-
};
|
|
75
|
-
|
|
76
|
-
constructor(
|
|
77
|
-
shaderKey: string,
|
|
78
|
-
config: WebGlShaderType<Props>,
|
|
79
|
-
program: WebGlShaderProgram,
|
|
80
|
-
stage: Stage,
|
|
81
|
-
props?: Props,
|
|
82
|
-
) {
|
|
83
|
-
super(shaderKey, config, stage, props);
|
|
84
|
-
this.program = program;
|
|
85
|
-
if (config.update !== undefined) {
|
|
86
|
-
this.updater = config.update!;
|
|
87
|
-
|
|
88
|
-
this.update = () => {
|
|
89
|
-
if (this.props === undefined) {
|
|
90
|
-
this.updater!(this.node as CoreNode, this.props);
|
|
91
|
-
return;
|
|
92
|
-
}
|
|
93
|
-
const prevKey = this.valueKey;
|
|
94
|
-
this.valueKey = '';
|
|
95
|
-
for (const key in this.resolvedProps) {
|
|
96
|
-
this.valueKey += `${key}:${this.resolvedProps[key]!};`;
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
if (prevKey === this.valueKey) {
|
|
100
|
-
return;
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
if (prevKey.length > 0) {
|
|
104
|
-
this.stage.shManager.mutateShaderValueUsage(prevKey, -1);
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
const values = this.stage.shManager.getShaderValues(
|
|
108
|
-
this.valueKey,
|
|
109
|
-
) as unknown as UniformCollection;
|
|
110
|
-
if (values !== undefined) {
|
|
111
|
-
this.uniforms = values;
|
|
112
|
-
return;
|
|
113
|
-
}
|
|
114
|
-
//create empty uniform collection when calculating new values
|
|
115
|
-
this.uniforms = {
|
|
116
|
-
single: {},
|
|
117
|
-
vec2: {},
|
|
118
|
-
vec3: {},
|
|
119
|
-
vec4: {},
|
|
120
|
-
};
|
|
121
|
-
this.updater!(this.node as CoreNode);
|
|
122
|
-
this.stage.shManager.setShaderValues(
|
|
123
|
-
this.valueKey,
|
|
124
|
-
this.uniforms as unknown as Record<string, unknown>,
|
|
125
|
-
);
|
|
126
|
-
};
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
/**
|
|
131
|
-
* Sets the value of a RGBA variable
|
|
132
|
-
* @param location
|
|
133
|
-
* @param value
|
|
134
|
-
*/
|
|
135
|
-
uniformRGBA(location: string, value: number) {
|
|
136
|
-
this.uniform4fv(
|
|
137
|
-
location,
|
|
138
|
-
new Float32Array(getNormalizedRgbaComponents(value)),
|
|
139
|
-
);
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
/**
|
|
143
|
-
* Sets the value of a single float uniform variable.
|
|
144
|
-
*
|
|
145
|
-
* @param location - The location of the uniform variable.
|
|
146
|
-
* @param v0 - The value to set.
|
|
147
|
-
*/
|
|
148
|
-
uniform1f(location: string, value: number) {
|
|
149
|
-
this.uniforms.single[location] = {
|
|
150
|
-
method: 'uniform1f',
|
|
151
|
-
value,
|
|
152
|
-
};
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
/**
|
|
156
|
-
* Sets the value of a float array uniform variable.
|
|
157
|
-
*
|
|
158
|
-
* @param location - The location of the uniform variable.
|
|
159
|
-
* @param value - The array of values to set.
|
|
160
|
-
*/
|
|
161
|
-
uniform1fv(location: string, value: Float32Array) {
|
|
162
|
-
this.uniforms.single[location] = {
|
|
163
|
-
method: 'uniform1fv',
|
|
164
|
-
value,
|
|
165
|
-
};
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
/**
|
|
169
|
-
* Sets the value of a single integer uniform variable.
|
|
170
|
-
*
|
|
171
|
-
* @param location - The location of the uniform variable.
|
|
172
|
-
* @param v0 - The value to set.
|
|
173
|
-
*/
|
|
174
|
-
uniform1i(location: string, value: number) {
|
|
175
|
-
this.uniforms.single[location] = {
|
|
176
|
-
method: 'uniform1i',
|
|
177
|
-
value,
|
|
178
|
-
};
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
/**
|
|
182
|
-
* Sets the value of an integer array uniform variable.
|
|
183
|
-
*
|
|
184
|
-
* @param location - The location of the uniform variable.
|
|
185
|
-
* @param value - The array of values to set.
|
|
186
|
-
*/
|
|
187
|
-
uniform1iv(location: string, value: Int32Array) {
|
|
188
|
-
this.uniforms.single[location] = {
|
|
189
|
-
method: 'uniform1iv',
|
|
190
|
-
value,
|
|
191
|
-
};
|
|
192
|
-
}
|
|
193
|
-
|
|
194
|
-
/**
|
|
195
|
-
* Sets the value of a vec2 uniform variable.
|
|
196
|
-
*
|
|
197
|
-
* @param location - The location of the uniform variable.
|
|
198
|
-
* @param v0 - The first component of the vector.
|
|
199
|
-
* @param v1 - The second component of the vector.
|
|
200
|
-
*/
|
|
201
|
-
uniform2f(location: string, v0: number, v1: number) {
|
|
202
|
-
this.uniforms.vec2[location] = {
|
|
203
|
-
method: 'uniform2f',
|
|
204
|
-
value: [v0, v1],
|
|
205
|
-
};
|
|
206
|
-
}
|
|
207
|
-
|
|
208
|
-
/**
|
|
209
|
-
* Sets the value of a vec2 array uniform variable.
|
|
210
|
-
*
|
|
211
|
-
* @param location - The location of the uniform variable.
|
|
212
|
-
* @param value - The array of vec2 values to set as FloatArray.
|
|
213
|
-
*/
|
|
214
|
-
uniform2fv(location: string, value: Float32Array) {
|
|
215
|
-
this.uniforms.single[location] = {
|
|
216
|
-
method: 'uniform2fv',
|
|
217
|
-
value,
|
|
218
|
-
};
|
|
219
|
-
}
|
|
220
|
-
|
|
221
|
-
/**
|
|
222
|
-
* Sets the value of a vec2 array uniform variable.
|
|
223
|
-
*
|
|
224
|
-
* @param location - The location of the uniform variable.
|
|
225
|
-
* @param value - The array of vec2 values to set.
|
|
226
|
-
*/
|
|
227
|
-
uniform2fa(location: string, value: Vec2) {
|
|
228
|
-
this.uniforms.vec2[location] = {
|
|
229
|
-
method: 'uniform2f',
|
|
230
|
-
value,
|
|
231
|
-
};
|
|
232
|
-
}
|
|
233
|
-
|
|
234
|
-
/**
|
|
235
|
-
* Sets the value of a ivec2 uniform variable.
|
|
236
|
-
*
|
|
237
|
-
* @param location - The location of the uniform variable.
|
|
238
|
-
* @param v0 - The first component of the vector.
|
|
239
|
-
* @param v1 - The second component of the vector.
|
|
240
|
-
*/
|
|
241
|
-
uniform2i(location: string, v0: number, v1: number) {
|
|
242
|
-
this.uniforms.vec2[location] = {
|
|
243
|
-
method: 'uniform2i',
|
|
244
|
-
value: [v0, v1],
|
|
245
|
-
};
|
|
246
|
-
}
|
|
247
|
-
|
|
248
|
-
/**
|
|
249
|
-
* Sets the value of an ivec2 array uniform variable.
|
|
250
|
-
*
|
|
251
|
-
* @param location - The location of the uniform variable.
|
|
252
|
-
* @param value - The array of ivec2 values to set.
|
|
253
|
-
*/
|
|
254
|
-
uniform2iv(location: string, value: Int32Array) {
|
|
255
|
-
this.uniforms.single[location] = {
|
|
256
|
-
method: 'uniform2iv',
|
|
257
|
-
value,
|
|
258
|
-
};
|
|
259
|
-
}
|
|
260
|
-
|
|
261
|
-
/**
|
|
262
|
-
* Sets the value of a vec3 uniform variable.
|
|
263
|
-
*
|
|
264
|
-
* @param location - The location of the uniform variable.
|
|
265
|
-
* @param v0 - The first component of the vector.
|
|
266
|
-
* @param v1 - The second component of the vector.
|
|
267
|
-
* @param v2 - The third component of the vector.
|
|
268
|
-
*/
|
|
269
|
-
uniform3f(location: string, v0: number, v1: number, v2: number) {
|
|
270
|
-
this.uniforms.vec3[location] = {
|
|
271
|
-
method: 'uniform3f',
|
|
272
|
-
value: [v0, v1, v2],
|
|
273
|
-
};
|
|
274
|
-
}
|
|
275
|
-
|
|
276
|
-
/**
|
|
277
|
-
* Sets the value of a vec3 uniform variable.
|
|
278
|
-
*
|
|
279
|
-
* @param location - The location of the uniform variable.
|
|
280
|
-
* @param
|
|
281
|
-
*/
|
|
282
|
-
uniform3fa(location: string, value: Vec3) {
|
|
283
|
-
this.uniforms.vec3[location] = {
|
|
284
|
-
method: 'uniform3f',
|
|
285
|
-
value,
|
|
286
|
-
};
|
|
287
|
-
}
|
|
288
|
-
|
|
289
|
-
/**
|
|
290
|
-
* Sets the value of a vec3 array uniform variable.
|
|
291
|
-
*
|
|
292
|
-
* @param location - The location of the uniform variable.
|
|
293
|
-
* @param value - The array of vec3 values to set.
|
|
294
|
-
*/
|
|
295
|
-
uniform3fv(location: string, value: Float32Array) {
|
|
296
|
-
this.uniforms.single[location] = {
|
|
297
|
-
method: 'uniform3fv',
|
|
298
|
-
value,
|
|
299
|
-
};
|
|
300
|
-
}
|
|
301
|
-
|
|
302
|
-
/**
|
|
303
|
-
* Sets the value of a ivec3 uniform variable.
|
|
304
|
-
*
|
|
305
|
-
* @param location - The location of the uniform variable.
|
|
306
|
-
* @param v0 - The first component of the vector.
|
|
307
|
-
* @param v1 - The second component of the vector.
|
|
308
|
-
* @param v2 - The third component of the vector.
|
|
309
|
-
*/
|
|
310
|
-
uniform3i(location: string, v0: number, v1: number, v2: number) {
|
|
311
|
-
this.uniforms.vec3[location] = {
|
|
312
|
-
method: 'uniform3i',
|
|
313
|
-
value: [v0, v1, v2],
|
|
314
|
-
};
|
|
315
|
-
}
|
|
316
|
-
|
|
317
|
-
/**
|
|
318
|
-
* Sets the value of an ivec3 array uniform variable.
|
|
319
|
-
*
|
|
320
|
-
* @param location - The location of the uniform variable.
|
|
321
|
-
* @param value - The array of ivec3 values to set.
|
|
322
|
-
*/
|
|
323
|
-
uniform3iv(location: string, value: Int32Array) {
|
|
324
|
-
this.uniforms.single[location] = {
|
|
325
|
-
method: 'uniform3iv',
|
|
326
|
-
value,
|
|
327
|
-
};
|
|
328
|
-
}
|
|
329
|
-
|
|
330
|
-
/**
|
|
331
|
-
* Sets the value of a vec4 uniform variable.
|
|
332
|
-
*
|
|
333
|
-
* @param location - The location of the uniform variable.
|
|
334
|
-
* @param v0 - The first component of the vector.
|
|
335
|
-
* @param v1 - The second component of the vector.
|
|
336
|
-
* @param v2 - The third component of the vector.
|
|
337
|
-
* @param v3 - The fourth component of the vector.
|
|
338
|
-
*/
|
|
339
|
-
uniform4f(location: string, v0: number, v1: number, v2: number, v3: number) {
|
|
340
|
-
this.uniforms.vec4[location] = {
|
|
341
|
-
method: 'uniform4f',
|
|
342
|
-
value: [v0, v1, v2, v3],
|
|
343
|
-
};
|
|
344
|
-
}
|
|
345
|
-
|
|
346
|
-
/**
|
|
347
|
-
* Sets an array of numbers
|
|
348
|
-
* @param location The location of the uniform variable.
|
|
349
|
-
* @param value
|
|
350
|
-
*/
|
|
351
|
-
uniform4fa(location: string, value: Vec4) {
|
|
352
|
-
this.uniforms.vec4[location] = {
|
|
353
|
-
method: 'uniform4f',
|
|
354
|
-
value,
|
|
355
|
-
};
|
|
356
|
-
}
|
|
357
|
-
|
|
358
|
-
/**
|
|
359
|
-
* Sets the value of a vec4 array uniform variable.
|
|
360
|
-
*
|
|
361
|
-
* @param location - The location of the uniform variable.
|
|
362
|
-
* @param value - The array of vec4 values to set.
|
|
363
|
-
*/
|
|
364
|
-
uniform4fv(location: string, value: Float32Array) {
|
|
365
|
-
this.uniforms.single[location] = {
|
|
366
|
-
method: 'uniform4fv',
|
|
367
|
-
value,
|
|
368
|
-
};
|
|
369
|
-
}
|
|
370
|
-
|
|
371
|
-
/**
|
|
372
|
-
* Sets the value of a ivec4 uniform variable.
|
|
373
|
-
*
|
|
374
|
-
* @param location - The location of the uniform variable.
|
|
375
|
-
* @param v0 - The first component of the vector.
|
|
376
|
-
* @param v1 - The second component of the vector.
|
|
377
|
-
* @param v2 - The third component of the vector.
|
|
378
|
-
* @param v3 - The fourth component of the vector.
|
|
379
|
-
*/
|
|
380
|
-
uniform4i(location: string, v0: number, v1: number, v2: number, v3: number) {
|
|
381
|
-
this.uniforms.vec4[location] = {
|
|
382
|
-
method: 'uniform4i',
|
|
383
|
-
value: [v0, v1, v2, v3],
|
|
384
|
-
};
|
|
385
|
-
}
|
|
386
|
-
|
|
387
|
-
/**
|
|
388
|
-
* Sets the value of an ivec4 array uniform variable.
|
|
389
|
-
*
|
|
390
|
-
* @param location - The location of the uniform variable.
|
|
391
|
-
* @param value - The array of ivec4 values to set.
|
|
392
|
-
*/
|
|
393
|
-
uniform4iv(location: string, value: Int32Array) {
|
|
394
|
-
this.uniforms.single[location] = {
|
|
395
|
-
method: 'uniform4iv',
|
|
396
|
-
value,
|
|
397
|
-
};
|
|
398
|
-
}
|
|
399
|
-
|
|
400
|
-
/**
|
|
401
|
-
* Sets the value of a mat2 uniform variable.
|
|
402
|
-
*
|
|
403
|
-
* @param location - The location of the uniform variable.
|
|
404
|
-
* @param transpose - Whether to transpose the matrix.
|
|
405
|
-
* @param value - The array of mat2 values to set.
|
|
406
|
-
*/
|
|
407
|
-
uniformMatrix2fv(location: string, value: Float32Array) {
|
|
408
|
-
this.uniforms.single[location] = {
|
|
409
|
-
method: 'uniformMatrix2fv',
|
|
410
|
-
value,
|
|
411
|
-
};
|
|
412
|
-
}
|
|
413
|
-
|
|
414
|
-
/**
|
|
415
|
-
* Sets the value of a mat2 uniform variable.
|
|
416
|
-
* @param location - The location of the uniform variable.
|
|
417
|
-
* @param value - The array of mat2 values to set.
|
|
418
|
-
*/
|
|
419
|
-
uniformMatrix3fv(location: string, value: Float32Array) {
|
|
420
|
-
this.uniforms.single[location] = {
|
|
421
|
-
method: 'uniformMatrix3fv',
|
|
422
|
-
value,
|
|
423
|
-
};
|
|
424
|
-
}
|
|
425
|
-
|
|
426
|
-
/**
|
|
427
|
-
* Sets the value of a mat4 uniform variable.
|
|
428
|
-
* @param location - The location of the uniform variable.
|
|
429
|
-
* @param value - The array of mat4 values to set.
|
|
430
|
-
*/
|
|
431
|
-
uniformMatrix4fv(location: string, value: Float32Array) {
|
|
432
|
-
this.uniforms.single[location] = {
|
|
433
|
-
method: 'uniformMatrix4fv',
|
|
434
|
-
value,
|
|
435
|
-
};
|
|
436
|
-
}
|
|
437
|
-
}
|
|
1
|
+
import type { CoreNode } from '../../CoreNode.js';
|
|
2
|
+
import { getNormalizedRgbaComponents } from '../../lib/utils.js';
|
|
3
|
+
import type { WebGlContextWrapper } from '../../lib/WebGlContextWrapper.js';
|
|
4
|
+
import type { Stage } from '../../Stage.js';
|
|
5
|
+
import type { QuadOptions } from '../CoreRenderer.js';
|
|
6
|
+
import { CoreShaderNode, type CoreShaderType } from '../CoreShaderNode.js';
|
|
7
|
+
import type {
|
|
8
|
+
UniformCollection,
|
|
9
|
+
Vec2,
|
|
10
|
+
Vec3,
|
|
11
|
+
Vec4,
|
|
12
|
+
} from './internal/ShaderUtils.js';
|
|
13
|
+
import type { WebGlRenderer } from './WebGlRenderer.js';
|
|
14
|
+
import type { WebGlRenderOp } from './WebGlRenderOp.js';
|
|
15
|
+
import type { WebGlShaderProgram } from './WebGlShaderProgram.js';
|
|
16
|
+
|
|
17
|
+
export type ShaderSource<T> =
|
|
18
|
+
| string
|
|
19
|
+
| ((renderer: WebGlRenderer, props: T) => string);
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* This is the WebGL specific ShaderType @mixes CoreShaderType
|
|
23
|
+
*/
|
|
24
|
+
export type WebGlShaderType<T extends object = Record<string, unknown>> =
|
|
25
|
+
CoreShaderType<T> & {
|
|
26
|
+
/**
|
|
27
|
+
* fragment shader source for WebGl or WebGl2
|
|
28
|
+
*/
|
|
29
|
+
fragment: ShaderSource<T>;
|
|
30
|
+
/**
|
|
31
|
+
* vertex shader source for WebGl or WebGl2
|
|
32
|
+
*/
|
|
33
|
+
vertex?: ShaderSource<T>;
|
|
34
|
+
/**
|
|
35
|
+
* This function is called when one of the props is changed, here you can update the uniforms you use in the fragment / vertex shader.
|
|
36
|
+
* @param node WebGlContextWrapper with utilities to update uniforms, and other actions.
|
|
37
|
+
*/
|
|
38
|
+
update?: (this: WebGlShaderNode<T>, node: CoreNode) => void;
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* only used for SDF shader, will be removed in the future.
|
|
42
|
+
*
|
|
43
|
+
* @warning don't use this in your shader type
|
|
44
|
+
*/
|
|
45
|
+
onSdfBind?: (this: WebGlContextWrapper, props: T) => void;
|
|
46
|
+
/**
|
|
47
|
+
* This function is used to check if the shader can be reused based on quad info
|
|
48
|
+
* @param props
|
|
49
|
+
*/
|
|
50
|
+
canBatch?: (
|
|
51
|
+
incomingQuad: QuadOptions,
|
|
52
|
+
currentRenderOp: WebGlRenderOp,
|
|
53
|
+
) => boolean;
|
|
54
|
+
/**
|
|
55
|
+
* extensions required for specific shader?
|
|
56
|
+
*/
|
|
57
|
+
webgl1Extensions?: string[];
|
|
58
|
+
webgl2Extensions?: string[];
|
|
59
|
+
supportsIndexedTextures?: boolean;
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
export class WebGlShaderNode<
|
|
63
|
+
Props extends object = Record<string, unknown>,
|
|
64
|
+
> extends CoreShaderNode<Props> {
|
|
65
|
+
readonly program: WebGlShaderProgram;
|
|
66
|
+
private updater: ((node: CoreNode, props?: Props) => void) | undefined =
|
|
67
|
+
undefined;
|
|
68
|
+
private valueKey: string = '';
|
|
69
|
+
uniforms: UniformCollection = {
|
|
70
|
+
single: {},
|
|
71
|
+
vec2: {},
|
|
72
|
+
vec3: {},
|
|
73
|
+
vec4: {},
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
constructor(
|
|
77
|
+
shaderKey: string,
|
|
78
|
+
config: WebGlShaderType<Props>,
|
|
79
|
+
program: WebGlShaderProgram,
|
|
80
|
+
stage: Stage,
|
|
81
|
+
props?: Props,
|
|
82
|
+
) {
|
|
83
|
+
super(shaderKey, config, stage, props);
|
|
84
|
+
this.program = program;
|
|
85
|
+
if (config.update !== undefined) {
|
|
86
|
+
this.updater = config.update!;
|
|
87
|
+
|
|
88
|
+
this.update = () => {
|
|
89
|
+
if (this.props === undefined) {
|
|
90
|
+
this.updater!(this.node as CoreNode, this.props);
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
93
|
+
const prevKey = this.valueKey;
|
|
94
|
+
this.valueKey = '';
|
|
95
|
+
for (const key in this.resolvedProps) {
|
|
96
|
+
this.valueKey += `${key}:${this.resolvedProps[key]!};`;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
if (prevKey === this.valueKey) {
|
|
100
|
+
return;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
if (prevKey.length > 0) {
|
|
104
|
+
this.stage.shManager.mutateShaderValueUsage(prevKey, -1);
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
const values = this.stage.shManager.getShaderValues(
|
|
108
|
+
this.valueKey,
|
|
109
|
+
) as unknown as UniformCollection;
|
|
110
|
+
if (values !== undefined) {
|
|
111
|
+
this.uniforms = values;
|
|
112
|
+
return;
|
|
113
|
+
}
|
|
114
|
+
//create empty uniform collection when calculating new values
|
|
115
|
+
this.uniforms = {
|
|
116
|
+
single: {},
|
|
117
|
+
vec2: {},
|
|
118
|
+
vec3: {},
|
|
119
|
+
vec4: {},
|
|
120
|
+
};
|
|
121
|
+
this.updater!(this.node as CoreNode);
|
|
122
|
+
this.stage.shManager.setShaderValues(
|
|
123
|
+
this.valueKey,
|
|
124
|
+
this.uniforms as unknown as Record<string, unknown>,
|
|
125
|
+
);
|
|
126
|
+
};
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
/**
|
|
131
|
+
* Sets the value of a RGBA variable
|
|
132
|
+
* @param location
|
|
133
|
+
* @param value
|
|
134
|
+
*/
|
|
135
|
+
uniformRGBA(location: string, value: number) {
|
|
136
|
+
this.uniform4fv(
|
|
137
|
+
location,
|
|
138
|
+
new Float32Array(getNormalizedRgbaComponents(value)),
|
|
139
|
+
);
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
/**
|
|
143
|
+
* Sets the value of a single float uniform variable.
|
|
144
|
+
*
|
|
145
|
+
* @param location - The location of the uniform variable.
|
|
146
|
+
* @param v0 - The value to set.
|
|
147
|
+
*/
|
|
148
|
+
uniform1f(location: string, value: number) {
|
|
149
|
+
this.uniforms.single[location] = {
|
|
150
|
+
method: 'uniform1f',
|
|
151
|
+
value,
|
|
152
|
+
};
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
/**
|
|
156
|
+
* Sets the value of a float array uniform variable.
|
|
157
|
+
*
|
|
158
|
+
* @param location - The location of the uniform variable.
|
|
159
|
+
* @param value - The array of values to set.
|
|
160
|
+
*/
|
|
161
|
+
uniform1fv(location: string, value: Float32Array) {
|
|
162
|
+
this.uniforms.single[location] = {
|
|
163
|
+
method: 'uniform1fv',
|
|
164
|
+
value,
|
|
165
|
+
};
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
/**
|
|
169
|
+
* Sets the value of a single integer uniform variable.
|
|
170
|
+
*
|
|
171
|
+
* @param location - The location of the uniform variable.
|
|
172
|
+
* @param v0 - The value to set.
|
|
173
|
+
*/
|
|
174
|
+
uniform1i(location: string, value: number) {
|
|
175
|
+
this.uniforms.single[location] = {
|
|
176
|
+
method: 'uniform1i',
|
|
177
|
+
value,
|
|
178
|
+
};
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
/**
|
|
182
|
+
* Sets the value of an integer array uniform variable.
|
|
183
|
+
*
|
|
184
|
+
* @param location - The location of the uniform variable.
|
|
185
|
+
* @param value - The array of values to set.
|
|
186
|
+
*/
|
|
187
|
+
uniform1iv(location: string, value: Int32Array) {
|
|
188
|
+
this.uniforms.single[location] = {
|
|
189
|
+
method: 'uniform1iv',
|
|
190
|
+
value,
|
|
191
|
+
};
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
/**
|
|
195
|
+
* Sets the value of a vec2 uniform variable.
|
|
196
|
+
*
|
|
197
|
+
* @param location - The location of the uniform variable.
|
|
198
|
+
* @param v0 - The first component of the vector.
|
|
199
|
+
* @param v1 - The second component of the vector.
|
|
200
|
+
*/
|
|
201
|
+
uniform2f(location: string, v0: number, v1: number) {
|
|
202
|
+
this.uniforms.vec2[location] = {
|
|
203
|
+
method: 'uniform2f',
|
|
204
|
+
value: [v0, v1],
|
|
205
|
+
};
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
/**
|
|
209
|
+
* Sets the value of a vec2 array uniform variable.
|
|
210
|
+
*
|
|
211
|
+
* @param location - The location of the uniform variable.
|
|
212
|
+
* @param value - The array of vec2 values to set as FloatArray.
|
|
213
|
+
*/
|
|
214
|
+
uniform2fv(location: string, value: Float32Array) {
|
|
215
|
+
this.uniforms.single[location] = {
|
|
216
|
+
method: 'uniform2fv',
|
|
217
|
+
value,
|
|
218
|
+
};
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
/**
|
|
222
|
+
* Sets the value of a vec2 array uniform variable.
|
|
223
|
+
*
|
|
224
|
+
* @param location - The location of the uniform variable.
|
|
225
|
+
* @param value - The array of vec2 values to set.
|
|
226
|
+
*/
|
|
227
|
+
uniform2fa(location: string, value: Vec2) {
|
|
228
|
+
this.uniforms.vec2[location] = {
|
|
229
|
+
method: 'uniform2f',
|
|
230
|
+
value,
|
|
231
|
+
};
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
/**
|
|
235
|
+
* Sets the value of a ivec2 uniform variable.
|
|
236
|
+
*
|
|
237
|
+
* @param location - The location of the uniform variable.
|
|
238
|
+
* @param v0 - The first component of the vector.
|
|
239
|
+
* @param v1 - The second component of the vector.
|
|
240
|
+
*/
|
|
241
|
+
uniform2i(location: string, v0: number, v1: number) {
|
|
242
|
+
this.uniforms.vec2[location] = {
|
|
243
|
+
method: 'uniform2i',
|
|
244
|
+
value: [v0, v1],
|
|
245
|
+
};
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
/**
|
|
249
|
+
* Sets the value of an ivec2 array uniform variable.
|
|
250
|
+
*
|
|
251
|
+
* @param location - The location of the uniform variable.
|
|
252
|
+
* @param value - The array of ivec2 values to set.
|
|
253
|
+
*/
|
|
254
|
+
uniform2iv(location: string, value: Int32Array) {
|
|
255
|
+
this.uniforms.single[location] = {
|
|
256
|
+
method: 'uniform2iv',
|
|
257
|
+
value,
|
|
258
|
+
};
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
/**
|
|
262
|
+
* Sets the value of a vec3 uniform variable.
|
|
263
|
+
*
|
|
264
|
+
* @param location - The location of the uniform variable.
|
|
265
|
+
* @param v0 - The first component of the vector.
|
|
266
|
+
* @param v1 - The second component of the vector.
|
|
267
|
+
* @param v2 - The third component of the vector.
|
|
268
|
+
*/
|
|
269
|
+
uniform3f(location: string, v0: number, v1: number, v2: number) {
|
|
270
|
+
this.uniforms.vec3[location] = {
|
|
271
|
+
method: 'uniform3f',
|
|
272
|
+
value: [v0, v1, v2],
|
|
273
|
+
};
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
/**
|
|
277
|
+
* Sets the value of a vec3 uniform variable.
|
|
278
|
+
*
|
|
279
|
+
* @param location - The location of the uniform variable.
|
|
280
|
+
* @param
|
|
281
|
+
*/
|
|
282
|
+
uniform3fa(location: string, value: Vec3) {
|
|
283
|
+
this.uniforms.vec3[location] = {
|
|
284
|
+
method: 'uniform3f',
|
|
285
|
+
value,
|
|
286
|
+
};
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
/**
|
|
290
|
+
* Sets the value of a vec3 array uniform variable.
|
|
291
|
+
*
|
|
292
|
+
* @param location - The location of the uniform variable.
|
|
293
|
+
* @param value - The array of vec3 values to set.
|
|
294
|
+
*/
|
|
295
|
+
uniform3fv(location: string, value: Float32Array) {
|
|
296
|
+
this.uniforms.single[location] = {
|
|
297
|
+
method: 'uniform3fv',
|
|
298
|
+
value,
|
|
299
|
+
};
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
/**
|
|
303
|
+
* Sets the value of a ivec3 uniform variable.
|
|
304
|
+
*
|
|
305
|
+
* @param location - The location of the uniform variable.
|
|
306
|
+
* @param v0 - The first component of the vector.
|
|
307
|
+
* @param v1 - The second component of the vector.
|
|
308
|
+
* @param v2 - The third component of the vector.
|
|
309
|
+
*/
|
|
310
|
+
uniform3i(location: string, v0: number, v1: number, v2: number) {
|
|
311
|
+
this.uniforms.vec3[location] = {
|
|
312
|
+
method: 'uniform3i',
|
|
313
|
+
value: [v0, v1, v2],
|
|
314
|
+
};
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
/**
|
|
318
|
+
* Sets the value of an ivec3 array uniform variable.
|
|
319
|
+
*
|
|
320
|
+
* @param location - The location of the uniform variable.
|
|
321
|
+
* @param value - The array of ivec3 values to set.
|
|
322
|
+
*/
|
|
323
|
+
uniform3iv(location: string, value: Int32Array) {
|
|
324
|
+
this.uniforms.single[location] = {
|
|
325
|
+
method: 'uniform3iv',
|
|
326
|
+
value,
|
|
327
|
+
};
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
/**
|
|
331
|
+
* Sets the value of a vec4 uniform variable.
|
|
332
|
+
*
|
|
333
|
+
* @param location - The location of the uniform variable.
|
|
334
|
+
* @param v0 - The first component of the vector.
|
|
335
|
+
* @param v1 - The second component of the vector.
|
|
336
|
+
* @param v2 - The third component of the vector.
|
|
337
|
+
* @param v3 - The fourth component of the vector.
|
|
338
|
+
*/
|
|
339
|
+
uniform4f(location: string, v0: number, v1: number, v2: number, v3: number) {
|
|
340
|
+
this.uniforms.vec4[location] = {
|
|
341
|
+
method: 'uniform4f',
|
|
342
|
+
value: [v0, v1, v2, v3],
|
|
343
|
+
};
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
/**
|
|
347
|
+
* Sets an array of numbers
|
|
348
|
+
* @param location The location of the uniform variable.
|
|
349
|
+
* @param value
|
|
350
|
+
*/
|
|
351
|
+
uniform4fa(location: string, value: Vec4) {
|
|
352
|
+
this.uniforms.vec4[location] = {
|
|
353
|
+
method: 'uniform4f',
|
|
354
|
+
value,
|
|
355
|
+
};
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
/**
|
|
359
|
+
* Sets the value of a vec4 array uniform variable.
|
|
360
|
+
*
|
|
361
|
+
* @param location - The location of the uniform variable.
|
|
362
|
+
* @param value - The array of vec4 values to set.
|
|
363
|
+
*/
|
|
364
|
+
uniform4fv(location: string, value: Float32Array) {
|
|
365
|
+
this.uniforms.single[location] = {
|
|
366
|
+
method: 'uniform4fv',
|
|
367
|
+
value,
|
|
368
|
+
};
|
|
369
|
+
}
|
|
370
|
+
|
|
371
|
+
/**
|
|
372
|
+
* Sets the value of a ivec4 uniform variable.
|
|
373
|
+
*
|
|
374
|
+
* @param location - The location of the uniform variable.
|
|
375
|
+
* @param v0 - The first component of the vector.
|
|
376
|
+
* @param v1 - The second component of the vector.
|
|
377
|
+
* @param v2 - The third component of the vector.
|
|
378
|
+
* @param v3 - The fourth component of the vector.
|
|
379
|
+
*/
|
|
380
|
+
uniform4i(location: string, v0: number, v1: number, v2: number, v3: number) {
|
|
381
|
+
this.uniforms.vec4[location] = {
|
|
382
|
+
method: 'uniform4i',
|
|
383
|
+
value: [v0, v1, v2, v3],
|
|
384
|
+
};
|
|
385
|
+
}
|
|
386
|
+
|
|
387
|
+
/**
|
|
388
|
+
* Sets the value of an ivec4 array uniform variable.
|
|
389
|
+
*
|
|
390
|
+
* @param location - The location of the uniform variable.
|
|
391
|
+
* @param value - The array of ivec4 values to set.
|
|
392
|
+
*/
|
|
393
|
+
uniform4iv(location: string, value: Int32Array) {
|
|
394
|
+
this.uniforms.single[location] = {
|
|
395
|
+
method: 'uniform4iv',
|
|
396
|
+
value,
|
|
397
|
+
};
|
|
398
|
+
}
|
|
399
|
+
|
|
400
|
+
/**
|
|
401
|
+
* Sets the value of a mat2 uniform variable.
|
|
402
|
+
*
|
|
403
|
+
* @param location - The location of the uniform variable.
|
|
404
|
+
* @param transpose - Whether to transpose the matrix.
|
|
405
|
+
* @param value - The array of mat2 values to set.
|
|
406
|
+
*/
|
|
407
|
+
uniformMatrix2fv(location: string, value: Float32Array) {
|
|
408
|
+
this.uniforms.single[location] = {
|
|
409
|
+
method: 'uniformMatrix2fv',
|
|
410
|
+
value,
|
|
411
|
+
};
|
|
412
|
+
}
|
|
413
|
+
|
|
414
|
+
/**
|
|
415
|
+
* Sets the value of a mat2 uniform variable.
|
|
416
|
+
* @param location - The location of the uniform variable.
|
|
417
|
+
* @param value - The array of mat2 values to set.
|
|
418
|
+
*/
|
|
419
|
+
uniformMatrix3fv(location: string, value: Float32Array) {
|
|
420
|
+
this.uniforms.single[location] = {
|
|
421
|
+
method: 'uniformMatrix3fv',
|
|
422
|
+
value,
|
|
423
|
+
};
|
|
424
|
+
}
|
|
425
|
+
|
|
426
|
+
/**
|
|
427
|
+
* Sets the value of a mat4 uniform variable.
|
|
428
|
+
* @param location - The location of the uniform variable.
|
|
429
|
+
* @param value - The array of mat4 values to set.
|
|
430
|
+
*/
|
|
431
|
+
uniformMatrix4fv(location: string, value: Float32Array) {
|
|
432
|
+
this.uniforms.single[location] = {
|
|
433
|
+
method: 'uniformMatrix4fv',
|
|
434
|
+
value,
|
|
435
|
+
};
|
|
436
|
+
}
|
|
437
|
+
}
|