1 | import { SpriteMaskFilter } from '../filters/spriteMask/SpriteMaskFilter';
|
2 | import { MaskData } from './MaskData';
|
3 | import type { ExtensionMetadata } from '@pixi/extensions';
|
4 | import type { Renderer } from '../Renderer';
|
5 | import type { ISystem } from '../system/ISystem';
|
6 | import type { IMaskTarget } from './MaskData';
|
7 | /**
|
8 | * System plugin to the renderer to manage masks.
|
9 | *
|
10 | * There are three built-in types of masking:
|
11 | * **Scissor Masking**: Scissor masking discards pixels that are outside of a rectangle called the scissor box. It is
|
12 | * the most performant as the scissor test is inexpensive. However, it can only be used when the mask is rectangular.
|
13 | * **Stencil Masking**: Stencil masking discards pixels that don't overlap with the pixels rendered into the stencil
|
14 | * buffer. It is the next fastest option as it does not require rendering into a separate framebuffer. However, it does
|
15 | * cause the mask to be rendered **twice** for each masking operation; hence, minimize the rendering cost of your masks.
|
16 | * **Sprite Mask Filtering**: Sprite mask filtering discards pixels based on the red channel of the sprite-mask's
|
17 | * texture. (Generally, the masking texture is grayscale). Using advanced techniques, you might be able to embed this
|
18 | * type of masking in a custom shader - and hence, bypassing the masking system fully for performance wins.
|
19 | *
|
20 | * The best type of masking is auto-detected when you `push` one. To use scissor masking, you must pass in a `Graphics`
|
21 | * object with just a rectangle drawn.
|
22 | *
|
23 | * ## Mask Stacks
|
24 | *
|
25 | * In the scene graph, masks can be applied recursively, i.e. a mask can be applied during a masking operation. The mask
|
26 | * stack stores the currently applied masks in order. Each {@link PIXI.BaseRenderTexture} holds its own mask stack, i.e.
|
27 | * when you switch render-textures, the old masks only applied when you switch back to rendering to the old render-target.
|
28 | * @memberof PIXI
|
29 | */
|
30 | export declare class MaskSystem implements ISystem {
|
31 | /** @ignore */
|
32 | static extension: ExtensionMetadata;
|
33 | /**
|
34 | * Flag to enable scissor masking.
|
35 | * @default true
|
36 | */
|
37 | enableScissor: boolean;
|
38 | /** Pool of used sprite mask filters. */
|
39 | protected readonly alphaMaskPool: Array<SpriteMaskFilter[]>;
|
40 | /**
|
41 | * Current index of alpha mask pool.
|
42 | * @default 0
|
43 | * @readonly
|
44 | */
|
45 | protected alphaMaskIndex: number;
|
46 | /** Pool of mask data. */
|
47 | private readonly maskDataPool;
|
48 | private maskStack;
|
49 | private renderer;
|
50 | /**
|
51 | * @param renderer - The renderer this System works for.
|
52 | */
|
53 | constructor(renderer: Renderer);
|
54 | /**
|
55 | * Changes the mask stack that is used by this System.
|
56 | * @param maskStack - The mask stack
|
57 | */
|
58 | setMaskStack(maskStack: Array<MaskData>): void;
|
59 | /**
|
60 | * Enables the mask and appends it to the current mask stack.
|
61 | *
|
62 | * NOTE: The batch renderer should be flushed beforehand to prevent pending renders from being masked.
|
63 | * @param {PIXI.DisplayObject} target - Display Object to push the mask to
|
64 | * {PIXI.MaskData|PIXI.Sprite|PIXI.Graphics|PIXI.DisplayObject} maskDataOrTarget - The masking data.
|
65 | */
|
66 | push(target: IMaskTarget, maskDataOrTarget: MaskData | IMaskTarget): void;
|
67 | /**
|
68 | * Removes the last mask from the mask stack and doesn't return it.
|
69 | *
|
70 | * NOTE: The batch renderer should be flushed beforehand to render the masked contents before the mask is removed.
|
71 | * @param {PIXI.IMaskTarget} target - Display Object to pop the mask from
|
72 | */
|
73 | pop(target: IMaskTarget): void;
|
74 | /**
|
75 | * Sets type of MaskData based on its maskObject.
|
76 | * @param maskData
|
77 | */
|
78 | detect(maskData: MaskData): void;
|
79 | /**
|
80 | * Applies the Mask and adds it to the current filter stack.
|
81 | * @param maskData - Sprite to be used as the mask.
|
82 | */
|
83 | pushSpriteMask(maskData: MaskData): void;
|
84 | /**
|
85 | * Removes the last filter from the filter stack and doesn't return it.
|
86 | * @param maskData - Sprite to be used as the mask.
|
87 | */
|
88 | popSpriteMask(maskData: MaskData): void;
|
89 | /**
|
90 | * Pushes the color mask.
|
91 | * @param maskData - The mask data
|
92 | */
|
93 | pushColorMask(maskData: MaskData): void;
|
94 | /**
|
95 | * Pops the color mask.
|
96 | * @param maskData - The mask data
|
97 | */
|
98 | popColorMask(maskData: MaskData): void;
|
99 | destroy(): void;
|
100 | }
|