UNPKG

10.1 kBJavaScriptView Raw
1"use strict";
2var constants = require("@pixi/constants"), extensions = require("@pixi/extensions"), math = require("@pixi/math"), settings = require("@pixi/settings"), utils = require("@pixi/utils"), UniformGroup = require("./shader/UniformGroup.js"), SystemManager = require("./system/SystemManager.js");
3const _Renderer = class _Renderer2 extends SystemManager.SystemManager {
4 /**
5 * @param {PIXI.IRendererOptions} [options] - See {@link PIXI.settings.RENDER_OPTIONS} for defaults.
6 */
7 constructor(options) {
8 super(), this.type = constants.RENDERER_TYPE.WEBGL, options = Object.assign({}, settings.settings.RENDER_OPTIONS, options), this.gl = null, this.CONTEXT_UID = 0, this.globalUniforms = new UniformGroup.UniformGroup({
9 projectionMatrix: new math.Matrix()
10 }, !0);
11 const systemConfig = {
12 runners: [
13 "init",
14 "destroy",
15 "contextChange",
16 "resolutionChange",
17 "reset",
18 "update",
19 "postrender",
20 "prerender",
21 "resize"
22 ],
23 systems: _Renderer2.__systems,
24 priority: [
25 "_view",
26 "textureGenerator",
27 "background",
28 "_plugin",
29 "startup",
30 // low level WebGL systems
31 "context",
32 "state",
33 "texture",
34 "buffer",
35 "geometry",
36 "framebuffer",
37 "transformFeedback",
38 // high level pixi specific rendering
39 "mask",
40 "scissor",
41 "stencil",
42 "projection",
43 "textureGC",
44 "filter",
45 "renderTexture",
46 "batch",
47 "objectRenderer",
48 "_multisample"
49 ]
50 };
51 this.setup(systemConfig), "useContextAlpha" in options && (utils.deprecation("7.0.0", "options.useContextAlpha is deprecated, use options.premultipliedAlpha and options.backgroundAlpha instead"), options.premultipliedAlpha = options.useContextAlpha && options.useContextAlpha !== "notMultiplied", options.backgroundAlpha = options.useContextAlpha === !1 ? 1 : options.backgroundAlpha), this._plugin.rendererPlugins = _Renderer2.__plugins, this.options = options, this.startup.run(this.options);
52 }
53 /**
54 * Create renderer if WebGL is available. Overrideable
55 * by the **@pixi/canvas-renderer** package to allow fallback.
56 * throws error if WebGL is not available.
57 * @param options
58 * @private
59 */
60 static test(options) {
61 return options?.forceCanvas ? !1 : utils.isWebGLSupported();
62 }
63 /**
64 * Renders the object to its WebGL view.
65 * @param displayObject - The object to be rendered.
66 * @param {object} [options] - Object to use for render options.
67 * @param {PIXI.RenderTexture} [options.renderTexture] - The render texture to render to.
68 * @param {boolean} [options.clear=true] - Should the canvas be cleared before the new render.
69 * @param {PIXI.Matrix} [options.transform] - A transform to apply to the render texture before rendering.
70 * @param {boolean} [options.skipUpdateTransform=false] - Should we skip the update transform pass?
71 */
72 render(displayObject, options) {
73 this.objectRenderer.render(displayObject, options);
74 }
75 /**
76 * Resizes the WebGL view to the specified width and height.
77 * @param desiredScreenWidth - The desired width of the screen.
78 * @param desiredScreenHeight - The desired height of the screen.
79 */
80 resize(desiredScreenWidth, desiredScreenHeight) {
81 this._view.resizeView(desiredScreenWidth, desiredScreenHeight);
82 }
83 /**
84 * Resets the WebGL state so you can render things however you fancy!
85 * @returns Returns itself.
86 */
87 reset() {
88 return this.runners.reset.emit(), this;
89 }
90 /** Clear the frame buffer. */
91 clear() {
92 this.renderTexture.bind(), this.renderTexture.clear();
93 }
94 /**
95 * Removes everything from the renderer (event listeners, spritebatch, etc...)
96 * @param [removeView=false] - Removes the Canvas element from the DOM.
97 * See: https://github.com/pixijs/pixijs/issues/2233
98 */
99 destroy(removeView = !1) {
100 this.runners.destroy.items.reverse(), this.emitWithCustomOptions(this.runners.destroy, {
101 _view: removeView
102 }), super.destroy();
103 }
104 /** Collection of plugins */
105 get plugins() {
106 return this._plugin.plugins;
107 }
108 /** The number of msaa samples of the canvas. */
109 get multisample() {
110 return this._multisample.multisample;
111 }
112 /**
113 * Same as view.width, actual number of pixels in the canvas by horizontal.
114 * @member {number}
115 * @readonly
116 * @default 800
117 */
118 get width() {
119 return this._view.element.width;
120 }
121 /**
122 * Same as view.height, actual number of pixels in the canvas by vertical.
123 * @default 600
124 */
125 get height() {
126 return this._view.element.height;
127 }
128 /** The resolution / device pixel ratio of the renderer. */
129 get resolution() {
130 return this._view.resolution;
131 }
132 set resolution(value) {
133 this._view.resolution = value, this.runners.resolutionChange.emit(value);
134 }
135 /** Whether CSS dimensions of canvas view should be resized to screen dimensions automatically. */
136 get autoDensity() {
137 return this._view.autoDensity;
138 }
139 /** The canvas element that everything is drawn to.*/
140 get view() {
141 return this._view.element;
142 }
143 /**
144 * Measurements of the screen. (0, 0, screenWidth, screenHeight).
145 *
146 * Its safe to use as filterArea or hitArea for the whole stage.
147 * @member {PIXI.Rectangle}
148 */
149 get screen() {
150 return this._view.screen;
151 }
152 /** the last object rendered by the renderer. Useful for other plugins like interaction managers */
153 get lastObjectRendered() {
154 return this.objectRenderer.lastObjectRendered;
155 }
156 /** Flag if we are rendering to the screen vs renderTexture */
157 get renderingToScreen() {
158 return this.objectRenderer.renderingToScreen;
159 }
160 /** When logging Pixi to the console, this is the name we will show */
161 get rendererLogId() {
162 return `WebGL ${this.context.webGLVersion}`;
163 }
164 /**
165 * This sets weather the screen is totally cleared between each frame withthe background color and alpha
166 * @deprecated since 7.0.0
167 */
168 get clearBeforeRender() {
169 return utils.deprecation("7.0.0", "renderer.clearBeforeRender has been deprecated, please use renderer.background.clearBeforeRender instead."), this.background.clearBeforeRender;
170 }
171 /**
172 * Pass-thru setting for the canvas' context `alpha` property. This is typically
173 * not something you need to fiddle with. If you want transparency, use `backgroundAlpha`.
174 * @deprecated since 7.0.0
175 * @member {boolean}
176 */
177 get useContextAlpha() {
178 return utils.deprecation("7.0.0", "renderer.useContextAlpha has been deprecated, please use renderer.context.premultipliedAlpha instead."), this.context.useContextAlpha;
179 }
180 /**
181 * readonly drawing buffer preservation
182 * we can only know this if Pixi created the context
183 * @deprecated since 7.0.0
184 */
185 get preserveDrawingBuffer() {
186 return utils.deprecation("7.0.0", "renderer.preserveDrawingBuffer has been deprecated, we cannot truly know this unless pixi created the context"), this.context.preserveDrawingBuffer;
187 }
188 /**
189 * The background color to fill if not transparent
190 * @member {number}
191 * @deprecated since 7.0.0
192 */
193 get backgroundColor() {
194 return utils.deprecation("7.0.0", "renderer.backgroundColor has been deprecated, use renderer.background.color instead."), this.background.color;
195 }
196 set backgroundColor(value) {
197 utils.deprecation("7.0.0", "renderer.backgroundColor has been deprecated, use renderer.background.color instead."), this.background.color = value;
198 }
199 /**
200 * The background color alpha. Setting this to 0 will make the canvas transparent.
201 * @member {number}
202 * @deprecated since 7.0.0
203 */
204 get backgroundAlpha() {
205 return utils.deprecation("7.0.0", "renderer.backgroundAlpha has been deprecated, use renderer.background.alpha instead."), this.background.alpha;
206 }
207 /**
208 * @deprecated since 7.0.0
209 */
210 set backgroundAlpha(value) {
211 utils.deprecation("7.0.0", "renderer.backgroundAlpha has been deprecated, use renderer.background.alpha instead."), this.background.alpha = value;
212 }
213 /**
214 * @deprecated since 7.0.0
215 */
216 get powerPreference() {
217 return utils.deprecation("7.0.0", "renderer.powerPreference has been deprecated, we can only know this if pixi creates the context"), this.context.powerPreference;
218 }
219 /**
220 * Useful function that returns a texture of the display object that can then be used to create sprites
221 * This can be quite useful if your displayObject is complicated and needs to be reused multiple times.
222 * @param displayObject - The displayObject the object will be generated from.
223 * @param {IGenerateTextureOptions} options - Generate texture options.
224 * @param {PIXI.Rectangle} options.region - The region of the displayObject, that shall be rendered,
225 * if no region is specified, defaults to the local bounds of the displayObject.
226 * @param {number} [options.resolution] - If not given, the renderer's resolution is used.
227 * @param {PIXI.MSAA_QUALITY} [options.multisample] - If not given, the renderer's multisample is used.
228 * @returns A texture of the graphics object.
229 */
230 generateTexture(displayObject, options) {
231 return this.textureGenerator.generateTexture(displayObject, options);
232 }
233};
234_Renderer.extension = {
235 type: extensions.ExtensionType.Renderer,
236 priority: 1
237}, /**
238* Collection of installed plugins. These are included by default in PIXI, but can be excluded
239* by creating a custom build. Consult the README for more information about creating custom
240* builds and excluding plugins.
241* @private
242*/
243_Renderer.__plugins = {}, /**
244* The collection of installed systems.
245* @private
246*/
247_Renderer.__systems = {};
248let Renderer = _Renderer;
249extensions.extensions.handleByMap(extensions.ExtensionType.RendererPlugin, Renderer.__plugins);
250extensions.extensions.handleByMap(extensions.ExtensionType.RendererSystem, Renderer.__systems);
251extensions.extensions.add(Renderer);
252exports.Renderer = Renderer;
253//# sourceMappingURL=Renderer.js.map