modern-canvas 0.24.7 → 0.24.9
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.
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { GlUniform } from './GlProgram';
|
|
1
2
|
export declare class GlProgramData {
|
|
2
3
|
native: WebGLProgram;
|
|
3
4
|
/**
|
|
@@ -6,5 +7,16 @@ export declare class GlProgramData {
|
|
|
6
7
|
* group's data is (re)uploaded to this program.
|
|
7
8
|
*/
|
|
8
9
|
uniformDirtyGroups: Record<number, number>;
|
|
10
|
+
/**
|
|
11
|
+
* Per-context uniform metadata: introspected name/type/size plus the lazily
|
|
12
|
+
* resolved {@link GlUniform.location} and the shadow copy of the last uploaded
|
|
13
|
+
* value. Both `location` and `value` are specific to THIS linked program in
|
|
14
|
+
* THIS GL context, so they must live here — not on the shared {@link GlProgram},
|
|
15
|
+
* which a module-level (static) Material reuses across multiple renderers/contexts.
|
|
16
|
+
* Storing them on the shared program would let one context clobber another's
|
|
17
|
+
* locations/shadows (e.g. a sampler `uniform1i` silently dropped → the sampler
|
|
18
|
+
* falls back to texture unit 0).
|
|
19
|
+
*/
|
|
20
|
+
uniforms: Record<string, GlUniform>;
|
|
9
21
|
constructor(native: WebGLProgram);
|
|
10
22
|
}
|
|
@@ -36,7 +36,7 @@ export declare class GlShaderSystem extends GlSystem {
|
|
|
36
36
|
* the group has not changed since it was last synced to this program.
|
|
37
37
|
*/
|
|
38
38
|
updateUniformGroup(group: UniformGroup, glProgram: GlProgram): void;
|
|
39
|
-
protected _uploadUniforms(
|
|
39
|
+
protected _uploadUniforms(glProgramData: GlProgramData, uniforms: Record<string, any>): void;
|
|
40
40
|
reset(): void;
|
|
41
41
|
destroy(): void;
|
|
42
42
|
}
|
package/dist/index.js
CHANGED
|
@@ -1525,6 +1525,7 @@ function Yt(e) {
|
|
|
1525
1525
|
var Xt = class {
|
|
1526
1526
|
native;
|
|
1527
1527
|
uniformDirtyGroups = Object.create(null);
|
|
1528
|
+
uniforms = Object.create(null);
|
|
1528
1529
|
constructor(e) {
|
|
1529
1530
|
this.native = e;
|
|
1530
1531
|
}
|
|
@@ -1677,7 +1678,7 @@ var nn = class extends M {
|
|
|
1677
1678
|
value: void 0
|
|
1678
1679
|
};
|
|
1679
1680
|
}
|
|
1680
|
-
return
|
|
1681
|
+
return n.uniforms = c, t.deleteShader(r), t.deleteShader(i), n;
|
|
1681
1682
|
}
|
|
1682
1683
|
_createGlShader(e, t) {
|
|
1683
1684
|
let n = this._gl, r = n.createShader(t);
|
|
@@ -1688,72 +1689,72 @@ var nn = class extends M {
|
|
|
1688
1689
|
updateUniforms(e) {
|
|
1689
1690
|
this.bind(e);
|
|
1690
1691
|
let { glProgram: t, uniforms: n = {} } = e;
|
|
1691
|
-
this._uploadUniforms(
|
|
1692
|
+
this._uploadUniforms(this.getGlProgramData(t), n);
|
|
1692
1693
|
}
|
|
1693
1694
|
updateUniformGroup(e, t) {
|
|
1694
1695
|
let n = this.getGlProgramData(t);
|
|
1695
|
-
e.isStatic && n.uniformDirtyGroups[e.uid] === e._dirtyId || (n.uniformDirtyGroups[e.uid] = e._dirtyId, this.useProgram(t), this._uploadUniforms(
|
|
1696
|
+
e.isStatic && n.uniformDirtyGroups[e.uid] === e._dirtyId || (n.uniformDirtyGroups[e.uid] = e._dirtyId, this.useProgram(t), this._uploadUniforms(n, e.uniforms));
|
|
1696
1697
|
}
|
|
1697
|
-
_uploadUniforms(e, t
|
|
1698
|
-
let
|
|
1699
|
-
for (let
|
|
1700
|
-
let a =
|
|
1698
|
+
_uploadUniforms(e, t) {
|
|
1699
|
+
let n = this._gl, { uniforms: r } = e;
|
|
1700
|
+
for (let i in t) {
|
|
1701
|
+
let a = t[i], o = r[i];
|
|
1701
1702
|
if (!o) continue;
|
|
1702
1703
|
let { type: s, isArray: c, name: l } = o;
|
|
1703
|
-
o.location === void 0 && (o.location =
|
|
1704
|
+
o.location === void 0 && (o.location = n.getUniformLocation(e.native, l));
|
|
1704
1705
|
let u = o.location;
|
|
1705
1706
|
if (rn(o.value, a)) switch (o.value = an(o.value, a), s) {
|
|
1706
1707
|
case "float":
|
|
1707
|
-
c ?
|
|
1708
|
+
c ? n.uniform1fv(u, a) : n.uniform1f(u, a);
|
|
1708
1709
|
break;
|
|
1709
1710
|
case "uint":
|
|
1710
|
-
c ?
|
|
1711
|
+
c ? n.uniform1uiv(u, a) : n.uniform1ui(u, a);
|
|
1711
1712
|
break;
|
|
1712
1713
|
case "bool":
|
|
1713
1714
|
case "int":
|
|
1714
1715
|
case "sampler2D":
|
|
1715
1716
|
case "samplerCube":
|
|
1716
1717
|
case "sampler2DArray":
|
|
1717
|
-
c ?
|
|
1718
|
+
c ? n.uniform1iv(u, a) : n.uniform1i(u, a);
|
|
1718
1719
|
break;
|
|
1719
1720
|
case "bvec2":
|
|
1720
1721
|
case "ivec2":
|
|
1721
|
-
|
|
1722
|
+
n.uniform2iv(u, a);
|
|
1722
1723
|
break;
|
|
1723
1724
|
case "uvec2":
|
|
1724
|
-
|
|
1725
|
+
n.uniform2uiv(u, a);
|
|
1725
1726
|
break;
|
|
1726
1727
|
case "vec2":
|
|
1727
|
-
|
|
1728
|
+
n.uniform2fv(u, a);
|
|
1728
1729
|
break;
|
|
1729
1730
|
case "bvec3":
|
|
1730
1731
|
case "ivec3":
|
|
1731
|
-
|
|
1732
|
+
n.uniform3iv(u, a);
|
|
1732
1733
|
break;
|
|
1733
1734
|
case "uvec3":
|
|
1734
|
-
|
|
1735
|
+
n.uniform3uiv(u, a);
|
|
1735
1736
|
break;
|
|
1736
1737
|
case "vec3":
|
|
1737
|
-
|
|
1738
|
+
n.uniform3fv(u, a);
|
|
1738
1739
|
break;
|
|
1739
1740
|
case "bvec4":
|
|
1740
1741
|
case "ivec4":
|
|
1741
|
-
|
|
1742
|
+
n.uniform4iv(u, a);
|
|
1742
1743
|
break;
|
|
1743
1744
|
case "uvec4":
|
|
1744
|
-
|
|
1745
|
+
n.uniform4uiv(u, a);
|
|
1745
1746
|
break;
|
|
1746
1747
|
case "vec4":
|
|
1747
|
-
|
|
1748
|
+
n.uniform4fv(u, a);
|
|
1748
1749
|
break;
|
|
1749
1750
|
case "mat2":
|
|
1750
|
-
|
|
1751
|
+
n.uniformMatrix2fv(u, !1, a);
|
|
1751
1752
|
break;
|
|
1752
1753
|
case "mat3":
|
|
1753
|
-
|
|
1754
|
+
n.uniformMatrix3fv(u, !1, a);
|
|
1754
1755
|
break;
|
|
1755
1756
|
case "mat4":
|
|
1756
|
-
|
|
1757
|
+
n.uniformMatrix4fv(u, !1, a);
|
|
1757
1758
|
break;
|
|
1758
1759
|
}
|
|
1759
1760
|
}
|
|
@@ -4757,7 +4758,7 @@ var U = class extends V {
|
|
|
4757
4758
|
this.width = e, this.height = t;
|
|
4758
4759
|
}
|
|
4759
4760
|
activate(e, t) {
|
|
4760
|
-
return this.valid ? (this.flush(e),
|
|
4761
|
+
return this.valid ? (this.flush(e), e.shader.uniforms.viewMatrix = this.canvasTransform.toArray(!0), e.shader.markGlobalUniformsDirty(), this.renderTarget.activate(e, t), this._tree?.setCurrentViewport(this), !0) : !1;
|
|
4761
4762
|
}
|
|
4762
4763
|
redraw(e, t) {
|
|
4763
4764
|
if (this.valid) {
|
|
@@ -5042,12 +5043,15 @@ var br = class {
|
|
|
5042
5043
|
let t = this.createCall(e);
|
|
5043
5044
|
return (this.currentCall?.calls ?? this.calls).push(t), t;
|
|
5044
5045
|
}
|
|
5046
|
+
reset() {
|
|
5047
|
+
this.calls = [], this.currentCall = void 0;
|
|
5048
|
+
}
|
|
5045
5049
|
render(e) {
|
|
5046
5050
|
this.calls.forEach(function t(n) {
|
|
5047
5051
|
n.fn(e, () => {
|
|
5048
5052
|
n.calls.forEach(t);
|
|
5049
5053
|
});
|
|
5050
|
-
}), this.
|
|
5054
|
+
}), this.reset();
|
|
5051
5055
|
}
|
|
5052
5056
|
}, xr, Sr = xr = class extends V {
|
|
5053
5057
|
currentTime = 0;
|
|
@@ -5195,7 +5199,7 @@ var wr = class extends Et {
|
|
|
5195
5199
|
this.debug && console.log(`[modern-canvas][${performance.now().toFixed(4)}ms]`, ...e);
|
|
5196
5200
|
}
|
|
5197
5201
|
_process(e = 0) {
|
|
5198
|
-
this.timeline.emit("process", e), this.emit("processing"), this.root.emit("process", e), this.emit("processed");
|
|
5202
|
+
this.renderStack.reset(), this.timeline.emit("process", e), this.emit("processing"), this.root.emit("process", e), this.emit("processed");
|
|
5199
5203
|
}
|
|
5200
5204
|
_render(e) {
|
|
5201
5205
|
this.emit("rendering"), _r(), this.renderStack.render(e), this._renderScreen(e), this.emit("rendered");
|
|
@@ -14,5 +14,16 @@ export declare class RenderStack {
|
|
|
14
14
|
calls: RenderCall[];
|
|
15
15
|
createCall(renderable: Renderable): RenderCall;
|
|
16
16
|
push(renderable: Renderable): RenderCall;
|
|
17
|
+
/**
|
|
18
|
+
* Discard any queued calls without rendering them. The stack is a per-process
|
|
19
|
+
* transient: it must start empty on every `_process` pass. Without this, a
|
|
20
|
+
* `_process` that is not followed by a `render` (e.g. the export pipeline's
|
|
21
|
+
* `waitUntilProcessed`, which processes then only awaits a tick) leaves its
|
|
22
|
+
* calls behind; the next `_process` appends to them, the scene ends up queued
|
|
23
|
+
* twice, and stateful effects (which flip `needsRender`/ping-pong viewports
|
|
24
|
+
* during the first pass) render the second pass wrong — e.g. a masked element
|
|
25
|
+
* drawn unmasked on export.
|
|
26
|
+
*/
|
|
27
|
+
reset(): void;
|
|
17
28
|
render(renderer: WebGLRenderer): void;
|
|
18
29
|
}
|