1 | "use strict";
|
2 | var extensions = require("@pixi/extensions"), math = require("@pixi/math"), settings = require("@pixi/settings"), AbstractMaskSystem = require("./AbstractMaskSystem.js");
|
3 | const tempMatrix = new math.Matrix(), rectPool = [], _ScissorSystem = class _ScissorSystem2 extends AbstractMaskSystem.AbstractMaskSystem {
|
4 | |
5 |
|
6 |
|
7 | constructor(renderer) {
|
8 | super(renderer), this.glConst = settings.settings.ADAPTER.getWebGLRenderingContext().SCISSOR_TEST;
|
9 | }
|
10 | getStackLength() {
|
11 | const maskData = this.maskStack[this.maskStack.length - 1];
|
12 | return maskData ? maskData._scissorCounter : 0;
|
13 | }
|
14 | |
15 |
|
16 |
|
17 |
|
18 | calcScissorRect(maskData) {
|
19 | if (maskData._scissorRectLocal)
|
20 | return;
|
21 | const prevData = maskData._scissorRect, { maskObject } = maskData, { renderer } = this, renderTextureSystem = renderer.renderTexture, rect = maskObject.getBounds(!0, rectPool.pop() ?? new math.Rectangle());
|
22 | this.roundFrameToPixels(
|
23 | rect,
|
24 | renderTextureSystem.current ? renderTextureSystem.current.resolution : renderer.resolution,
|
25 | renderTextureSystem.sourceFrame,
|
26 | renderTextureSystem.destinationFrame,
|
27 | renderer.projection.transform
|
28 | ), prevData && rect.fit(prevData), maskData._scissorRectLocal = rect;
|
29 | }
|
30 | static isMatrixRotated(matrix) {
|
31 | if (!matrix)
|
32 | return !1;
|
33 | const { a, b, c, d } = matrix;
|
34 | return (Math.abs(b) > 1e-4 || Math.abs(c) > 1e-4) && (Math.abs(a) > 1e-4 || Math.abs(d) > 1e-4);
|
35 | }
|
36 | |
37 |
|
38 |
|
39 |
|
40 |
|
41 |
|
42 | testScissor(maskData) {
|
43 | const { maskObject } = maskData;
|
44 | if (!maskObject.isFastRect || !maskObject.isFastRect() || _ScissorSystem2.isMatrixRotated(maskObject.worldTransform) || _ScissorSystem2.isMatrixRotated(this.renderer.projection.transform))
|
45 | return !1;
|
46 | this.calcScissorRect(maskData);
|
47 | const rect = maskData._scissorRectLocal;
|
48 | return rect.width > 0 && rect.height > 0;
|
49 | }
|
50 | roundFrameToPixels(frame, resolution, bindingSourceFrame, bindingDestinationFrame, transform) {
|
51 | _ScissorSystem2.isMatrixRotated(transform) || (transform = transform ? tempMatrix.copyFrom(transform) : tempMatrix.identity(), transform.translate(-bindingSourceFrame.x, -bindingSourceFrame.y).scale(
|
52 | bindingDestinationFrame.width / bindingSourceFrame.width,
|
53 | bindingDestinationFrame.height / bindingSourceFrame.height
|
54 | ).translate(bindingDestinationFrame.x, bindingDestinationFrame.y), this.renderer.filter.transformAABB(transform, frame), frame.fit(bindingDestinationFrame), frame.x = Math.round(frame.x * resolution), frame.y = Math.round(frame.y * resolution), frame.width = Math.round(frame.width * resolution), frame.height = Math.round(frame.height * resolution));
|
55 | }
|
56 | |
57 |
|
58 |
|
59 |
|
60 |
|
61 | push(maskData) {
|
62 | maskData._scissorRectLocal || this.calcScissorRect(maskData);
|
63 | const { gl } = this.renderer;
|
64 | maskData._scissorRect || gl.enable(gl.SCISSOR_TEST), maskData._scissorCounter++, maskData._scissorRect = maskData._scissorRectLocal, this._useCurrent();
|
65 | }
|
66 | |
67 |
|
68 |
|
69 |
|
70 |
|
71 |
|
72 |
|
73 | pop(maskData) {
|
74 | const { gl } = this.renderer;
|
75 | maskData && rectPool.push(maskData._scissorRectLocal), this.getStackLength() > 0 ? this._useCurrent() : gl.disable(gl.SCISSOR_TEST);
|
76 | }
|
77 | |
78 |
|
79 |
|
80 |
|
81 | _useCurrent() {
|
82 | const rect = this.maskStack[this.maskStack.length - 1]._scissorRect;
|
83 | let y;
|
84 | this.renderer.renderTexture.current ? y = rect.y : y = this.renderer.height - rect.height - rect.y, this.renderer.gl.scissor(rect.x, y, rect.width, rect.height);
|
85 | }
|
86 | };
|
87 | _ScissorSystem.extension = {
|
88 | type: extensions.ExtensionType.RendererSystem,
|
89 | name: "scissor"
|
90 | };
|
91 | let ScissorSystem = _ScissorSystem;
|
92 | extensions.extensions.add(ScissorSystem);
|
93 | exports.ScissorSystem = ScissorSystem;
|
94 |
|