UNPKG

@pixi/core

Version:
50 lines (47 loc) 1.64 kB
import { ExtensionType, extensions } from '@pixi/extensions'; import { Matrix } from '@pixi/math'; class ProjectionSystem { constructor(renderer) { this.renderer = renderer; this.destinationFrame = null; this.sourceFrame = null; this.defaultFrame = null; this.projectionMatrix = new Matrix(); this.transform = null; } update(destinationFrame, sourceFrame, resolution, root) { this.destinationFrame = destinationFrame || this.destinationFrame || this.defaultFrame; this.sourceFrame = sourceFrame || this.sourceFrame || destinationFrame; this.calculateProjection(this.destinationFrame, this.sourceFrame, resolution, root); if (this.transform) { this.projectionMatrix.append(this.transform); } const renderer = this.renderer; renderer.globalUniforms.uniforms.projectionMatrix = this.projectionMatrix; renderer.globalUniforms.update(); if (renderer.shader.shader) { renderer.shader.syncUniformGroup(renderer.shader.shader.uniforms.globals); } } calculateProjection(_destinationFrame, sourceFrame, _resolution, root) { const pm = this.projectionMatrix; const sign = !root ? 1 : -1; pm.identity(); pm.a = 1 / sourceFrame.width * 2; pm.d = sign * (1 / sourceFrame.height * 2); pm.tx = -1 - sourceFrame.x * pm.a; pm.ty = -sign - sourceFrame.y * pm.d; } setTransform(_matrix) { } destroy() { this.renderer = null; } } ProjectionSystem.extension = { type: ExtensionType.RendererSystem, name: "projection" }; extensions.add(ProjectionSystem); export { ProjectionSystem }; //# sourceMappingURL=ProjectionSystem.mjs.map