UNPKG

7.13 kBTypeScriptView Raw
1import { CLEAR_MODES, MSAA_QUALITY } from '@pixi/constants';
2import { Matrix } from '@pixi/math';
3import { RenderTexturePool } from '../renderTexture/RenderTexturePool';
4import { UniformGroup } from '../shader/UniformGroup';
5import { Quad } from '../utils/Quad';
6import { QuadUv } from '../utils/QuadUv';
7import { FilterState } from './FilterState';
8import type { ExtensionMetadata } from '@pixi/extensions';
9import type { Renderer } from '../Renderer';
10import type { RenderTexture } from '../renderTexture/RenderTexture';
11import type { ISystem } from '../system/ISystem';
12import type { Filter } from './Filter';
13import type { IFilterTarget } from './IFilterTarget';
14import type { ISpriteMaskTarget } from './spriteMask/SpriteMaskFilter';
15/**
16 * System plugin to the renderer to manage filters.
17 *
18 * ## Pipeline
19 *
20 * The FilterSystem executes the filtering pipeline by rendering the display-object into a texture, applying its
21 * [filters]{@link PIXI.Filter} in series, and the last filter outputs into the final render-target.
22 *
23 * The filter-frame is the rectangle in world space being filtered, and those contents are mapped into
24 * `(0, 0, filterFrame.width, filterFrame.height)` into the filter render-texture. The filter-frame is also called
25 * the source-frame, as it is used to bind the filter render-textures. The last filter outputs to the `filterFrame`
26 * in the final render-target.
27 *
28 * ## Usage
29 *
30 * {@link PIXI.Container#renderAdvanced} is an example of how to use the filter system. It is a 3 step process:
31 *
32 * **push**: Use {@link PIXI.FilterSystem#push} to push the set of filters to be applied on a filter-target.
33 * **render**: Render the contents to be filtered using the renderer. The filter-system will only capture the contents
34 * inside the bounds of the filter-target. NOTE: Using {@link PIXI.Renderer#render} is
35 * illegal during an existing render cycle, and it may reset the filter system.
36 * **pop**: Use {@link PIXI.FilterSystem#pop} to pop & execute the filters you initially pushed. It will apply them
37 * serially and output to the bounds of the filter-target.
38 * @memberof PIXI
39 */
40export declare class FilterSystem implements ISystem {
41 /** @ignore */
42 static extension: ExtensionMetadata;
43 /**
44 * List of filters for the FilterSystem
45 * @member {object[]}
46 */
47 readonly defaultFilterStack: Array<FilterState>;
48 /** A pool for storing filter states, save us creating new ones each tick. */
49 statePool: Array<FilterState>;
50 /** Stores a bunch of POT textures used for filtering. */
51 texturePool: RenderTexturePool;
52 /** Whether to clear output renderTexture in AUTO/BLIT mode. See {@link PIXI.CLEAR_MODES}. */
53 forceClear: boolean;
54 /**
55 * Old padding behavior is to use the max amount instead of sum padding.
56 * Use this flag if you need the old behavior.
57 * @default false
58 */
59 useMaxPadding: boolean;
60 /** A very simple geometry used when drawing a filter effect to the screen. */
61 protected quad: Quad;
62 /** Quad UVs */
63 protected quadUv: QuadUv;
64 /**
65 * Active state
66 * @member {object}
67 */
68 protected activeState: FilterState;
69 /**
70 * This uniform group is attached to filter uniforms when used.
71 * @property {PIXI.Rectangle} outputFrame -
72 * @property {Float32Array} inputSize -
73 * @property {Float32Array} inputPixel -
74 * @property {Float32Array} inputClamp -
75 * @property {number} resolution -
76 * @property {Float32Array} filterArea -
77 * @property {Float32Array} filterClamp -
78 */
79 protected globalUniforms: UniformGroup;
80 /** Temporary rect for math. */
81 private tempRect;
82 renderer: Renderer;
83 /**
84 * @param renderer - The renderer this System works for.
85 */
86 constructor(renderer: Renderer);
87 init(): void;
88 /**
89 * Pushes a set of filters to be applied later to the system. This will redirect further rendering into an
90 * input render-texture for the rest of the filtering pipeline.
91 * @param {PIXI.DisplayObject} target - The target of the filter to render.
92 * @param filters - The filters to apply.
93 */
94 push(target: IFilterTarget, filters: Array<Filter>): void;
95 /** Pops off the filter and applies it. */
96 pop(): void;
97 /**
98 * Binds a renderTexture with corresponding `filterFrame`, clears it if mode corresponds.
99 * @param filterTexture - renderTexture to bind, should belong to filter pool or filter stack
100 * @param clearMode - clearMode, by default its CLEAR/YES. See {@link PIXI.CLEAR_MODES}
101 */
102 bindAndClear(filterTexture: RenderTexture, clearMode?: CLEAR_MODES): void;
103 /**
104 * Draws a filter using the default rendering process.
105 *
106 * This should be called only by {@link PIXI.Filter#apply}.
107 * @param filter - The filter to draw.
108 * @param input - The input render target.
109 * @param output - The target to output to.
110 * @param clearMode - Should the output be cleared before rendering to it
111 */
112 applyFilter(filter: Filter, input: RenderTexture, output: RenderTexture, clearMode?: CLEAR_MODES): void;
113 /**
114 * Multiply _input normalized coordinates_ to this matrix to get _sprite texture normalized coordinates_.
115 *
116 * Use `outputMatrix * vTextureCoord` in the shader.
117 * @param outputMatrix - The matrix to output to.
118 * @param {PIXI.Sprite} sprite - The sprite to map to.
119 * @returns The mapped matrix.
120 */
121 calculateSpriteMatrix(outputMatrix: Matrix, sprite: ISpriteMaskTarget): Matrix;
122 /** Destroys this Filter System. */
123 destroy(): void;
124 /**
125 * Gets a Power-of-Two render texture or fullScreen texture
126 * @param minWidth - The minimum width of the render texture in real pixels.
127 * @param minHeight - The minimum height of the render texture in real pixels.
128 * @param resolution - The resolution of the render texture.
129 * @param multisample - Number of samples of the render texture.
130 * @returns - The new render texture.
131 */
132 protected getOptimalFilterTexture(minWidth: number, minHeight: number, resolution?: number, multisample?: MSAA_QUALITY): RenderTexture;
133 /**
134 * Gets extra render texture to use inside current filter
135 * To be compliant with older filters, you can use params in any order
136 * @param input - renderTexture from which size and resolution will be copied
137 * @param resolution - override resolution of the renderTexture
138 * @param multisample - number of samples of the renderTexture
139 */
140 getFilterTexture(input?: RenderTexture, resolution?: number, multisample?: MSAA_QUALITY): RenderTexture;
141 /**
142 * Frees a render texture back into the pool.
143 * @param renderTexture - The renderTarget to free
144 */
145 returnFilterTexture(renderTexture: RenderTexture): void;
146 /** Empties the texture pool. */
147 emptyPool(): void;
148 /** Calls `texturePool.resize()`, affects fullScreen renderTextures. */
149 resize(): void;
150 /**
151 * @param matrix - first param
152 * @param rect - second param
153 */
154 private transformAABB;
155 private roundFrame;
156}