UNPKG

4.13 kBTypeScriptView Raw
1import { Texture } from '../textures/Texture';
2import { BaseRenderTexture } from './BaseRenderTexture';
3import type { MSAA_QUALITY } from '@pixi/constants';
4import type { Rectangle } from '@pixi/math';
5import type { Framebuffer } from '../framebuffer/Framebuffer';
6import type { IBaseTextureOptions } from '../textures/BaseTexture';
7/**
8 * A RenderTexture is a special texture that allows any PixiJS display object to be rendered to it.
9 *
10 * __Hint__: All DisplayObjects (i.e. Sprites) that render to a RenderTexture should be preloaded
11 * otherwise black rectangles will be drawn instead.
12 *
13 * __Hint-2__: The actual memory allocation will happen on first render.
14 * You shouldn't create renderTextures each frame just to delete them after, try to reuse them.
15 *
16 * A RenderTexture takes a snapshot of any Display Object given to its render method. For example:
17 * @example
18 * import { autoDetectRenderer, RenderTexture, Sprite } from 'pixi.js';
19 *
20 * const renderer = autoDetectRenderer();
21 * const renderTexture = RenderTexture.create({ width: 800, height: 600 });
22 * const sprite = Sprite.from('spinObj_01.png');
23 *
24 * sprite.position.x = 800 / 2;
25 * sprite.position.y = 600 / 2;
26 * sprite.anchor.x = 0.5;
27 * sprite.anchor.y = 0.5;
28 *
29 * renderer.render(sprite, { renderTexture });
30 *
31 * // Note that you should not create a new renderer, but reuse the same one as the rest of the application.
32 * // The Sprite in this case will be rendered using its local transform. To render this sprite at 0,0
33 * // you can clear the transform
34 *
35 * sprite.setTransform();
36 *
37 * const renderTexture = new RenderTexture.create({ width: 100, height: 100 });
38 *
39 * renderer.render(sprite, { renderTexture }); // Renders to center of RenderTexture
40 * @memberof PIXI
41 */
42export declare class RenderTexture extends Texture {
43 baseTexture: BaseRenderTexture;
44 /**
45 * Stores `sourceFrame` when this texture is inside current filter stack.
46 *
47 * You can read it inside filters.
48 * @readonly
49 */
50 filterFrame: Rectangle | null;
51 /**
52 * The key for pooled texture of FilterSystem.
53 * @see PIXI.RenderTexturePool
54 */
55 filterPoolKey: string | number | null;
56 /**
57 * @param baseRenderTexture - The base texture object that this texture uses.
58 * @param frame - The rectangle frame of the texture to show.
59 */
60 constructor(baseRenderTexture: BaseRenderTexture, frame?: Rectangle);
61 /**
62 * Shortcut to `this.baseTexture.framebuffer`, saves baseTexture cast.
63 * @readonly
64 */
65 get framebuffer(): Framebuffer;
66 /**
67 * Shortcut to `this.framebuffer.multisample`.
68 * @default PIXI.MSAA_QUALITY.NONE
69 */
70 get multisample(): MSAA_QUALITY;
71 set multisample(value: MSAA_QUALITY);
72 /**
73 * Resizes the RenderTexture.
74 * @param desiredWidth - The desired width to resize to.
75 * @param desiredHeight - The desired height to resize to.
76 * @param resizeBaseTexture - Should the baseTexture.width and height values be resized as well?
77 */
78 resize(desiredWidth: number, desiredHeight: number, resizeBaseTexture?: boolean): void;
79 /**
80 * Changes the resolution of baseTexture, but does not change framebuffer size.
81 * @param resolution - The new resolution to apply to RenderTexture
82 */
83 setResolution(resolution: number): void;
84 /**
85 * A short hand way of creating a render texture.
86 * @param options - Options
87 * @param {number} [options.width=100] - The width of the render texture
88 * @param {number} [options.height=100] - The height of the render texture
89 * @param {PIXI.SCALE_MODES} [options.scaleMode=PIXI.BaseTexture.defaultOptions.scaleMode] - See {@link PIXI.SCALE_MODES}
90 * for possible values
91 * @param {number} [options.resolution=PIXI.settings.RESOLUTION] - The resolution / device pixel ratio of the texture
92 * being generated
93 * @param {PIXI.MSAA_QUALITY} [options.multisample=PIXI.MSAA_QUALITY.NONE] - The number of samples of the frame buffer
94 * @returns The new render texture
95 */
96 static create(options?: IBaseTextureOptions): RenderTexture;
97}