- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
- 47
- 48
- 49
- 50
- 51
- 52
- 53
- 54
- 55
- 56
- 57
- 58
- 59
- 60
- 61
- 62
- 63
- 64
- 65
- 66
- 67
- 68
- 69
- 70
- 71
- 72
- 73
- 74
- 75
- 76
- 77
- 78
- 79
- 80
- 81
- 82
- 83
- 84
import type { ISystem } from '../ISystem';
import type { MaskData } from './MaskData';
import type { Renderer } from '../Renderer';
/**
* System plugin to the renderer to manage specific types of masking operations.
* @memberof PIXI
*/
export class AbstractMaskSystem implements ISystem
{
/**
* The mask stack
* @member {PIXI.MaskData[]}
*/
protected maskStack: Array<MaskData>;
/**
* Constant for gl.enable
* @private
*/
protected glConst: number;
protected renderer: Renderer;
/**
* @param renderer - The renderer this System works for.
*/
constructor(renderer: Renderer)
{
this.renderer = renderer;
this.maskStack = [];
this.glConst = 0;
}
/** Gets count of masks of certain type. */
getStackLength(): number
{
return this.maskStack.length;
}
/**
* Changes the mask stack that is used by this System.
* @param {PIXI.MaskData[]} maskStack - The mask stack
*/
setMaskStack(maskStack: Array<MaskData>): void
{
const { gl } = this.renderer;
const curStackLen = this.getStackLength();
this.maskStack = maskStack;
const newStackLen = this.getStackLength();
if (newStackLen !== curStackLen)
{
if (newStackLen === 0)
{
gl.disable(this.glConst);
}
else
{
gl.enable(this.glConst);
this._useCurrent();
}
}
}
/**
* Setup renderer to use the current mask data.
* @private
*/
protected _useCurrent(): void
{
// OVERWRITE;
}
/** Destroys the mask stack. */
destroy(): void
{
this.renderer = null;
this.maskStack = null;
}
}