UNPKG

16.1 kBTypeScriptView Raw
1import { RENDERER_TYPE } from '@pixi/constants';
2import { UniformGroup } from './shader/UniformGroup';
3import { SystemManager } from './system/SystemManager';
4import type { ColorSource } from '@pixi/color';
5import type { MSAA_QUALITY } from '@pixi/constants';
6import type { ExtensionMetadata } from '@pixi/extensions';
7import type { Rectangle } from '@pixi/math';
8import type { ICanvas } from '@pixi/settings';
9import type { BackgroundSystem } from './background/BackgroundSystem';
10import type { BatchSystem } from './batch/BatchSystem';
11import type { ContextSystem } from './context/ContextSystem';
12import type { FilterSystem } from './filters/FilterSystem';
13import type { FramebufferSystem } from './framebuffer/FramebufferSystem';
14import type { MultisampleSystem } from './framebuffer/MultisampleSystem';
15import type { BufferSystem } from './geometry/BufferSystem';
16import type { GeometrySystem } from './geometry/GeometrySystem';
17import type { IRenderableObject, IRenderer, IRendererOptions, IRendererRenderOptions, IRenderingContext } from './IRenderer';
18import type { MaskSystem } from './mask/MaskSystem';
19import type { ScissorSystem } from './mask/ScissorSystem';
20import type { StencilSystem } from './mask/StencilSystem';
21import type { IRendererPlugins, PluginSystem } from './plugin/PluginSystem';
22import type { ProjectionSystem } from './projection/ProjectionSystem';
23import type { ObjectRendererSystem } from './render/ObjectRendererSystem';
24import type { GenerateTextureSystem, IGenerateTextureOptions } from './renderTexture/GenerateTextureSystem';
25import type { RenderTexture } from './renderTexture/RenderTexture';
26import type { RenderTextureSystem } from './renderTexture/RenderTextureSystem';
27import type { ShaderSystem } from './shader/ShaderSystem';
28import type { StartupSystem } from './startup/StartupSystem';
29import type { StateSystem } from './state/StateSystem';
30import type { TextureGCSystem } from './textures/TextureGCSystem';
31import type { TextureSystem } from './textures/TextureSystem';
32import type { TransformFeedbackSystem } from './transformFeedback/TransformFeedbackSystem';
33import type { ViewSystem } from './view/ViewSystem';
34export interface Renderer extends GlobalMixins.Renderer {
35}
36/**
37 * The Renderer draws the scene and all its content onto a WebGL enabled canvas.
38 *
39 * This renderer should be used for browsers that support WebGL.
40 *
41 * This renderer works by automatically managing WebGLBatches, so no need for Sprite Batches or Sprite Clouds.
42 * Don't forget to add the view to your DOM or you will not see anything!
43 *
44 * Renderer is composed of systems that manage specific tasks. The following systems are added by default
45 * whenever you create a renderer:
46 *
47 * | System | Description |
48 * | ------------------------------------ | ----------------------------------------------------------------------------- |
49 *
50 * | Generic Systems | Systems that manage functionality that all renderer types share |
51 * | ------------------------------------ | ----------------------------------------------------------------------------- |
52 * | {@link PIXI.ViewSystem} | This manages the main view of the renderer usually a Canvas |
53 * | {@link PIXI.PluginSystem} | This manages plugins for the renderer |
54 * | {@link PIXI.BackgroundSystem} | This manages the main views background color and alpha |
55 * | {@link PIXI.StartupSystem} | Boots up a renderer and initiatives all the systems |
56 * | {@link PIXI.EventSystem} | This manages UI events. |
57 *
58 * | WebGL Core Systems | Provide an optimised, easy to use API to work with WebGL |
59 * | ------------------------------------ | ----------------------------------------------------------------------------- |
60 * | {@link PIXI.ContextSystem} | This manages the WebGL context and extensions. |
61 * | {@link PIXI.FramebufferSystem} | This manages framebuffers, which are used for offscreen rendering. |
62 * | {@link PIXI.GeometrySystem} | This manages geometries & buffers, which are used to draw object meshes. |
63 * | {@link PIXI.ShaderSystem} | This manages shaders, programs that run on the GPU to calculate 'em pixels. |
64 * | {@link PIXI.StateSystem} | This manages the WebGL state variables like blend mode, depth testing, etc. |
65 * | {@link PIXI.TextureSystem} | This manages textures and their resources on the GPU. |
66 * | {@link PIXI.TextureGCSystem} | This will automatically remove textures from the GPU if they are not used. |
67 * | {@link PIXI.MultisampleSystem} | This manages the multisample const on the WEbGL Renderer |
68 *
69 * | PixiJS High-Level Systems | Set of specific systems designed to work with PixiJS objects |
70 * | ------------------------------------ | ----------------------------------------------------------------------------- |
71 * | {@link PIXI.GenerateTextureSystem} | This adds the ability to generate textures from any PIXI.DisplayObject |
72 * | {@link PIXI.ProjectionSystem} | This manages the `projectionMatrix`, used by shaders to get NDC coordinates. |
73 * | {@link PIXI.RenderTextureSystem} | This manages render-textures, which are an abstraction over framebuffers. |
74 * | {@link PIXI.MaskSystem} | This manages masking operations. |
75 * | {@link PIXI.ScissorSystem} | This handles scissor masking, and is used internally by {@link PIXI.MaskSystem} |
76 * | {@link PIXI.StencilSystem} | This handles stencil masking, and is used internally by {@link PIXI.MaskSystem} |
77 * | {@link PIXI.FilterSystem} | This manages the filtering pipeline for post-processing effects. |
78 * | {@link PIXI.BatchSystem} | This manages object renderers that defer rendering until a flush. |
79 * | {@link PIXI.Prepare} | This manages uploading assets to the GPU. |
80 * | {@link PIXI.Extract} | This extracts image data from display objects. |
81 *
82 * The breadth of the API surface provided by the renderer is contained within these systems.
83 * @memberof PIXI
84 */
85export declare class Renderer extends SystemManager<Renderer> implements IRenderer {
86 /** @ignore */
87 static extension: ExtensionMetadata;
88 /**
89 * The type of the renderer. will be PIXI.RENDERER_TYPE.CANVAS
90 * @member {number}
91 * @see PIXI.RENDERER_TYPE
92 */
93 readonly type = RENDERER_TYPE.WEBGL;
94 /**
95 * Options passed to the constructor.
96 * @type {PIXI.IRendererOptions}
97 */
98 readonly options: IRendererOptions;
99 /**
100 * WebGL context, set by {@link PIXI.ContextSystem this.context}.
101 * @readonly
102 * @member {WebGLRenderingContext}
103 */
104 gl: IRenderingContext;
105 /**
106 * Global uniforms
107 * Add any uniforms you want shared across your shaders.
108 * the must be added before the scene is rendered for the first time
109 * as we dynamically buildcode to handle all global var per shader
110 *
111 */
112 globalUniforms: UniformGroup;
113 /** Unique UID assigned to the renderer's WebGL context. */
114 CONTEXT_UID: number;
115 /**
116 * Mask system instance
117 * @readonly
118 */
119 readonly mask: MaskSystem;
120 /**
121 * Context system instance
122 * @readonly
123 */
124 readonly context: ContextSystem;
125 /**
126 * State system instance
127 * @readonly
128 */
129 readonly state: StateSystem;
130 /**
131 * Shader system instance
132 * @readonly
133 */
134 readonly shader: ShaderSystem;
135 /**
136 * Texture system instance
137 * @readonly
138 */
139 readonly texture: TextureSystem;
140 /**
141 * Buffer system instance
142 * @readonly
143 */
144 readonly buffer: BufferSystem;
145 /**
146 * TransformFeedback system instance
147 * @readonly
148 */
149 transformFeedback: TransformFeedbackSystem;
150 /**
151 * Geometry system instance
152 * @readonly
153 */
154 readonly geometry: GeometrySystem;
155 /**
156 * Framebuffer system instance
157 * @readonly
158 */
159 readonly framebuffer: FramebufferSystem;
160 /**
161 * Scissor system instance
162 * @readonly
163 */
164 readonly scissor: ScissorSystem;
165 /**
166 * Stencil system instance
167 * @readonly
168 */
169 readonly stencil: StencilSystem;
170 /**
171 * Projection system instance
172 * @readonly
173 */
174 readonly projection: ProjectionSystem;
175 /**
176 * Texture garbage collector system instance
177 * @readonly
178 */
179 readonly textureGC: TextureGCSystem;
180 /**
181 * Filter system instance
182 * @readonly
183 */
184 readonly filter: FilterSystem;
185 /**
186 * RenderTexture system instance
187 * @readonly
188 */
189 readonly renderTexture: RenderTextureSystem;
190 /**
191 * Batch system instance
192 * @readonly
193 */
194 readonly batch: BatchSystem;
195 /**
196 * plugin system instance
197 * @readonly
198 */
199 readonly _plugin: PluginSystem;
200 /**
201 * _multisample system instance
202 * @readonly
203 */
204 readonly _multisample: MultisampleSystem;
205 /**
206 * textureGenerator system instance
207 * @readonly
208 */
209 readonly textureGenerator: GenerateTextureSystem;
210 /**
211 * background system instance
212 * @readonly
213 */
214 readonly background: BackgroundSystem;
215 /**
216 * _view system instance
217 * @readonly
218 */
219 readonly _view: ViewSystem;
220 /**
221 * _render system instance
222 * @readonly
223 */
224 readonly objectRenderer: ObjectRendererSystem;
225 /**
226 * startup system instance
227 * @readonly
228 */
229 readonly startup: StartupSystem;
230 /**
231 * Create renderer if WebGL is available. Overrideable
232 * by the **@pixi/canvas-renderer** package to allow fallback.
233 * throws error if WebGL is not available.
234 * @param options
235 * @private
236 */
237 static test(options?: Partial<IRendererOptions>): boolean;
238 /**
239 * @param {PIXI.IRendererOptions} [options] - See {@link PIXI.settings.RENDER_OPTIONS} for defaults.
240 */
241 constructor(options?: Partial<IRendererOptions>);
242 /**
243 * Renders the object to its WebGL view.
244 * @param displayObject - The object to be rendered.
245 * @param {object} [options] - Object to use for render options.
246 * @param {PIXI.RenderTexture} [options.renderTexture] - The render texture to render to.
247 * @param {boolean} [options.clear=true] - Should the canvas be cleared before the new render.
248 * @param {PIXI.Matrix} [options.transform] - A transform to apply to the render texture before rendering.
249 * @param {boolean} [options.skipUpdateTransform=false] - Should we skip the update transform pass?
250 */
251 render(displayObject: IRenderableObject, options?: IRendererRenderOptions): void;
252 /**
253 * Resizes the WebGL view to the specified width and height.
254 * @param desiredScreenWidth - The desired width of the screen.
255 * @param desiredScreenHeight - The desired height of the screen.
256 */
257 resize(desiredScreenWidth: number, desiredScreenHeight: number): void;
258 /**
259 * Resets the WebGL state so you can render things however you fancy!
260 * @returns Returns itself.
261 */
262 reset(): this;
263 /** Clear the frame buffer. */
264 clear(): void;
265 /**
266 * Removes everything from the renderer (event listeners, spritebatch, etc...)
267 * @param [removeView=false] - Removes the Canvas element from the DOM.
268 * See: https://github.com/pixijs/pixijs/issues/2233
269 */
270 destroy(removeView?: boolean): void;
271 /** Collection of plugins */
272 get plugins(): IRendererPlugins;
273 /** The number of msaa samples of the canvas. */
274 get multisample(): MSAA_QUALITY;
275 /**
276 * Same as view.width, actual number of pixels in the canvas by horizontal.
277 * @member {number}
278 * @readonly
279 * @default 800
280 */
281 get width(): number;
282 /**
283 * Same as view.height, actual number of pixels in the canvas by vertical.
284 * @default 600
285 */
286 get height(): number;
287 /** The resolution / device pixel ratio of the renderer. */
288 get resolution(): number;
289 set resolution(value: number);
290 /** Whether CSS dimensions of canvas view should be resized to screen dimensions automatically. */
291 get autoDensity(): boolean;
292 /** The canvas element that everything is drawn to.*/
293 get view(): ICanvas;
294 /**
295 * Measurements of the screen. (0, 0, screenWidth, screenHeight).
296 *
297 * Its safe to use as filterArea or hitArea for the whole stage.
298 * @member {PIXI.Rectangle}
299 */
300 get screen(): Rectangle;
301 /** the last object rendered by the renderer. Useful for other plugins like interaction managers */
302 get lastObjectRendered(): IRenderableObject;
303 /** Flag if we are rendering to the screen vs renderTexture */
304 get renderingToScreen(): boolean;
305 /** When logging Pixi to the console, this is the name we will show */
306 get rendererLogId(): string;
307 /**
308 * This sets weather the screen is totally cleared between each frame withthe background color and alpha
309 * @deprecated since 7.0.0
310 */
311 get clearBeforeRender(): boolean;
312 /**
313 * Pass-thru setting for the canvas' context `alpha` property. This is typically
314 * not something you need to fiddle with. If you want transparency, use `backgroundAlpha`.
315 * @deprecated since 7.0.0
316 * @member {boolean}
317 */
318 get useContextAlpha(): boolean | 'notMultiplied';
319 /**
320 * readonly drawing buffer preservation
321 * we can only know this if Pixi created the context
322 * @deprecated since 7.0.0
323 */
324 get preserveDrawingBuffer(): boolean;
325 /**
326 * The background color to fill if not transparent
327 * @member {number}
328 * @deprecated since 7.0.0
329 */
330 get backgroundColor(): ColorSource;
331 set backgroundColor(value: ColorSource);
332 /**
333 * The background color alpha. Setting this to 0 will make the canvas transparent.
334 * @member {number}
335 * @deprecated since 7.0.0
336 */
337 get backgroundAlpha(): number;
338 /**
339 * @deprecated since 7.0.0
340 */
341 set backgroundAlpha(value: number);
342 /**
343 * @deprecated since 7.0.0
344 */
345 get powerPreference(): WebGLPowerPreference;
346 /**
347 * Useful function that returns a texture of the display object that can then be used to create sprites
348 * This can be quite useful if your displayObject is complicated and needs to be reused multiple times.
349 * @param displayObject - The displayObject the object will be generated from.
350 * @param {IGenerateTextureOptions} options - Generate texture options.
351 * @param {PIXI.Rectangle} options.region - The region of the displayObject, that shall be rendered,
352 * if no region is specified, defaults to the local bounds of the displayObject.
353 * @param {number} [options.resolution] - If not given, the renderer's resolution is used.
354 * @param {PIXI.MSAA_QUALITY} [options.multisample] - If not given, the renderer's multisample is used.
355 * @returns A texture of the graphics object.
356 */
357 generateTexture(displayObject: IRenderableObject, options?: IGenerateTextureOptions): RenderTexture;
358 /**
359 * Collection of installed plugins. These are included by default in PIXI, but can be excluded
360 * by creating a custom build. Consult the README for more information about creating custom
361 * builds and excluding plugins.
362 * @private
363 */
364 static readonly __plugins: IRendererPlugins;
365 /**
366 * The collection of installed systems.
367 * @private
368 */
369 static readonly __systems: Record<string, any>;
370}