UNPKG

1.64 kBJavaScriptView Raw
1import { ExtensionType, extensions } from '@pixi/extensions';
2import { Matrix } from '@pixi/math';
3
4class ProjectionSystem {
5 constructor(renderer) {
6 this.renderer = renderer;
7 this.destinationFrame = null;
8 this.sourceFrame = null;
9 this.defaultFrame = null;
10 this.projectionMatrix = new Matrix();
11 this.transform = null;
12 }
13 update(destinationFrame, sourceFrame, resolution, root) {
14 this.destinationFrame = destinationFrame || this.destinationFrame || this.defaultFrame;
15 this.sourceFrame = sourceFrame || this.sourceFrame || destinationFrame;
16 this.calculateProjection(this.destinationFrame, this.sourceFrame, resolution, root);
17 if (this.transform) {
18 this.projectionMatrix.append(this.transform);
19 }
20 const renderer = this.renderer;
21 renderer.globalUniforms.uniforms.projectionMatrix = this.projectionMatrix;
22 renderer.globalUniforms.update();
23 if (renderer.shader.shader) {
24 renderer.shader.syncUniformGroup(renderer.shader.shader.uniforms.globals);
25 }
26 }
27 calculateProjection(_destinationFrame, sourceFrame, _resolution, root) {
28 const pm = this.projectionMatrix;
29 const sign = !root ? 1 : -1;
30 pm.identity();
31 pm.a = 1 / sourceFrame.width * 2;
32 pm.d = sign * (1 / sourceFrame.height * 2);
33 pm.tx = -1 - sourceFrame.x * pm.a;
34 pm.ty = -sign - sourceFrame.y * pm.d;
35 }
36 setTransform(_matrix) {
37 }
38 destroy() {
39 this.renderer = null;
40 }
41}
42ProjectionSystem.extension = {
43 type: ExtensionType.RendererSystem,
44 name: "projection"
45};
46extensions.add(ProjectionSystem);
47
48export { ProjectionSystem };
49//# sourceMappingURL=ProjectionSystem.mjs.map