@codexo/exojs 0.9.0 → 0.10.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +44 -0
- package/README.md +14 -14
- package/dist/esm/core/Application.d.ts +25 -6
- package/dist/esm/core/Application.js +42 -8
- package/dist/esm/core/Application.js.map +1 -1
- package/dist/esm/core/Perf.d.ts +23 -0
- package/dist/esm/core/Perf.js +49 -0
- package/dist/esm/core/Perf.js.map +1 -0
- package/dist/esm/core/Scene.d.ts +8 -8
- package/dist/esm/core/Scene.js +7 -7
- package/dist/esm/core/Scene.js.map +1 -1
- package/dist/esm/core/SceneManager.js +2 -2
- package/dist/esm/core/SceneManager.js.map +1 -1
- package/dist/esm/core/SceneNode.d.ts +0 -3
- package/dist/esm/core/SceneNode.js +0 -9
- package/dist/esm/core/SceneNode.js.map +1 -1
- package/dist/esm/core/capabilities.d.ts +2 -0
- package/dist/esm/core/capabilities.js +15 -0
- package/dist/esm/core/capabilities.js.map +1 -1
- package/dist/esm/core/index.d.ts +1 -0
- package/dist/esm/core/types.d.ts +1 -1
- package/dist/esm/core/utils.d.ts +12 -0
- package/dist/esm/core/utils.js +18 -1
- package/dist/esm/core/utils.js.map +1 -1
- package/dist/esm/index.js +14 -3
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/particles/ParticleSystem.d.ts +8 -5
- package/dist/esm/particles/ParticleSystem.js +9 -5
- package/dist/esm/particles/ParticleSystem.js.map +1 -1
- package/dist/esm/particles/distributions/{Gradient.d.ts → ColorGradient.d.ts} +5 -5
- package/dist/esm/particles/distributions/{Gradient.js → ColorGradient.js} +5 -5
- package/dist/esm/particles/distributions/ColorGradient.js.map +1 -0
- package/dist/esm/particles/distributions/Distribution.d.ts +2 -2
- package/dist/esm/particles/distributions/index.d.ts +2 -2
- package/dist/esm/particles/gpu/ParticleGpuState.js +1 -1
- package/dist/esm/particles/modules/ColorOverLifetime.d.ts +3 -3
- package/dist/esm/particles/modules/ColorOverLifetime.js.map +1 -1
- package/dist/esm/particles/modules/ColorOverSpeed.d.ts +3 -3
- package/dist/esm/particles/modules/ColorOverSpeed.js.map +1 -1
- package/dist/esm/particles/modules/UpdateModule.d.ts +2 -2
- package/dist/esm/particles/modules/UpdateModule.js +1 -1
- package/dist/esm/particles/modules/WgslContribution.d.ts +2 -2
- package/dist/esm/rendering/Camera.d.ts +33 -0
- package/dist/esm/rendering/Camera.js +38 -0
- package/dist/esm/rendering/Camera.js.map +1 -0
- package/dist/esm/rendering/Container.d.ts +5 -24
- package/dist/esm/rendering/Container.js +8 -71
- package/dist/esm/rendering/Container.js.map +1 -1
- package/dist/esm/rendering/Drawable.d.ts +8 -10
- package/dist/esm/rendering/Drawable.js +12 -20
- package/dist/esm/rendering/Drawable.js.map +1 -1
- package/dist/esm/rendering/RenderBackend.d.ts +18 -0
- package/dist/esm/rendering/RenderNode.d.ts +81 -8
- package/dist/esm/rendering/RenderNode.js +121 -144
- package/dist/esm/rendering/RenderNode.js.map +1 -1
- package/dist/esm/rendering/RenderTarget.d.ts +13 -0
- package/dist/esm/rendering/RenderTarget.js +13 -0
- package/dist/esm/rendering/RenderTarget.js.map +1 -1
- package/dist/esm/rendering/RenderTargetPass.js +17 -0
- package/dist/esm/rendering/RenderTargetPass.js.map +1 -1
- package/dist/esm/rendering/RenderingContext.d.ts +87 -0
- package/dist/esm/rendering/RenderingContext.js +157 -0
- package/dist/esm/rendering/RenderingContext.js.map +1 -0
- package/dist/esm/rendering/TransformBuffer.d.ts +38 -0
- package/dist/esm/rendering/TransformBuffer.js +116 -0
- package/dist/esm/rendering/TransformBuffer.js.map +1 -0
- package/dist/esm/rendering/filters/WebGpuShaderFilter.js +5 -12
- package/dist/esm/rendering/filters/WebGpuShaderFilter.js.map +1 -1
- package/dist/esm/rendering/geometry/Geometry.d.ts +40 -0
- package/dist/esm/rendering/geometry/Geometry.js +228 -0
- package/dist/esm/rendering/geometry/Geometry.js.map +1 -0
- package/dist/esm/rendering/geometry/GeometryAttribute.d.ts +32 -0
- package/dist/esm/rendering/geometry/QuadGeometry.d.ts +5 -0
- package/dist/esm/rendering/gradient/Gradient.d.ts +34 -0
- package/dist/esm/rendering/gradient/Gradient.js +114 -0
- package/dist/esm/rendering/gradient/Gradient.js.map +1 -0
- package/dist/esm/rendering/gradient/LinearGradient.d.ts +10 -0
- package/dist/esm/rendering/gradient/LinearGradient.js +26 -0
- package/dist/esm/rendering/gradient/LinearGradient.js.map +1 -0
- package/dist/esm/rendering/gradient/RadialGradient.d.ts +10 -0
- package/dist/esm/rendering/gradient/RadialGradient.js +25 -0
- package/dist/esm/rendering/gradient/RadialGradient.js.map +1 -0
- package/dist/esm/rendering/index.d.ts +16 -2
- package/dist/esm/rendering/material/Material.d.ts +114 -0
- package/dist/esm/rendering/material/Material.js +111 -0
- package/dist/esm/rendering/material/Material.js.map +1 -0
- package/dist/esm/rendering/material/MaterialKey.d.ts +18 -0
- package/dist/esm/rendering/material/MaterialKey.js +82 -0
- package/dist/esm/rendering/material/MaterialKey.js.map +1 -0
- package/dist/esm/rendering/material/MeshMaterial.d.ts +16 -0
- package/dist/esm/rendering/material/MeshMaterial.js +21 -0
- package/dist/esm/rendering/material/MeshMaterial.js.map +1 -0
- package/dist/esm/rendering/{mesh/MeshShader.d.ts → material/ShaderSource.d.ts} +29 -62
- package/dist/esm/rendering/{mesh/MeshShader.js → material/ShaderSource.js} +35 -62
- package/dist/esm/rendering/material/ShaderSource.js.map +1 -0
- package/dist/esm/rendering/material/SpriteMaterial.d.ts +15 -0
- package/dist/esm/rendering/material/SpriteMaterial.js +20 -0
- package/dist/esm/rendering/material/SpriteMaterial.js.map +1 -0
- package/dist/esm/rendering/mesh/Mesh.d.ts +29 -12
- package/dist/esm/rendering/mesh/Mesh.js +122 -3
- package/dist/esm/rendering/mesh/Mesh.js.map +1 -1
- package/dist/esm/rendering/pass/RenderPassCoordinator.d.ts +63 -0
- package/dist/esm/rendering/pass/RenderPassDescriptor.d.ts +48 -0
- package/dist/esm/rendering/pass/RenderPassDescriptor.js +16 -0
- package/dist/esm/rendering/pass/RenderPassDescriptor.js.map +1 -0
- package/dist/esm/rendering/plan/RenderCommand.d.ts +67 -0
- package/dist/esm/rendering/plan/RenderCommand.js +94 -0
- package/dist/esm/rendering/plan/RenderCommand.js.map +1 -0
- package/dist/esm/rendering/plan/RenderEffectExecutor.d.ts +10 -0
- package/dist/esm/rendering/plan/RenderEffectExecutor.js +159 -0
- package/dist/esm/rendering/plan/RenderEffectExecutor.js.map +1 -0
- package/dist/esm/rendering/plan/RenderPlan.d.ts +23 -0
- package/dist/esm/rendering/plan/RenderPlan.js +12 -0
- package/dist/esm/rendering/plan/RenderPlan.js.map +1 -0
- package/dist/esm/rendering/plan/RenderPlanBuilder.d.ts +31 -0
- package/dist/esm/rendering/plan/RenderPlanBuilder.js +242 -0
- package/dist/esm/rendering/plan/RenderPlanBuilder.js.map +1 -0
- package/dist/esm/rendering/plan/RenderPlanOptimizer.d.ts +10 -0
- package/dist/esm/rendering/plan/RenderPlanOptimizer.js +180 -0
- package/dist/esm/rendering/plan/RenderPlanOptimizer.js.map +1 -0
- package/dist/esm/rendering/plan/RenderPlanPlayer.d.ts +9 -0
- package/dist/esm/rendering/plan/RenderPlanPlayer.js +56 -0
- package/dist/esm/rendering/plan/RenderPlanPlayer.js.map +1 -0
- package/dist/esm/rendering/plan/RenderScope.d.ts +70 -0
- package/dist/esm/rendering/plan/RenderScope.js +16 -0
- package/dist/esm/rendering/plan/RenderScope.js.map +1 -0
- package/dist/esm/rendering/plan/playRenderTree.d.ts +4 -0
- package/dist/esm/rendering/plan/playRenderTree.js +19 -0
- package/dist/esm/rendering/plan/playRenderTree.js.map +1 -0
- package/dist/esm/rendering/sprite/Sprite.d.ts +22 -1
- package/dist/esm/rendering/sprite/Sprite.js +33 -2
- package/dist/esm/rendering/sprite/Sprite.js.map +1 -1
- package/dist/esm/rendering/sprite/spriteMaterialSources.d.ts +36 -0
- package/dist/esm/rendering/sprite/spriteMaterialSources.js +128 -0
- package/dist/esm/rendering/sprite/spriteMaterialSources.js.map +1 -0
- package/dist/esm/rendering/text/TextStyle.d.ts +1 -1
- package/dist/esm/rendering/texture/DataTexture.d.ts +5 -0
- package/dist/esm/rendering/texture/DataTexture.js +7 -0
- package/dist/esm/rendering/texture/DataTexture.js.map +1 -1
- package/dist/esm/rendering/video/Video.d.ts +3 -7
- package/dist/esm/rendering/video/Video.js +3 -8
- package/dist/esm/rendering/video/Video.js.map +1 -1
- package/dist/esm/rendering/webgl2/WebGl2Backend.d.ts +40 -0
- package/dist/esm/rendering/webgl2/WebGl2Backend.js +303 -22
- package/dist/esm/rendering/webgl2/WebGl2Backend.js.map +1 -1
- package/dist/esm/rendering/webgl2/WebGl2MeshRenderer.d.ts +22 -2
- package/dist/esm/rendering/webgl2/WebGl2MeshRenderer.js +404 -112
- package/dist/esm/rendering/webgl2/WebGl2MeshRenderer.js.map +1 -1
- package/dist/esm/rendering/webgl2/WebGl2PassCoordinator.d.ts +57 -0
- package/dist/esm/rendering/webgl2/WebGl2PassCoordinator.js +79 -0
- package/dist/esm/rendering/webgl2/WebGl2PassCoordinator.js.map +1 -0
- package/dist/esm/rendering/webgl2/WebGl2SpriteRenderer.d.ts +12 -0
- package/dist/esm/rendering/webgl2/WebGl2SpriteRenderer.js +214 -58
- package/dist/esm/rendering/webgl2/WebGl2SpriteRenderer.js.map +1 -1
- package/dist/esm/rendering/webgl2/WebGl2StencilClipper.d.ts +34 -0
- package/dist/esm/rendering/webgl2/WebGl2StencilClipper.js +169 -0
- package/dist/esm/rendering/webgl2/WebGl2StencilClipper.js.map +1 -0
- package/dist/esm/rendering/webgl2/WebGl2TextRenderer.js +4 -0
- package/dist/esm/rendering/webgl2/WebGl2TextRenderer.js.map +1 -1
- package/dist/esm/rendering/webgl2/glsl/mesh.frag.js +1 -1
- package/dist/esm/rendering/webgl2/glsl/mesh.vert.js +1 -1
- package/dist/esm/rendering/webgl2/glsl/stencil-clip.frag.js +4 -0
- package/dist/esm/rendering/webgl2/glsl/stencil-clip.frag.js.map +1 -0
- package/dist/esm/rendering/webgl2/glsl/stencil-clip.vert.js +4 -0
- package/dist/esm/rendering/webgl2/glsl/stencil-clip.vert.js.map +1 -0
- package/dist/esm/rendering/webgpu/WebGpuBackend.d.ts +50 -0
- package/dist/esm/rendering/webgpu/WebGpuBackend.js +135 -19
- package/dist/esm/rendering/webgpu/WebGpuBackend.js.map +1 -1
- package/dist/esm/rendering/webgpu/WebGpuMaskCompositor.js +22 -17
- package/dist/esm/rendering/webgpu/WebGpuMaskCompositor.js.map +1 -1
- package/dist/esm/rendering/webgpu/WebGpuMeshRenderer.d.ts +24 -0
- package/dist/esm/rendering/webgpu/WebGpuMeshRenderer.js +488 -74
- package/dist/esm/rendering/webgpu/WebGpuMeshRenderer.js.map +1 -1
- package/dist/esm/rendering/webgpu/WebGpuParticleRenderer.js +13 -17
- package/dist/esm/rendering/webgpu/WebGpuParticleRenderer.js.map +1 -1
- package/dist/esm/rendering/webgpu/WebGpuPassCoordinator.d.ts +141 -0
- package/dist/esm/rendering/webgpu/WebGpuPassCoordinator.js +270 -0
- package/dist/esm/rendering/webgpu/WebGpuPassCoordinator.js.map +1 -0
- package/dist/esm/rendering/webgpu/WebGpuSpriteRenderer.d.ts +16 -0
- package/dist/esm/rendering/webgpu/WebGpuSpriteRenderer.js +335 -26
- package/dist/esm/rendering/webgpu/WebGpuSpriteRenderer.js.map +1 -1
- package/dist/esm/rendering/webgpu/WebGpuStencilClipper.d.ts +57 -0
- package/dist/esm/rendering/webgpu/WebGpuStencilClipper.js +257 -0
- package/dist/esm/rendering/webgpu/WebGpuStencilClipper.js.map +1 -0
- package/dist/esm/rendering/webgpu/WebGpuStencilState.d.ts +14 -0
- package/dist/esm/rendering/webgpu/WebGpuStencilState.js +36 -0
- package/dist/esm/rendering/webgpu/WebGpuStencilState.js.map +1 -0
- package/dist/esm/rendering/webgpu/WebGpuTextRenderer.js +14 -12
- package/dist/esm/rendering/webgpu/WebGpuTextRenderer.js.map +1 -1
- package/dist/esm/rendering/webgpu/WebGpuTransformStorage.d.ts +16 -0
- package/dist/esm/rendering/webgpu/WebGpuTransformStorage.js +57 -0
- package/dist/esm/rendering/webgpu/WebGpuTransformStorage.js.map +1 -0
- package/dist/esm/resources/JsonStore.d.ts +18 -0
- package/dist/esm/resources/JsonStore.js +62 -0
- package/dist/esm/resources/JsonStore.js.map +1 -0
- package/dist/esm/resources/factories/ImageFactory.d.ts +14 -8
- package/dist/esm/resources/factories/ImageFactory.js +13 -6
- package/dist/esm/resources/factories/ImageFactory.js.map +1 -1
- package/dist/esm/resources/factories/TextureFactory.d.ts +4 -4
- package/dist/esm/resources/factories/TextureFactory.js +8 -4
- package/dist/esm/resources/factories/TextureFactory.js.map +1 -1
- package/dist/esm/resources/index.d.ts +1 -0
- package/dist/exo.esm.js +5424 -2205
- package/dist/exo.esm.js.map +1 -1
- package/package.json +30 -24
- package/dist/esm/particles/distributions/Gradient.js.map +0 -1
- package/dist/esm/rendering/mesh/MeshShader.js.map +0 -1
- package/dist/esm/vendor/webgl-debug.js +0 -1160
- package/dist/esm/vendor/webgl-debug.js.map +0 -1
|
@@ -1,15 +1,18 @@
|
|
|
1
|
+
let nextShaderSourceId = 1;
|
|
1
2
|
/**
|
|
2
|
-
*
|
|
3
|
+
* Immutable shader source pair shared by {@link Material} instances.
|
|
3
4
|
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
5
|
+
* `ShaderSource` owns only the GLSL/WGSL text and its stable identity;
|
|
6
|
+
* it carries no uniform/texture state (that lives on the {@link Material}).
|
|
7
|
+
* One `ShaderSource` can back many materials, and renderers key their
|
|
8
|
+
* compiled program/pipeline caches on the source identity exposed via
|
|
9
|
+
* {@link id}.
|
|
8
10
|
*
|
|
9
11
|
* # Vertex layout
|
|
10
12
|
*
|
|
11
|
-
* The vertex layout is fixed and shared with the default
|
|
12
|
-
* so custom vertex shaders MUST pin the standard attribute
|
|
13
|
+
* The vertex layout for the mesh path is fixed and shared with the default
|
|
14
|
+
* mesh material, so custom vertex shaders MUST pin the standard attribute
|
|
15
|
+
* locations:
|
|
13
16
|
*
|
|
14
17
|
* ## GLSL (location-qualified)
|
|
15
18
|
*
|
|
@@ -31,16 +34,16 @@
|
|
|
31
34
|
*
|
|
32
35
|
* # Auto-bound uniforms
|
|
33
36
|
*
|
|
34
|
-
*
|
|
35
|
-
*
|
|
36
|
-
*
|
|
37
|
+
* Renderers auto-bind these when the source declares them. Declared but
|
|
38
|
+
* unused is fine; absent is fine too. Both backends carry the same logical
|
|
39
|
+
* uniforms, only the binding scheme differs.
|
|
37
40
|
*
|
|
38
41
|
* ## GLSL
|
|
39
42
|
*
|
|
40
43
|
* ```glsl
|
|
41
44
|
* uniform mat3 u_projection; // active view's projection
|
|
42
|
-
* uniform mat3 u_translation; //
|
|
43
|
-
* uniform vec4 u_tint; //
|
|
45
|
+
* uniform mat3 u_translation; // drawable's global transform
|
|
46
|
+
* uniform vec4 u_tint; // tint as RGBA in 0..1
|
|
44
47
|
* uniform sampler2D u_texture; // bound to texture slot 0
|
|
45
48
|
* ```
|
|
46
49
|
*
|
|
@@ -61,8 +64,9 @@
|
|
|
61
64
|
*
|
|
62
65
|
* # User uniforms
|
|
63
66
|
*
|
|
64
|
-
* Anything in {@link uniforms} is set after the auto-binds.
|
|
65
|
-
* `RenderTexture` values claim slots 1..N (slot 0 belongs to the
|
|
67
|
+
* Anything in {@link Material.uniforms} is set after the auto-binds.
|
|
68
|
+
* `Texture`/`RenderTexture` values claim slots 1..N (slot 0 belongs to the
|
|
69
|
+
* drawable's own texture).
|
|
66
70
|
*
|
|
67
71
|
* ## WGSL user-uniform contract
|
|
68
72
|
*
|
|
@@ -74,46 +78,37 @@
|
|
|
74
78
|
* in declaration order, alongside its sampler at `@binding(N+1)`.
|
|
75
79
|
* @advanced
|
|
76
80
|
*/
|
|
77
|
-
class
|
|
78
|
-
/**
|
|
79
|
-
* Mutable user uniform values. Mutate between frames to drive animated
|
|
80
|
-
* effects; the renderer reads from this map every draw.
|
|
81
|
-
*
|
|
82
|
-
* shader.uniforms.uTime = performance.now() / 1000;
|
|
83
|
-
* shader.uniforms.uColor = [1, 0.5, 0, 1];
|
|
84
|
-
*/
|
|
85
|
-
uniforms;
|
|
81
|
+
class ShaderSource {
|
|
86
82
|
/** GLSL source pair for the WebGL2 backend, or `null` if not provided. */
|
|
87
83
|
glsl;
|
|
88
84
|
/** WGSL source for the WebGPU backend, or `null` if not provided. */
|
|
89
85
|
wgsl;
|
|
90
|
-
|
|
86
|
+
_id;
|
|
91
87
|
constructor(options) {
|
|
92
88
|
if (options.glsl === undefined && options.wgsl === undefined) {
|
|
93
|
-
throw new Error('
|
|
89
|
+
throw new Error('ShaderSource requires at least one of `glsl` or `wgsl`.');
|
|
94
90
|
}
|
|
95
91
|
if (options.glsl !== undefined) {
|
|
96
92
|
if (typeof options.glsl.vertex !== 'string' || options.glsl.vertex.length === 0) {
|
|
97
|
-
throw new Error('
|
|
93
|
+
throw new Error('ShaderSource.glsl.vertex must be a non-empty string.');
|
|
98
94
|
}
|
|
99
95
|
if (typeof options.glsl.fragment !== 'string' || options.glsl.fragment.length === 0) {
|
|
100
|
-
throw new Error('
|
|
96
|
+
throw new Error('ShaderSource.glsl.fragment must be a non-empty string.');
|
|
101
97
|
}
|
|
102
98
|
}
|
|
103
99
|
if (options.wgsl !== undefined && (typeof options.wgsl !== 'string' || options.wgsl.length === 0)) {
|
|
104
|
-
throw new Error('
|
|
100
|
+
throw new Error('ShaderSource.wgsl must be a non-empty string.');
|
|
105
101
|
}
|
|
106
102
|
this.glsl = options.glsl ?? null;
|
|
107
103
|
this.wgsl = options.wgsl ?? null;
|
|
108
|
-
this.
|
|
104
|
+
this._id = nextShaderSourceId++;
|
|
109
105
|
}
|
|
110
106
|
/**
|
|
111
|
-
*
|
|
112
|
-
*
|
|
113
|
-
* over property mutation.
|
|
107
|
+
* Stable per-instance identity. Identical `id` ⇒ same compiled program/
|
|
108
|
+
* pipeline can be reused. Monotonic across the session; never reused.
|
|
114
109
|
*/
|
|
115
|
-
|
|
116
|
-
this.
|
|
110
|
+
get id() {
|
|
111
|
+
return this._id;
|
|
117
112
|
}
|
|
118
113
|
/**
|
|
119
114
|
* Reflect declared uniforms from each language's source. Returns a per-
|
|
@@ -124,8 +119,9 @@ class MeshShader {
|
|
|
124
119
|
*
|
|
125
120
|
* Reflection is best-effort and intended for CI drift-checks and editor
|
|
126
121
|
* tooling, not for runtime uniform binding decisions. The renderers do
|
|
127
|
-
* NOT consult this map; they bind uniforms by name from
|
|
128
|
-
* and let the underlying API resolve declared-
|
|
122
|
+
* NOT consult this map; they bind uniforms by name from
|
|
123
|
+
* {@link Material.uniforms} and let the underlying API resolve declared-
|
|
124
|
+
* but-unused entries.
|
|
129
125
|
*/
|
|
130
126
|
getDeclaredUniforms() {
|
|
131
127
|
return {
|
|
@@ -164,29 +160,6 @@ class MeshShader {
|
|
|
164
160
|
}
|
|
165
161
|
return { onlyInGlsl, onlyInWgsl };
|
|
166
162
|
}
|
|
167
|
-
/**
|
|
168
|
-
* Release GPU resources cached against this `MeshShader` on every
|
|
169
|
-
* backend that has compiled it. Safe to call multiple times. After
|
|
170
|
-
* destroy, the shader can still be re-used — renderers will recompile
|
|
171
|
-
* on next draw — but typical usage is to drop the reference.
|
|
172
|
-
*/
|
|
173
|
-
destroy() {
|
|
174
|
-
for (const callback of this._disposeCallbacks) {
|
|
175
|
-
callback();
|
|
176
|
-
}
|
|
177
|
-
this._disposeCallbacks.clear();
|
|
178
|
-
}
|
|
179
|
-
/**
|
|
180
|
-
* Internal hook for renderers to register a per-shader-instance cleanup
|
|
181
|
-
* callback (release compiled program, pipeline, or bind groups). The
|
|
182
|
-
* callback fires on {@link destroy}; renderers MUST also tolerate the
|
|
183
|
-
* shader being garbage-collected without destroy ever being called.
|
|
184
|
-
*
|
|
185
|
-
* @internal
|
|
186
|
-
*/
|
|
187
|
-
_onDispose(callback) {
|
|
188
|
-
this._disposeCallbacks.add(callback);
|
|
189
|
-
}
|
|
190
163
|
}
|
|
191
164
|
const autoBoundUniformNames = new Set(['u_projection', 'u_translation', 'u_tint', 'u_texture', 'u_mesh']);
|
|
192
165
|
const glslUniformPattern = /\buniform\s+(?:mediump\s+|highp\s+|lowp\s+|)(\w+)\s+(\w+)[^;]*;/g;
|
|
@@ -194,7 +167,7 @@ const wgslUserUniformPattern = /@group\(\s*2\s*\)\s*@binding\(\s*\d+\s*\)\s*var(
|
|
|
194
167
|
/**
|
|
195
168
|
* Strip line and block comments from a shader source so the uniform
|
|
196
169
|
* regexes don't match commented-out declarations. Conservative: works
|
|
197
|
-
* for both GLSL and WGSL syntax (both use `//` and
|
|
170
|
+
* for both GLSL and WGSL syntax (both use `//` and block comments).
|
|
198
171
|
*/
|
|
199
172
|
function stripComments(source) {
|
|
200
173
|
return source.replaceAll(/\/\*[\s\S]*?\*\//g, '').replaceAll(/\/\/[^\n]*/g, '');
|
|
@@ -228,5 +201,5 @@ function parseWgslUniforms(source) {
|
|
|
228
201
|
return result;
|
|
229
202
|
}
|
|
230
203
|
|
|
231
|
-
export {
|
|
232
|
-
//# sourceMappingURL=
|
|
204
|
+
export { ShaderSource };
|
|
205
|
+
//# sourceMappingURL=ShaderSource.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ShaderSource.js","sources":["../../../../../src/rendering/material/ShaderSource.ts"],"sourcesContent":[null],"names":[],"mappings":"AAyBA,IAAI,kBAAkB,GAAG,CAAC;AAE1B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA8EG;MACU,YAAY,CAAA;;AAEP,IAAA,IAAI;;AAGJ,IAAA,IAAI;AAEH,IAAA,GAAG;AAEpB,IAAA,WAAA,CAAmB,OAA4B,EAAA;AAC7C,QAAA,IAAI,OAAO,CAAC,IAAI,KAAK,SAAS,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AI,EAAE;IAC5B;AAEA,IAAA,OAAO,MAAM;AACf;;;;"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { MaterialOptions } from './Material';
|
|
2
|
+
import { Material } from './Material';
|
|
3
|
+
/**
|
|
4
|
+
* Material specialization for {@link Sprite} drawables.
|
|
5
|
+
*
|
|
6
|
+
* API shell for the sprite custom-material path; the renderer integration
|
|
7
|
+
* and instancing contract are added in a later phase. The base texture
|
|
8
|
+
* stays on the sprite — this material supplies the fragment program,
|
|
9
|
+
* uniforms, and additional texture bindings.
|
|
10
|
+
* @advanced
|
|
11
|
+
*/
|
|
12
|
+
export declare class SpriteMaterial extends Material {
|
|
13
|
+
readonly target = "sprite";
|
|
14
|
+
constructor(options: MaterialOptions);
|
|
15
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { Material } from './Material.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Material specialization for {@link Sprite} drawables.
|
|
5
|
+
*
|
|
6
|
+
* API shell for the sprite custom-material path; the renderer integration
|
|
7
|
+
* and instancing contract are added in a later phase. The base texture
|
|
8
|
+
* stays on the sprite — this material supplies the fragment program,
|
|
9
|
+
* uniforms, and additional texture bindings.
|
|
10
|
+
* @advanced
|
|
11
|
+
*/
|
|
12
|
+
class SpriteMaterial extends Material {
|
|
13
|
+
target = 'sprite';
|
|
14
|
+
constructor(options) {
|
|
15
|
+
super(options);
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export { SpriteMaterial };
|
|
20
|
+
//# sourceMappingURL=SpriteMaterial.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SpriteMaterial.js","sources":["../../../../../src/rendering/material/SpriteMaterial.ts"],"sourcesContent":[null],"names":[],"mappings":";;AAGA;;;;;;;;AAQG;AACG,MAAO,cAAe,SAAQ,QAAQ,CAAA;IAC1B,MAAM,GAAG,QAAQ;AAEjC,IAAA,WAAA,CAAmB,OAAwB,EAAA;QACzC,KAAK,CAAC,OAAO,CAAC;IAChB;AACD;;;;"}
|
|
@@ -1,29 +1,43 @@
|
|
|
1
1
|
import { Drawable } from '@/rendering/Drawable';
|
|
2
|
-
import type {
|
|
2
|
+
import type { Geometry } from '@/rendering/geometry/Geometry';
|
|
3
|
+
import type { MeshMaterial } from '@/rendering/material/MeshMaterial';
|
|
3
4
|
import type { RenderTexture } from '@/rendering/texture/RenderTexture';
|
|
4
5
|
import type { Texture } from '@/rendering/texture/Texture';
|
|
5
6
|
/**
|
|
6
7
|
* Construction-time options for a {@link Mesh}.
|
|
7
8
|
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
9
|
+
* Provide the geometry in exactly one of two forms:
|
|
10
|
+
*
|
|
11
|
+
* - **Convenience form** — a flat `vertices` array of (x, y) pairs in local
|
|
12
|
+
* space, with optional `uvs`, per-vertex `colors`, and `indices`. This is
|
|
13
|
+
* the simplest path: `new Mesh({ vertices })`.
|
|
14
|
+
* - **Geometry form** — a {@link Geometry} object whose standard attributes
|
|
15
|
+
* (`a_position`/`position`, `a_texcoord`/`texcoord`, `a_color`/`color`) are
|
|
16
|
+
* read into the mesh: `new Mesh({ geometry })`. The geometry must use the
|
|
17
|
+
* `triangle-list` topology.
|
|
18
|
+
*
|
|
19
|
+
* Supplying both `vertices` and `geometry`, or neither, throws.
|
|
20
|
+
*
|
|
21
|
+
* When present, `uvs` must match the vertex count (as (u, v) pairs) and
|
|
22
|
+
* `colors` must supply one packed-RGBA8 u32 per vertex. `indices` are optional
|
|
23
|
+
* — if absent, the vertex stream is drawn as a flat triangle list (3*N
|
|
24
|
+
* vertices = N triangles). A texture is optional; a textured mesh samples it
|
|
25
|
+
* at the supplied UVs while an untextured mesh paints solid vertex colors only.
|
|
15
26
|
*
|
|
16
27
|
* Validation is enforced at construction; any mismatch throws.
|
|
17
28
|
*
|
|
18
|
-
* For custom shaders,
|
|
29
|
+
* For custom shaders/uniforms/textures, attach a {@link MeshMaterial}.
|
|
19
30
|
*/
|
|
20
31
|
export interface MeshOptions {
|
|
21
|
-
readonly vertices
|
|
32
|
+
readonly vertices?: Float32Array;
|
|
22
33
|
readonly indices?: Uint16Array;
|
|
23
34
|
readonly uvs?: Float32Array;
|
|
24
35
|
readonly colors?: Uint32Array;
|
|
36
|
+
/** Interleaved geometry source; mutually exclusive with `vertices`. */
|
|
37
|
+
readonly geometry?: Geometry;
|
|
25
38
|
readonly texture?: Texture | RenderTexture | null;
|
|
26
|
-
|
|
39
|
+
/** Custom look (shader/uniforms/textures/blendMode); `null` uses the default mesh material. */
|
|
40
|
+
readonly material?: MeshMaterial;
|
|
27
41
|
}
|
|
28
42
|
/**
|
|
29
43
|
* Arbitrary 2D triangle-mesh primitive.
|
|
@@ -58,7 +72,10 @@ export declare class Mesh extends Drawable {
|
|
|
58
72
|
readonly indices: Uint16Array | null;
|
|
59
73
|
readonly uvs: Float32Array | null;
|
|
60
74
|
readonly colors: Uint32Array | null;
|
|
61
|
-
|
|
75
|
+
/** Custom material attached to this mesh, or `null` for the default mesh path. */
|
|
76
|
+
readonly material: MeshMaterial | null;
|
|
77
|
+
/** Source geometry when constructed from the geometry form, otherwise `null`. */
|
|
78
|
+
readonly geometry: Geometry | null;
|
|
62
79
|
private _texture;
|
|
63
80
|
constructor(options: MeshOptions);
|
|
64
81
|
/** Number of (x, y) vertex pairs in the mesh (i.e. `vertices.length / 2`). */
|
|
@@ -33,11 +33,40 @@ class Mesh extends Drawable {
|
|
|
33
33
|
indices;
|
|
34
34
|
uvs;
|
|
35
35
|
colors;
|
|
36
|
-
|
|
36
|
+
/** Custom material attached to this mesh, or `null` for the default mesh path. */
|
|
37
|
+
material;
|
|
38
|
+
/** Source geometry when constructed from the geometry form, otherwise `null`. */
|
|
39
|
+
geometry;
|
|
37
40
|
_texture;
|
|
38
41
|
constructor(options) {
|
|
39
42
|
super();
|
|
40
|
-
const {
|
|
43
|
+
const { texture = null, material = null } = options;
|
|
44
|
+
let vertices;
|
|
45
|
+
let indices;
|
|
46
|
+
let uvs;
|
|
47
|
+
let colors;
|
|
48
|
+
let geometry;
|
|
49
|
+
if (options.geometry !== undefined) {
|
|
50
|
+
if (options.vertices !== undefined) {
|
|
51
|
+
throw new Error('Mesh accepts either `vertices` or `geometry`, not both.');
|
|
52
|
+
}
|
|
53
|
+
geometry = options.geometry;
|
|
54
|
+
const data = readGeometry(geometry);
|
|
55
|
+
vertices = data.vertices;
|
|
56
|
+
uvs = data.uvs;
|
|
57
|
+
colors = data.colors;
|
|
58
|
+
indices = data.indices;
|
|
59
|
+
}
|
|
60
|
+
else {
|
|
61
|
+
if (options.vertices === undefined) {
|
|
62
|
+
throw new Error('Mesh requires either `vertices` or `geometry`.');
|
|
63
|
+
}
|
|
64
|
+
geometry = null;
|
|
65
|
+
vertices = options.vertices;
|
|
66
|
+
indices = options.indices ?? null;
|
|
67
|
+
uvs = options.uvs ?? null;
|
|
68
|
+
colors = options.colors ?? null;
|
|
69
|
+
}
|
|
41
70
|
if (vertices.length === 0 || vertices.length % 2 !== 0) {
|
|
42
71
|
throw new Error(`Mesh vertices must be a non-empty flat array of (x,y) pairs (got length ${vertices.length}).`);
|
|
43
72
|
}
|
|
@@ -68,7 +97,8 @@ class Mesh extends Drawable {
|
|
|
68
97
|
this.indices = indices;
|
|
69
98
|
this.uvs = uvs;
|
|
70
99
|
this.colors = colors;
|
|
71
|
-
this.
|
|
100
|
+
this.material = material;
|
|
101
|
+
this.geometry = geometry;
|
|
72
102
|
this._texture = texture;
|
|
73
103
|
this.recomputeLocalBounds();
|
|
74
104
|
}
|
|
@@ -114,6 +144,95 @@ class Mesh extends Drawable {
|
|
|
114
144
|
return this;
|
|
115
145
|
}
|
|
116
146
|
}
|
|
147
|
+
const positionAttributeNames = new Set(['a_position', 'position']);
|
|
148
|
+
const texcoordAttributeNames = new Set(['a_texcoord', 'texcoord', 'a_uv', 'uv']);
|
|
149
|
+
const colorAttributeNames = new Set(['a_color', 'color']);
|
|
150
|
+
const findAttribute = (attributes, names) => attributes.find(attribute => names.has(attribute.name));
|
|
151
|
+
/**
|
|
152
|
+
* Read a {@link Geometry}'s standard mesh attributes into the flat
|
|
153
|
+
* `vertices`/`uvs`/`colors` arrays the mesh renderers consume. Only the
|
|
154
|
+
* `triangle-list` topology and the canonical attribute layout (`f32` position
|
|
155
|
+
* and texcoord, `u8`/`u32`/`f32` color) are supported — this is the immediate
|
|
156
|
+
* (non-batched) bridge; shared GPU buffers and instancing arrive later.
|
|
157
|
+
*/
|
|
158
|
+
function readGeometry(geometry) {
|
|
159
|
+
if (geometry.topology !== 'triangle-list') {
|
|
160
|
+
throw new Error(`Mesh only supports triangle-list geometry (got "${geometry.topology}").`);
|
|
161
|
+
}
|
|
162
|
+
const position = findAttribute(geometry.attributes, positionAttributeNames);
|
|
163
|
+
if (position === undefined) {
|
|
164
|
+
throw new Error('Mesh geometry requires a position attribute named `a_position` or `position`.');
|
|
165
|
+
}
|
|
166
|
+
if (position.type !== 'f32' || position.size < 2) {
|
|
167
|
+
throw new Error('Mesh geometry position attribute must be a float vector with at least 2 components.');
|
|
168
|
+
}
|
|
169
|
+
const texcoord = findAttribute(geometry.attributes, texcoordAttributeNames);
|
|
170
|
+
if (texcoord !== undefined && (texcoord.type !== 'f32' || texcoord.size < 2)) {
|
|
171
|
+
throw new Error('Mesh geometry texcoord attribute must be a float vector with at least 2 components.');
|
|
172
|
+
}
|
|
173
|
+
const color = findAttribute(geometry.attributes, colorAttributeNames);
|
|
174
|
+
const vertexCount = geometry.vertexCount;
|
|
175
|
+
const { stride } = geometry;
|
|
176
|
+
const source = geometry.vertexData;
|
|
177
|
+
const view = source instanceof Float32Array ? new DataView(source.buffer, source.byteOffset, source.byteLength) : new DataView(source);
|
|
178
|
+
const vertices = new Float32Array(vertexCount * 2);
|
|
179
|
+
const uvs = texcoord !== undefined ? new Float32Array(vertexCount * 2) : null;
|
|
180
|
+
const colors = color !== undefined ? new Uint32Array(vertexCount) : null;
|
|
181
|
+
for (let i = 0; i < vertexCount; i++) {
|
|
182
|
+
const base = i * stride;
|
|
183
|
+
vertices[i * 2] = view.getFloat32(base + position.offset, true);
|
|
184
|
+
vertices[i * 2 + 1] = view.getFloat32(base + position.offset + 4, true);
|
|
185
|
+
if (uvs !== null && texcoord !== undefined) {
|
|
186
|
+
uvs[i * 2] = view.getFloat32(base + texcoord.offset, true);
|
|
187
|
+
uvs[i * 2 + 1] = view.getFloat32(base + texcoord.offset + 4, true);
|
|
188
|
+
}
|
|
189
|
+
if (colors !== null && color !== undefined) {
|
|
190
|
+
colors[i] = readPackedColor(view, base + color.offset, color);
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
const indices = readIndices(geometry.indices, vertexCount);
|
|
194
|
+
return { vertices, uvs, colors, indices };
|
|
195
|
+
}
|
|
196
|
+
/** Pack a geometry color attribute into the mesh's RGBA8 u32 representation. */
|
|
197
|
+
function readPackedColor(view, offset, attribute) {
|
|
198
|
+
if (attribute.type === 'u32' && attribute.size === 1) {
|
|
199
|
+
return view.getUint32(offset, true) >>> 0;
|
|
200
|
+
}
|
|
201
|
+
if (attribute.type === 'u8' && attribute.size === 4) {
|
|
202
|
+
const r = view.getUint8(offset);
|
|
203
|
+
const g = view.getUint8(offset + 1);
|
|
204
|
+
const b = view.getUint8(offset + 2);
|
|
205
|
+
const a = view.getUint8(offset + 3);
|
|
206
|
+
return (r | (g << 8) | (b << 16) | (a << 24)) >>> 0;
|
|
207
|
+
}
|
|
208
|
+
if (attribute.type === 'f32' && attribute.size === 4) {
|
|
209
|
+
const r = Math.round(clamp01(view.getFloat32(offset, true)) * 255);
|
|
210
|
+
const g = Math.round(clamp01(view.getFloat32(offset + 4, true)) * 255);
|
|
211
|
+
const b = Math.round(clamp01(view.getFloat32(offset + 8, true)) * 255);
|
|
212
|
+
const a = Math.round(clamp01(view.getFloat32(offset + 12, true)) * 255);
|
|
213
|
+
return (r | (g << 8) | (b << 16) | (a << 24)) >>> 0;
|
|
214
|
+
}
|
|
215
|
+
throw new Error('Mesh geometry color attribute must be u8x4, u32x1, or f32x4.');
|
|
216
|
+
}
|
|
217
|
+
function readIndices(indices, vertexCount) {
|
|
218
|
+
if (indices === null) {
|
|
219
|
+
return null;
|
|
220
|
+
}
|
|
221
|
+
if (indices instanceof Uint16Array) {
|
|
222
|
+
return indices;
|
|
223
|
+
}
|
|
224
|
+
if (vertexCount > 0xffff) {
|
|
225
|
+
throw new Error(`Mesh geometry with ${vertexCount} vertices exceeds the 16-bit index limit.`);
|
|
226
|
+
}
|
|
227
|
+
return Uint16Array.from(indices);
|
|
228
|
+
}
|
|
229
|
+
function clamp01(value) {
|
|
230
|
+
if (value < 0)
|
|
231
|
+
return 0;
|
|
232
|
+
if (value > 1)
|
|
233
|
+
return 1;
|
|
234
|
+
return value;
|
|
235
|
+
}
|
|
117
236
|
|
|
118
237
|
export { Mesh };
|
|
119
238
|
//# sourceMappingURL=Mesh.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Mesh.js","sources":["../../../../../src/rendering/mesh/Mesh.ts"],"sourcesContent":[null],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"Mesh.js","sources":["../../../../../src/rendering/mesh/Mesh.ts"],"sourcesContent":[null],"names":[],"mappings":";;AA4CA;;;;;;;;;;;;;;;;;;;;;;;;;;;AA2BG;AACG,MAAO,IAAK,SAAQ,QAAQ,CAAA;AAChB,IAAA,QAAQ;AACR,IAAA,OAAO;AACP,IAAA,GAAG;AACH,IAAA,MAAM;;AAGN,IAAA,QAAQ;;AAGR,IAAA,QAAQ;AAEhB,IAAA,QAAQ;AAEhB,IAAA,WAAA,CAAmB,OAAoB,EAAA;AACrC,QAAA,KAAK,EAAE;QAEP,MAAM,EAAE,OAAO,GAAG,IAAI,EAAE,QAAQ,GAAG,IAAI,EAAE,GAAG,OAAO;AAEnD,QAAA,IAAI,QAAsB;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;AACjF;AAEA,SAAS,WAAW,CAAC,OAAyC,EAAE,WAAmB,EAAA;AACjF,IAAA,IAAI,OAAO,KAAK,IAAI,EAAE;AACpB,QAAA,OAAO,IAAI;IACb;AAEA,IAAA,IAAI,OAAO,YAAY,WAAW,EAAE;AAClC,QAAA,OAAO,OAAO;IAChB;AAEA,IAAA,IAAI,WAAW,GAAG,MAAM,EAAE;AACxB,QAAA,MAAM,IAAI,KAAK,CAAC,sBAAsB,WAAW,CAAA,yCAAA,CAA2C,CAAC;IAC/F;AAEA,IAAA,OAAO,WAAW,CAAC,IAAI,CAAC,OAAO,CAAC;AAClC;AAEA,SAAS,OAAO,CAAC,KAAa,EAAA;IAC5B,IAAI,KAAK,GAAG,CAAC;AAAE,QAAA,OAAO,CAAC;IACvB,IAAI,KAAK,GAAG,CAAC;AAAE,QAAA,OAAO,CAAC;AACvB,IAAA,OAAO,KAAK;AACd;;;;"}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import type { Matrix } from '@/math/Matrix';
|
|
2
|
+
import type { Rectangle } from '@/math/Rectangle';
|
|
3
|
+
import type { Geometry } from '../geometry/Geometry';
|
|
4
|
+
import type { RenderTarget } from '../RenderTarget';
|
|
5
|
+
import type { View } from '../View';
|
|
6
|
+
import type { RenderPassDescriptor, RenderPassLoad } from './RenderPassDescriptor';
|
|
7
|
+
/**
|
|
8
|
+
* Internal, backend-owned owner of render-pass lifecycle: target / view / clear
|
|
9
|
+
* orchestration, the scissor and stencil-clip stacks, and — on WebGPU, from
|
|
10
|
+
* phase 12D — the active `GPURenderPassEncoder`.
|
|
11
|
+
*
|
|
12
|
+
* There is no public RenderPass API. This abstraction exists so the WebGL2 and
|
|
13
|
+
* WebGPU backends can share the orchestration shape that geometric stencil
|
|
14
|
+
* clipping needs, while each maps it onto its own state model: WebGL2 onto
|
|
15
|
+
* ambient GL state (bound framebuffer, viewport, scissor, stencil), WebGPU onto
|
|
16
|
+
* explicit render passes built up front with their attachments.
|
|
17
|
+
* @internal
|
|
18
|
+
*/
|
|
19
|
+
export interface RenderPassCoordinator {
|
|
20
|
+
/** The target the active pass draws into (the backend root when idle). */
|
|
21
|
+
readonly activeTarget: RenderTarget;
|
|
22
|
+
/** The view the active pass renders with. */
|
|
23
|
+
readonly activeView: View;
|
|
24
|
+
/** Whether a pass is currently open. */
|
|
25
|
+
readonly hasActivePass: boolean;
|
|
26
|
+
/** Open a pass for `descriptor`, applying its target / view / clear / stencil state. */
|
|
27
|
+
beginPass(descriptor: RenderPassDescriptor): void;
|
|
28
|
+
/** Close the active pass, flushing any pending draws into it. */
|
|
29
|
+
endPass(): void;
|
|
30
|
+
/**
|
|
31
|
+
* Run `body` inside a child pass described by `descriptor`, restoring the
|
|
32
|
+
* previous target and view afterwards — even if `body` throws. Preserves the
|
|
33
|
+
* save / restore semantics of {@link RenderTargetPass}.
|
|
34
|
+
*/
|
|
35
|
+
withChildPass(descriptor: RenderPassDescriptor, body: () => void): void;
|
|
36
|
+
/** Push an axis-aligned scissor rectangle; nested rectangles intersect. */
|
|
37
|
+
pushScissorRect(bounds: Rectangle): void;
|
|
38
|
+
/** Pop the most recently pushed scissor rectangle. */
|
|
39
|
+
popScissorRect(): void;
|
|
40
|
+
/** Push a geometric stencil clip — the `shape` silhouette under `transform`. */
|
|
41
|
+
pushStencilClip(shape: Geometry, transform: Matrix): void;
|
|
42
|
+
/** Pop the most recently pushed stencil clip. */
|
|
43
|
+
popStencilClip(): void;
|
|
44
|
+
/**
|
|
45
|
+
* Decide whether `target` should be cleared or loaded given an explicit clear
|
|
46
|
+
* request. Centralizes the clear-vs-load / content-preservation decision so a
|
|
47
|
+
* render texture's contents survive across multiple passes in one frame.
|
|
48
|
+
*/
|
|
49
|
+
resolveLoad(target: RenderTarget, clearRequested: boolean): RenderPassLoad;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Duck-typing host for backends that own a {@link RenderPassCoordinator}.
|
|
53
|
+
*
|
|
54
|
+
* Generic, `RenderBackend`-typed orchestration code ({@link RenderTargetPass},
|
|
55
|
+
* {@link RenderingContext.renderTo}) reaches the coordinator through this
|
|
56
|
+
* optional accessor and falls back to a legacy inline target/view save-restore
|
|
57
|
+
* when it is absent (e.g. test stub backends), mirroring the `_beginDrawPlan?`
|
|
58
|
+
* hook pattern used by `RenderPlanPlayer`.
|
|
59
|
+
* @internal
|
|
60
|
+
*/
|
|
61
|
+
export interface RenderPassCoordinatorHost {
|
|
62
|
+
readonly _passCoordinator: RenderPassCoordinator;
|
|
63
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import type { Color } from '@/core/Color';
|
|
2
|
+
import type { RenderTarget } from '../RenderTarget';
|
|
3
|
+
import type { View } from '../View';
|
|
4
|
+
/**
|
|
5
|
+
* Whether a render pass carries a stencil attachment.
|
|
6
|
+
*
|
|
7
|
+
* WebGL2 stencil is ambient per-target GL state, so this flag is largely
|
|
8
|
+
* informational there; the WebGPU backend (from phase 12D onwards) uses it to
|
|
9
|
+
* decide whether a pass descriptor needs a `depthStencilAttachment`.
|
|
10
|
+
* @internal
|
|
11
|
+
*/
|
|
12
|
+
export declare enum StencilAttachmentMode {
|
|
13
|
+
None = 0,
|
|
14
|
+
Enabled = 1
|
|
15
|
+
}
|
|
16
|
+
/** Load behaviour for a pass's colour attachment. @internal */
|
|
17
|
+
export type RenderPassLoad = 'clear' | 'load';
|
|
18
|
+
/**
|
|
19
|
+
* Backend-agnostic description of a single render pass: which target and view
|
|
20
|
+
* it draws into, whether it clears or loads its colour attachment, and whether
|
|
21
|
+
* it carries a stencil attachment.
|
|
22
|
+
*
|
|
23
|
+
* WebGL2 maps this onto ambient framebuffer / viewport / scissor / stencil
|
|
24
|
+
* state; WebGPU (phase 12D onwards) maps it onto a `GPURenderPassEncoder`.
|
|
25
|
+
* @internal
|
|
26
|
+
*/
|
|
27
|
+
export interface RenderPassDescriptor {
|
|
28
|
+
/** Target to draw into. `null` selects the backend's root (canvas) target. */
|
|
29
|
+
readonly target: RenderTarget | null;
|
|
30
|
+
/** View to render with. `null` inherits the target's current view. */
|
|
31
|
+
readonly view: View | null;
|
|
32
|
+
/** Whether the colour attachment is cleared or preserved when the pass begins. */
|
|
33
|
+
readonly load: RenderPassLoad;
|
|
34
|
+
/** Clear colour used when `load === 'clear'`. `null` keeps the backend's current clear colour. */
|
|
35
|
+
readonly clearColor: Color | null;
|
|
36
|
+
/** Whether this pass carries a stencil attachment. */
|
|
37
|
+
readonly stencil: StencilAttachmentMode;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Snapshot of the pass currently open on a {@link RenderPassCoordinator}. The
|
|
41
|
+
* WebGPU coordinator exposes the live encoder alongside these fields from phase
|
|
42
|
+
* 12D; the shared shape lives here so both backends agree on it.
|
|
43
|
+
* @internal
|
|
44
|
+
*/
|
|
45
|
+
export interface ActiveRenderPass {
|
|
46
|
+
readonly view: View;
|
|
47
|
+
readonly stencilEnabled: boolean;
|
|
48
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Whether a render pass carries a stencil attachment.
|
|
3
|
+
*
|
|
4
|
+
* WebGL2 stencil is ambient per-target GL state, so this flag is largely
|
|
5
|
+
* informational there; the WebGPU backend (from phase 12D onwards) uses it to
|
|
6
|
+
* decide whether a pass descriptor needs a `depthStencilAttachment`.
|
|
7
|
+
* @internal
|
|
8
|
+
*/
|
|
9
|
+
var StencilAttachmentMode;
|
|
10
|
+
(function (StencilAttachmentMode) {
|
|
11
|
+
StencilAttachmentMode[StencilAttachmentMode["None"] = 0] = "None";
|
|
12
|
+
StencilAttachmentMode[StencilAttachmentMode["Enabled"] = 1] = "Enabled";
|
|
13
|
+
})(StencilAttachmentMode || (StencilAttachmentMode = {}));
|
|
14
|
+
|
|
15
|
+
export { StencilAttachmentMode };
|
|
16
|
+
//# sourceMappingURL=RenderPassDescriptor.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"RenderPassDescriptor.js","sources":["../../../../../src/rendering/pass/RenderPassDescriptor.ts"],"sourcesContent":[null],"names":[],"mappings":"AAKA;;;;;;;AAOG;IACS;AAAZ,CAAA,UAAY,qBAAqB,EAAA;AAC/B,IAAA,qBAAA,CAAA,qBAAA,CAAA,MAAA,CAAA,GAAA,CAAA,CAAA,GAAA,MAAQ;AACR,IAAA,qBAAA,CAAA,qBAAA,CAAA,SAAA,CAAA,GAAA,CAAA,CAAA,GAAA,SAAW;AACb,CAAC,EAHW,qBAAqB,KAArB,qBAAqB,GAAA,EAAA,CAAA,CAAA;;;;"}
|