1 | "use strict";
|
2 | var extensions = require("@pixi/extensions"), settings = require("@pixi/settings"), AbstractMaskSystem = require("./AbstractMaskSystem.js");
|
3 | class StencilSystem extends AbstractMaskSystem.AbstractMaskSystem {
|
4 | |
5 |
|
6 |
|
7 | constructor(renderer) {
|
8 | super(renderer), this.glConst = settings.settings.ADAPTER.getWebGLRenderingContext().STENCIL_TEST;
|
9 | }
|
10 | getStackLength() {
|
11 | const maskData = this.maskStack[this.maskStack.length - 1];
|
12 | return maskData ? maskData._stencilCounter : 0;
|
13 | }
|
14 | |
15 |
|
16 |
|
17 |
|
18 | push(maskData) {
|
19 | const maskObject = maskData.maskObject, { gl } = this.renderer, prevMaskCount = maskData._stencilCounter;
|
20 | prevMaskCount === 0 && (this.renderer.framebuffer.forceStencil(), gl.clearStencil(0), gl.clear(gl.STENCIL_BUFFER_BIT), gl.enable(gl.STENCIL_TEST)), maskData._stencilCounter++;
|
21 | const colorMask = maskData._colorMask;
|
22 | colorMask !== 0 && (maskData._colorMask = 0, gl.colorMask(!1, !1, !1, !1)), gl.stencilFunc(gl.EQUAL, prevMaskCount, 4294967295), gl.stencilOp(gl.KEEP, gl.KEEP, gl.INCR), maskObject.renderable = !0, maskObject.render(this.renderer), this.renderer.batch.flush(), maskObject.renderable = !1, colorMask !== 0 && (maskData._colorMask = colorMask, gl.colorMask(
|
23 | (colorMask & 1) !== 0,
|
24 | (colorMask & 2) !== 0,
|
25 | (colorMask & 4) !== 0,
|
26 | (colorMask & 8) !== 0
|
27 | )), this._useCurrent();
|
28 | }
|
29 | |
30 |
|
31 |
|
32 |
|
33 | pop(maskObject) {
|
34 | const gl = this.renderer.gl;
|
35 | if (this.getStackLength() === 0)
|
36 | gl.disable(gl.STENCIL_TEST);
|
37 | else {
|
38 | const maskData = this.maskStack.length !== 0 ? this.maskStack[this.maskStack.length - 1] : null, colorMask = maskData ? maskData._colorMask : 15;
|
39 | colorMask !== 0 && (maskData._colorMask = 0, gl.colorMask(!1, !1, !1, !1)), gl.stencilOp(gl.KEEP, gl.KEEP, gl.DECR), maskObject.renderable = !0, maskObject.render(this.renderer), this.renderer.batch.flush(), maskObject.renderable = !1, colorMask !== 0 && (maskData._colorMask = colorMask, gl.colorMask(
|
40 | (colorMask & 1) !== 0,
|
41 | (colorMask & 2) !== 0,
|
42 | (colorMask & 4) !== 0,
|
43 | (colorMask & 8) !== 0
|
44 | )), this._useCurrent();
|
45 | }
|
46 | }
|
47 | |
48 |
|
49 |
|
50 |
|
51 | _useCurrent() {
|
52 | const gl = this.renderer.gl;
|
53 | gl.stencilFunc(gl.EQUAL, this.getStackLength(), 4294967295), gl.stencilOp(gl.KEEP, gl.KEEP, gl.KEEP);
|
54 | }
|
55 | }
|
56 | StencilSystem.extension = {
|
57 | type: extensions.ExtensionType.RendererSystem,
|
58 | name: "stencil"
|
59 | };
|
60 | extensions.extensions.add(StencilSystem);
|
61 | exports.StencilSystem = StencilSystem;
|
62 |
|