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