1 | import { RENDERER_TYPE } from "@pixi/constants";
|
2 | import { ExtensionType, extensions } from "@pixi/extensions";
|
3 | import { Matrix } from "@pixi/math";
|
4 | import { settings } from "@pixi/settings";
|
5 | import { deprecation, isWebGLSupported } from "@pixi/utils";
|
6 | import { UniformGroup } from "./shader/UniformGroup.mjs";
|
7 | import { SystemManager } from "./system/SystemManager.mjs";
|
8 | const _Renderer = class _Renderer2 extends SystemManager {
|
9 | |
10 |
|
11 |
|
12 | constructor(options) {
|
13 | super(), this.type = RENDERER_TYPE.WEBGL, options = Object.assign({}, settings.RENDER_OPTIONS, options), this.gl = null, this.CONTEXT_UID = 0, this.globalUniforms = new UniformGroup({
|
14 | projectionMatrix: new Matrix()
|
15 | }, !0);
|
16 | const systemConfig = {
|
17 | runners: [
|
18 | "init",
|
19 | "destroy",
|
20 | "contextChange",
|
21 | "resolutionChange",
|
22 | "reset",
|
23 | "update",
|
24 | "postrender",
|
25 | "prerender",
|
26 | "resize"
|
27 | ],
|
28 | systems: _Renderer2.__systems,
|
29 | priority: [
|
30 | "_view",
|
31 | "textureGenerator",
|
32 | "background",
|
33 | "_plugin",
|
34 | "startup",
|
35 |
|
36 | "context",
|
37 | "state",
|
38 | "texture",
|
39 | "buffer",
|
40 | "geometry",
|
41 | "framebuffer",
|
42 | "transformFeedback",
|
43 |
|
44 | "mask",
|
45 | "scissor",
|
46 | "stencil",
|
47 | "projection",
|
48 | "textureGC",
|
49 | "filter",
|
50 | "renderTexture",
|
51 | "batch",
|
52 | "objectRenderer",
|
53 | "_multisample"
|
54 | ]
|
55 | };
|
56 | this.setup(systemConfig), "useContextAlpha" in options && (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);
|
57 | }
|
58 | |
59 |
|
60 |
|
61 |
|
62 |
|
63 |
|
64 |
|
65 | static test(options) {
|
66 | return options?.forceCanvas ? !1 : isWebGLSupported();
|
67 | }
|
68 | |
69 |
|
70 |
|
71 |
|
72 |
|
73 |
|
74 |
|
75 |
|
76 |
|
77 | render(displayObject, options) {
|
78 | this.objectRenderer.render(displayObject, options);
|
79 | }
|
80 | |
81 |
|
82 |
|
83 |
|
84 |
|
85 | resize(desiredScreenWidth, desiredScreenHeight) {
|
86 | this._view.resizeView(desiredScreenWidth, desiredScreenHeight);
|
87 | }
|
88 | |
89 |
|
90 |
|
91 |
|
92 | reset() {
|
93 | return this.runners.reset.emit(), this;
|
94 | }
|
95 |
|
96 | clear() {
|
97 | this.renderTexture.bind(), this.renderTexture.clear();
|
98 | }
|
99 | |
100 |
|
101 |
|
102 |
|
103 |
|
104 | destroy(removeView = !1) {
|
105 | this.runners.destroy.items.reverse(), this.emitWithCustomOptions(this.runners.destroy, {
|
106 | _view: removeView
|
107 | }), super.destroy();
|
108 | }
|
109 |
|
110 | get plugins() {
|
111 | return this._plugin.plugins;
|
112 | }
|
113 |
|
114 | get multisample() {
|
115 | return this._multisample.multisample;
|
116 | }
|
117 | |
118 |
|
119 |
|
120 |
|
121 |
|
122 |
|
123 | get width() {
|
124 | return this._view.element.width;
|
125 | }
|
126 | |
127 |
|
128 |
|
129 |
|
130 | get height() {
|
131 | return this._view.element.height;
|
132 | }
|
133 |
|
134 | get resolution() {
|
135 | return this._view.resolution;
|
136 | }
|
137 | set resolution(value) {
|
138 | this._view.resolution = value, this.runners.resolutionChange.emit(value);
|
139 | }
|
140 |
|
141 | get autoDensity() {
|
142 | return this._view.autoDensity;
|
143 | }
|
144 |
|
145 | get view() {
|
146 | return this._view.element;
|
147 | }
|
148 | |
149 |
|
150 |
|
151 |
|
152 |
|
153 |
|
154 | get screen() {
|
155 | return this._view.screen;
|
156 | }
|
157 |
|
158 | get lastObjectRendered() {
|
159 | return this.objectRenderer.lastObjectRendered;
|
160 | }
|
161 |
|
162 | get renderingToScreen() {
|
163 | return this.objectRenderer.renderingToScreen;
|
164 | }
|
165 |
|
166 | get rendererLogId() {
|
167 | return `WebGL ${this.context.webGLVersion}`;
|
168 | }
|
169 | |
170 |
|
171 |
|
172 |
|
173 | get clearBeforeRender() {
|
174 | return deprecation("7.0.0", "renderer.clearBeforeRender has been deprecated, please use renderer.background.clearBeforeRender instead."), this.background.clearBeforeRender;
|
175 | }
|
176 | |
177 |
|
178 |
|
179 |
|
180 |
|
181 |
|
182 | get useContextAlpha() {
|
183 | return deprecation("7.0.0", "renderer.useContextAlpha has been deprecated, please use renderer.context.premultipliedAlpha instead."), this.context.useContextAlpha;
|
184 | }
|
185 | |
186 |
|
187 |
|
188 |
|
189 |
|
190 | get preserveDrawingBuffer() {
|
191 | return deprecation("7.0.0", "renderer.preserveDrawingBuffer has been deprecated, we cannot truly know this unless pixi created the context"), this.context.preserveDrawingBuffer;
|
192 | }
|
193 | |
194 |
|
195 |
|
196 |
|
197 |
|
198 | get backgroundColor() {
|
199 | return deprecation("7.0.0", "renderer.backgroundColor has been deprecated, use renderer.background.color instead."), this.background.color;
|
200 | }
|
201 | set backgroundColor(value) {
|
202 | deprecation("7.0.0", "renderer.backgroundColor has been deprecated, use renderer.background.color instead."), this.background.color = value;
|
203 | }
|
204 | |
205 |
|
206 |
|
207 |
|
208 |
|
209 | get backgroundAlpha() {
|
210 | return deprecation("7.0.0", "renderer.backgroundAlpha has been deprecated, use renderer.background.alpha instead."), this.background.alpha;
|
211 | }
|
212 | |
213 |
|
214 |
|
215 | set backgroundAlpha(value) {
|
216 | deprecation("7.0.0", "renderer.backgroundAlpha has been deprecated, use renderer.background.alpha instead."), this.background.alpha = value;
|
217 | }
|
218 | |
219 |
|
220 |
|
221 | get powerPreference() {
|
222 | return deprecation("7.0.0", "renderer.powerPreference has been deprecated, we can only know this if pixi creates the context"), this.context.powerPreference;
|
223 | }
|
224 | |
225 |
|
226 |
|
227 |
|
228 |
|
229 |
|
230 |
|
231 |
|
232 |
|
233 |
|
234 |
|
235 | generateTexture(displayObject, options) {
|
236 | return this.textureGenerator.generateTexture(displayObject, options);
|
237 | }
|
238 | };
|
239 | _Renderer.extension = {
|
240 | type: ExtensionType.Renderer,
|
241 | priority: 1
|
242 | }, |
243 |
|
244 |
|
245 |
|
246 |
|
247 |
|
248 | _Renderer.__plugins = {}, |
249 |
|
250 |
|
251 |
|
252 | _Renderer.__systems = {};
|
253 | let Renderer = _Renderer;
|
254 | extensions.handleByMap(ExtensionType.RendererPlugin, Renderer.__plugins);
|
255 | extensions.handleByMap(ExtensionType.RendererSystem, Renderer.__systems);
|
256 | extensions.add(Renderer);
|
257 | export {
|
258 | Renderer
|
259 | };
|
260 |
|