UNPKG

6.11 kBTypeScriptView Raw
1import type { ExtensionMetadata } from '@pixi/extensions';
2import type { ICanvas } from '@pixi/settings';
3import type { IRenderingContext } from '../IRenderer';
4import type { Renderer } from '../Renderer';
5import type { ISystem } from '../system/ISystem';
6import type { WebGLExtensions } from './WebGLExtensions';
7export interface ContextSystemOptions {
8 /**
9 * **Deprecated since 7.0.0, use `premultipliedAlpha` and `backgroundAlpha` instead.**
10 *
11 * Pass-through value for canvas' context attribute `alpha`. This option is for cases where the
12 * canvas needs to be opaque, possibly for performance reasons on some older devices.
13 * If you want to set transparency, please use `backgroundAlpha`.
14 *
15 * **WebGL Only:** When set to `'notMultiplied'`, the canvas' context attribute `alpha` will be
16 * set to `true` and `premultipliedAlpha` will be to `false`.
17 * @deprecated since 7.0.0
18 * @memberof PIXI.IRendererOptions
19 */
20 useContextAlpha?: boolean | 'notMultiplied';
21 /**
22 * **WebGL Only.** User-provided WebGL rendering context object.
23 * @memberof PIXI.IRendererOptions
24 */
25 context: IRenderingContext | null;
26 /**
27 * **WebGL Only.** Whether to enable anti-aliasing. This may affect performance.
28 * @memberof PIXI.IRendererOptions
29 */
30 antialias: boolean;
31 /**
32 * **WebGL Only.** A hint indicating what configuration of GPU is suitable for the WebGL context,
33 * can be `'default'`, `'high-performance'` or `'low-power'`.
34 * Setting to `'high-performance'` will prioritize rendering performance over power consumption,
35 * while setting to `'low-power'` will prioritize power saving over rendering performance.
36 * @memberof PIXI.IRendererOptions
37 */
38 powerPreference: WebGLPowerPreference;
39 /**
40 * **WebGL Only.** Whether the compositor will assume the drawing buffer contains colors with premultiplied alpha.
41 * @memberof PIXI.IRendererOptions
42 */
43 premultipliedAlpha: boolean;
44 /**
45 * **WebGL Only.** Whether to enable drawing buffer preservation. If enabled, the drawing buffer will preserve
46 * its value until cleared or overwritten. Enable this if you need to call `toDataUrl` on the WebGL context.
47 * @memberof PIXI.IRendererOptions
48 */
49 preserveDrawingBuffer: boolean;
50}
51export interface ISupportDict {
52 uint32Indices: boolean;
53}
54/**
55 * System plugin to the renderer to manage the context.
56 * @memberof PIXI
57 */
58export declare class ContextSystem implements ISystem<ContextSystemOptions> {
59 /** @ignore */
60 static defaultOptions: ContextSystemOptions;
61 /** @ignore */
62 static extension: ExtensionMetadata;
63 /**
64 * Either 1 or 2 to reflect the WebGL version being used.
65 * @readonly
66 */
67 webGLVersion: number;
68 /**
69 * Features supported by current context.
70 * @type {object}
71 * @readonly
72 * @property {boolean} uint32Indices - Support for 32-bit indices buffer.
73 */
74 readonly supports: ISupportDict;
75 preserveDrawingBuffer: boolean;
76 powerPreference: WebGLPowerPreference;
77 /**
78 * Pass-thru setting for the canvas' context `alpha` property. This is typically
79 * not something you need to fiddle with. If you want transparency, use `backgroundAlpha`.
80 * @member {boolean}
81 * @deprecated since 7.0.0
82 */
83 useContextAlpha: boolean | 'notMultiplied';
84 protected CONTEXT_UID: number;
85 protected gl: IRenderingContext;
86 /**
87 * Extensions available.
88 * @type {object}
89 * @readonly
90 * @property {WEBGL_draw_buffers} drawBuffers - WebGL v1 extension
91 * @property {WEBGL_depth_texture} depthTexture - WebGL v1 extension
92 * @property {OES_texture_float} floatTexture - WebGL v1 extension
93 * @property {WEBGL_lose_context} loseContext - WebGL v1 extension
94 * @property {OES_vertex_array_object} vertexArrayObject - WebGL v1 extension
95 * @property {EXT_texture_filter_anisotropic} anisotropicFiltering - WebGL v1 and v2 extension
96 */
97 extensions: WebGLExtensions;
98 private renderer;
99 /** @param renderer - The renderer this System works for. */
100 constructor(renderer: Renderer);
101 /**
102 * `true` if the context is lost
103 * @readonly
104 */
105 get isLost(): boolean;
106 /**
107 * Handles the context change event.
108 * @param {WebGLRenderingContext} gl - New WebGL context.
109 */
110 protected contextChange(gl: IRenderingContext): void;
111 init(options: ContextSystemOptions): void;
112 /**
113 * Initializes the context.
114 * @protected
115 * @param {WebGLRenderingContext} gl - WebGL context
116 */
117 initFromContext(gl: IRenderingContext): void;
118 /**
119 * Initialize from context options
120 * @protected
121 * @see https://developer.mozilla.org/en-US/docs/Web/API/HTMLCanvasElement/getContext
122 * @param {object} options - context attributes
123 */
124 initFromOptions(options: WebGLContextAttributes): void;
125 /**
126 * Helper class to create a WebGL Context
127 * @param canvas - the canvas element that we will get the context from
128 * @param options - An options object that gets passed in to the canvas element containing the
129 * context attributes
130 * @see https://developer.mozilla.org/en/docs/Web/API/HTMLCanvasElement/getContext
131 * @returns {WebGLRenderingContext} the WebGL context
132 */
133 createContext(canvas: ICanvas, options: WebGLContextAttributes): IRenderingContext;
134 /** Auto-populate the {@link PIXI.ContextSystem.extensions extensions}. */
135 protected getExtensions(): void;
136 /**
137 * Handles a lost webgl context
138 * @param {WebGLContextEvent} event - The context lost event.
139 */
140 protected handleContextLost(event: WebGLContextEvent): void;
141 /** Handles a restored webgl context. */
142 protected handleContextRestored(): void;
143 destroy(): void;
144 /** Handle the post-render runner event. */
145 protected postrender(): void;
146 /**
147 * Validate context.
148 * @param {WebGLRenderingContext} gl - Render context.
149 */
150 protected validateContext(gl: IRenderingContext): void;
151}