@eva/plugin-renderer 1.2.8-fix.1 → 1.2.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,1052 @@
1
+ function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
2
+
3
+ import { __values, __extends, __decorate, __spread, __assign } from 'tslib';
4
+ import { OBSERVER_TYPE, decorators, resourceLoader, resource, RESOURCE_TYPE_STRATEGY, LOAD_SCENE_MODE, System } from '@eva/eva.js/dist/miniprogram';
5
+ import { Container, Application } from '@eva/renderer-adapter/dist/miniprogram';
6
+ import isEqual from 'lodash-es/isEqual';
7
+ import EventEmitter from 'eventemitter3';
8
+ import { glCore, Texture, BaseTexture, utils, ticker } from '@eva/miniprogram-pixi';
9
+
10
+ var RendererManager = function () {
11
+ function RendererManager(_a) {
12
+ var game = _a.game,
13
+ rendererSystem = _a.rendererSystem;
14
+ this.renderers = [];
15
+ this.game = game;
16
+ this.rendererSystem = rendererSystem;
17
+ }
18
+
19
+ RendererManager.prototype.register = function () {
20
+ var e_1, _a;
21
+
22
+ var renderers = [];
23
+
24
+ for (var _i = 0; _i < arguments.length; _i++) {
25
+ renderers[_i] = arguments[_i];
26
+ }
27
+
28
+ try {
29
+ for (var renderers_1 = __values(renderers), renderers_1_1 = renderers_1.next(); !renderers_1_1.done; renderers_1_1 = renderers_1.next()) {
30
+ var renderer = renderers_1_1.value;
31
+ renderer.game = this.game;
32
+ renderer.rendererManager = this.rendererSystem.rendererManager;
33
+ renderer.containerManager = this.rendererSystem.containerManager;
34
+ this.renderers.push(renderer);
35
+ }
36
+ } catch (e_1_1) {
37
+ e_1 = {
38
+ error: e_1_1
39
+ };
40
+ } finally {
41
+ try {
42
+ if (renderers_1_1 && !renderers_1_1.done && (_a = renderers_1.return)) _a.call(renderers_1);
43
+ } finally {
44
+ if (e_1) throw e_1.error;
45
+ }
46
+ }
47
+ };
48
+
49
+ RendererManager.prototype.componentChanged = function (changes) {
50
+ var e_2, _a;
51
+
52
+ var _loop_1 = function _loop_1(changed) {
53
+ var e_3, _a;
54
+
55
+ try {
56
+ for (var _b = (e_3 = void 0, __values(this_1.renderers)), _c = _b.next(); !_c.done; _c = _b.next()) {
57
+ var renderer = _c.value;
58
+ var props = renderer.observerInfo[changed.componentName];
59
+
60
+ if (props) {
61
+ if ([OBSERVER_TYPE.ADD, OBSERVER_TYPE.REMOVE].indexOf(changed.type) > -1) {
62
+ try {
63
+ renderer.componentChanged && renderer.componentChanged(changed);
64
+ } catch (e) {
65
+ console.error("gameObject: " + changed.gameObject.name + ", " + changed.componentName + " is error.", changed, e);
66
+ }
67
+
68
+ continue;
69
+ }
70
+
71
+ var index = props.findIndex(function (prop) {
72
+ return isEqual(prop, changed.prop);
73
+ });
74
+
75
+ if (index > -1) {
76
+ try {
77
+ renderer.componentChanged && renderer.componentChanged(changed);
78
+ } catch (e) {
79
+ console.error("gameObject: " + (changed.gameObject && changed.gameObject.name) + ", " + changed.componentName + " is componentChanged error.", changed, e);
80
+ }
81
+ }
82
+ }
83
+ }
84
+ } catch (e_3_1) {
85
+ e_3 = {
86
+ error: e_3_1
87
+ };
88
+ } finally {
89
+ try {
90
+ if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
91
+ } finally {
92
+ if (e_3) throw e_3.error;
93
+ }
94
+ }
95
+ };
96
+
97
+ var this_1 = this;
98
+
99
+ try {
100
+ for (var changes_1 = __values(changes), changes_1_1 = changes_1.next(); !changes_1_1.done; changes_1_1 = changes_1.next()) {
101
+ var changed = changes_1_1.value;
102
+
103
+ _loop_1(changed);
104
+ }
105
+ } catch (e_2_1) {
106
+ e_2 = {
107
+ error: e_2_1
108
+ };
109
+ } finally {
110
+ try {
111
+ if (changes_1_1 && !changes_1_1.done && (_a = changes_1.return)) _a.call(changes_1);
112
+ } finally {
113
+ if (e_2) throw e_2.error;
114
+ }
115
+ }
116
+ };
117
+
118
+ RendererManager.prototype.update = function (gameObject) {
119
+ var e_4, _a, e_5, _b;
120
+
121
+ try {
122
+ for (var _c = __values(gameObject.components), _d = _c.next(); !_d.done; _d = _c.next()) {
123
+ var component = _d.value;
124
+
125
+ try {
126
+ for (var _e = (e_5 = void 0, __values(this.renderers)), _f = _e.next(); !_f.done; _f = _e.next()) {
127
+ var renderer = _f.value;
128
+ var cache = [];
129
+ var props = renderer.observerInfo[component.name];
130
+
131
+ if (props && cache.indexOf(gameObject) === -1) {
132
+ cache.push(gameObject);
133
+
134
+ try {
135
+ renderer.rendererUpdate && renderer.rendererUpdate(gameObject);
136
+ } catch (e) {
137
+ console.info("gameObject: " + gameObject.name + ", " + component.name + " is update error", e);
138
+ }
139
+ }
140
+ }
141
+ } catch (e_5_1) {
142
+ e_5 = {
143
+ error: e_5_1
144
+ };
145
+ } finally {
146
+ try {
147
+ if (_f && !_f.done && (_b = _e.return)) _b.call(_e);
148
+ } finally {
149
+ if (e_5) throw e_5.error;
150
+ }
151
+ }
152
+ }
153
+ } catch (e_4_1) {
154
+ e_4 = {
155
+ error: e_4_1
156
+ };
157
+ } finally {
158
+ try {
159
+ if (_d && !_d.done && (_a = _c.return)) _a.call(_c);
160
+ } finally {
161
+ if (e_4) throw e_4.error;
162
+ }
163
+ }
164
+ };
165
+
166
+ return RendererManager;
167
+ }();
168
+
169
+ var RendererManager$1 = RendererManager;
170
+
171
+ var ContainerManager = function () {
172
+ function ContainerManager() {
173
+ this.containerMap = {};
174
+ }
175
+
176
+ ContainerManager.prototype.addContainer = function (_a) {
177
+ var name = _a.name,
178
+ container = _a.container;
179
+ this.containerMap[name] = container;
180
+ };
181
+
182
+ ContainerManager.prototype.getContainer = function (name) {
183
+ return this.containerMap[name];
184
+ };
185
+
186
+ ContainerManager.prototype.removeContainer = function (name) {
187
+ var _a;
188
+
189
+ (_a = this.containerMap[name]) === null || _a === void 0 ? void 0 : _a.destroy({
190
+ children: true
191
+ });
192
+ delete this.containerMap[name];
193
+ };
194
+
195
+ ContainerManager.prototype.updateTransform = function (_a) {
196
+ var name = _a.name,
197
+ transform = _a.transform;
198
+ var container = this.containerMap[name];
199
+ if (!container || !transform) return;
200
+ var anchor = transform.anchor,
201
+ origin = transform.origin,
202
+ position = transform.position,
203
+ rotation = transform.rotation,
204
+ scale = transform.scale,
205
+ size = transform.size,
206
+ skew = transform.skew;
207
+ container.rotation = rotation;
208
+ container.scale = scale;
209
+ container.pivot.x = size.width * origin.x;
210
+ container.pivot.y = size.height * origin.y;
211
+ container.skew = skew;
212
+ var x = position.x;
213
+ var y = position.y;
214
+
215
+ if (transform.parent) {
216
+ var parent_1 = transform.parent;
217
+ x = x + parent_1.size.width * anchor.x;
218
+ y = y + parent_1.size.height * anchor.y;
219
+ }
220
+
221
+ container.position = {
222
+ x: x,
223
+ y: y
224
+ };
225
+ };
226
+
227
+ return ContainerManager;
228
+ }();
229
+
230
+ var ContainerManager$1 = ContainerManager;
231
+
232
+ var Transform = function (_super) {
233
+ __extends(Transform, _super);
234
+
235
+ function Transform(_a) {
236
+ var system = _a.system,
237
+ containerManager = _a.containerManager;
238
+
239
+ var _this = _super.call(this) || this;
240
+
241
+ _this.name = 'Transform';
242
+ _this.waitRemoveIds = [];
243
+ _this.waitChangeScenes = [];
244
+ _this.containerManager = containerManager;
245
+
246
+ _this.init(system);
247
+
248
+ return _this;
249
+ }
250
+
251
+ Transform.prototype.init = function (system) {
252
+ var _this = this;
253
+
254
+ this.system = system;
255
+ this.on('changeScene', function (_a) {
256
+ var scene = _a.scene,
257
+ mode = _a.mode,
258
+ application = _a.application;
259
+
260
+ _this.waitChangeScenes.push({
261
+ scene: scene,
262
+ mode: mode,
263
+ application: application
264
+ });
265
+ });
266
+ };
267
+
268
+ Transform.prototype.update = function () {
269
+ var e_1, _a, e_2, _b;
270
+
271
+ try {
272
+ for (var _c = __values(this.waitRemoveIds), _d = _c.next(); !_d.done; _d = _c.next()) {
273
+ var id = _d.value;
274
+ this.containerManager.removeContainer(id);
275
+ }
276
+ } catch (e_1_1) {
277
+ e_1 = {
278
+ error: e_1_1
279
+ };
280
+ } finally {
281
+ try {
282
+ if (_d && !_d.done && (_a = _c.return)) _a.call(_c);
283
+ } finally {
284
+ if (e_1) throw e_1.error;
285
+ }
286
+ }
287
+
288
+ this.waitRemoveIds = [];
289
+
290
+ try {
291
+ for (var _e = __values(this.waitChangeScenes), _f = _e.next(); !_f.done; _f = _e.next()) {
292
+ var sceneInfo = _f.value;
293
+ var container = this.containerManager.getContainer(sceneInfo.scene.id);
294
+
295
+ if (container) {
296
+ sceneInfo.application.stage.removeChildren();
297
+ sceneInfo.application.stage.addChild(container);
298
+ }
299
+ }
300
+ } catch (e_2_1) {
301
+ e_2 = {
302
+ error: e_2_1
303
+ };
304
+ } finally {
305
+ try {
306
+ if (_f && !_f.done && (_b = _e.return)) _b.call(_e);
307
+ } finally {
308
+ if (e_2) throw e_2.error;
309
+ }
310
+ }
311
+
312
+ this.waitChangeScenes = [];
313
+ };
314
+
315
+ Transform.prototype.componentChanged = function (changed) {
316
+ if (changed.type === OBSERVER_TYPE.ADD) {
317
+ this.addContainer(changed);
318
+ } else if (changed.type === OBSERVER_TYPE.CHANGE) {
319
+ this.change(changed);
320
+ } else if (changed.type === OBSERVER_TYPE.REMOVE) {
321
+ this.waitRemoveIds.push(changed.gameObject.id);
322
+ }
323
+ };
324
+
325
+ Transform.prototype.addContainer = function (changed) {
326
+ var container = new Container();
327
+ container.name = changed.gameObject.name;
328
+ this.containerManager.addContainer({
329
+ name: changed.gameObject.id,
330
+ container: container
331
+ });
332
+ var transform = changed.component;
333
+ transform.worldTransform = container.transform.worldTransform;
334
+ };
335
+
336
+ Transform.prototype.change = function (changed) {
337
+ var transform = changed.component;
338
+
339
+ if (transform.parent) {
340
+ var parentContainer = this.containerManager.getContainer(transform.parent.gameObject.id);
341
+ parentContainer.addChild(this.containerManager.getContainer(changed.gameObject.id));
342
+ var render = changed.gameObject.transform.parent && changed.gameObject.transform.parent.gameObject.getComponent('Render');
343
+
344
+ if (render) {
345
+ render.sortDirty = true;
346
+ }
347
+ } else {
348
+ var container = this.containerManager.getContainer(changed.gameObject.id);
349
+ delete transform.worldTransform;
350
+ container.parent && container.parent.removeChild(container);
351
+ }
352
+ };
353
+
354
+ Transform.prototype.destroy = function () {
355
+ this.removeAllListeners();
356
+ this.waitRemoveIds = null;
357
+ this.waitChangeScenes = null;
358
+ this.system = null;
359
+ this.containerManager = null;
360
+ };
361
+
362
+ Transform = __decorate([decorators.componentObserver({
363
+ Transform: ['_parent']
364
+ })], Transform);
365
+ return Transform;
366
+ }(EventEmitter);
367
+
368
+ var Transform$1 = Transform;
369
+ var result = undefined;
370
+
371
+ function getSuportCompressedTextureFormats(gl) {
372
+ if (result) return result;
373
+
374
+ if (!gl) {
375
+ console.warn('WebGL not available for compressed textures. Silently failing.');
376
+ return {
377
+ s3tc: false,
378
+ etc: false,
379
+ etc1: false,
380
+ pvrtc: false,
381
+ atc: false,
382
+ astc: false
383
+ };
384
+ }
385
+
386
+ result = {
387
+ s3tc: !!gl.getExtension('WEBGL_compressed_texture_s3tc'),
388
+ etc: !!gl.getExtension('WEBGL_compressed_texture_etc'),
389
+ etc1: !!gl.getExtension('WEBGL_compressed_texture_etc1'),
390
+ pvrtc: !!gl.getExtension('WEBGL_compressed_texture_pvrtc') || !!gl.getExtension('WEBKIT_WEBGL_compressed_texture_pvrtc'),
391
+ atc: !!gl.getExtension('WEBGL_compressed_texture_atc'),
392
+ astc: !!gl.getExtension('WEBGL_compressed_texture_astc')
393
+ };
394
+
395
+ try {
396
+ console.log('Eva.js Supported Compressed Texture Format List: ' + Object.keys(result).filter(function (type) {
397
+ return result[type];
398
+ }).join(', '));
399
+ } catch (e) {}
400
+
401
+ return result;
402
+ }
403
+
404
+ var XLS = resourceLoader.XhrLoadStrategy;
405
+ var XhrLoadStrategy = XLS;
406
+
407
+ var _a, _b;
408
+
409
+ var INTERNAL_FORMATS;
410
+
411
+ (function (INTERNAL_FORMATS) {
412
+ INTERNAL_FORMATS[INTERNAL_FORMATS["COMPRESSED_RGB_S3TC_DXT1_EXT"] = 33776] = "COMPRESSED_RGB_S3TC_DXT1_EXT";
413
+ INTERNAL_FORMATS[INTERNAL_FORMATS["COMPRESSED_RGBA_S3TC_DXT1_EXT"] = 33777] = "COMPRESSED_RGBA_S3TC_DXT1_EXT";
414
+ INTERNAL_FORMATS[INTERNAL_FORMATS["COMPRESSED_RGBA_S3TC_DXT3_EXT"] = 33778] = "COMPRESSED_RGBA_S3TC_DXT3_EXT";
415
+ INTERNAL_FORMATS[INTERNAL_FORMATS["COMPRESSED_RGBA_S3TC_DXT5_EXT"] = 33779] = "COMPRESSED_RGBA_S3TC_DXT5_EXT";
416
+ INTERNAL_FORMATS[INTERNAL_FORMATS["COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT"] = 35917] = "COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT";
417
+ INTERNAL_FORMATS[INTERNAL_FORMATS["COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT"] = 35918] = "COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT";
418
+ INTERNAL_FORMATS[INTERNAL_FORMATS["COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT"] = 35919] = "COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT";
419
+ INTERNAL_FORMATS[INTERNAL_FORMATS["COMPRESSED_SRGB_S3TC_DXT1_EXT"] = 35916] = "COMPRESSED_SRGB_S3TC_DXT1_EXT";
420
+ INTERNAL_FORMATS[INTERNAL_FORMATS["COMPRESSED_R11_EAC"] = 37488] = "COMPRESSED_R11_EAC";
421
+ INTERNAL_FORMATS[INTERNAL_FORMATS["COMPRESSED_SIGNED_R11_EAC"] = 37489] = "COMPRESSED_SIGNED_R11_EAC";
422
+ INTERNAL_FORMATS[INTERNAL_FORMATS["COMPRESSED_RG11_EAC"] = 37490] = "COMPRESSED_RG11_EAC";
423
+ INTERNAL_FORMATS[INTERNAL_FORMATS["COMPRESSED_SIGNED_RG11_EAC"] = 37491] = "COMPRESSED_SIGNED_RG11_EAC";
424
+ INTERNAL_FORMATS[INTERNAL_FORMATS["COMPRESSED_RGB8_ETC2"] = 37492] = "COMPRESSED_RGB8_ETC2";
425
+ INTERNAL_FORMATS[INTERNAL_FORMATS["COMPRESSED_RGBA8_ETC2_EAC"] = 37496] = "COMPRESSED_RGBA8_ETC2_EAC";
426
+ INTERNAL_FORMATS[INTERNAL_FORMATS["COMPRESSED_SRGB8_ETC2"] = 37493] = "COMPRESSED_SRGB8_ETC2";
427
+ INTERNAL_FORMATS[INTERNAL_FORMATS["COMPRESSED_SRGB8_ALPHA8_ETC2_EAC"] = 37497] = "COMPRESSED_SRGB8_ALPHA8_ETC2_EAC";
428
+ INTERNAL_FORMATS[INTERNAL_FORMATS["COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2"] = 37494] = "COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2";
429
+ INTERNAL_FORMATS[INTERNAL_FORMATS["COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2"] = 37495] = "COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2";
430
+ INTERNAL_FORMATS[INTERNAL_FORMATS["COMPRESSED_RGB_PVRTC_4BPPV1_IMG"] = 35840] = "COMPRESSED_RGB_PVRTC_4BPPV1_IMG";
431
+ INTERNAL_FORMATS[INTERNAL_FORMATS["COMPRESSED_RGBA_PVRTC_4BPPV1_IMG"] = 35842] = "COMPRESSED_RGBA_PVRTC_4BPPV1_IMG";
432
+ INTERNAL_FORMATS[INTERNAL_FORMATS["COMPRESSED_RGB_PVRTC_2BPPV1_IMG"] = 35841] = "COMPRESSED_RGB_PVRTC_2BPPV1_IMG";
433
+ INTERNAL_FORMATS[INTERNAL_FORMATS["COMPRESSED_RGBA_PVRTC_2BPPV1_IMG"] = 35843] = "COMPRESSED_RGBA_PVRTC_2BPPV1_IMG";
434
+ INTERNAL_FORMATS[INTERNAL_FORMATS["COMPRESSED_RGB_ETC1_WEBGL"] = 36196] = "COMPRESSED_RGB_ETC1_WEBGL";
435
+ INTERNAL_FORMATS[INTERNAL_FORMATS["COMPRESSED_RGB_ATC_WEBGL"] = 35986] = "COMPRESSED_RGB_ATC_WEBGL";
436
+ INTERNAL_FORMATS[INTERNAL_FORMATS["COMPRESSED_RGBA_ATC_EXPLICIT_ALPHA_WEBGL"] = 35986] = "COMPRESSED_RGBA_ATC_EXPLICIT_ALPHA_WEBGL";
437
+ INTERNAL_FORMATS[INTERNAL_FORMATS["COMPRESSED_RGBA_ATC_INTERPOLATED_ALPHA_WEBGL"] = 34798] = "COMPRESSED_RGBA_ATC_INTERPOLATED_ALPHA_WEBGL";
438
+ INTERNAL_FORMATS[INTERNAL_FORMATS["COMPRESSED_RGBA_ASTC_10x10_KHR"] = 37819] = "COMPRESSED_RGBA_ASTC_10x10_KHR";
439
+ INTERNAL_FORMATS[INTERNAL_FORMATS["COMPRESSED_RGBA_ASTC_10x5_KHR"] = 37816] = "COMPRESSED_RGBA_ASTC_10x5_KHR";
440
+ INTERNAL_FORMATS[INTERNAL_FORMATS["COMPRESSED_RGBA_ASTC_10x6_KHR"] = 37817] = "COMPRESSED_RGBA_ASTC_10x6_KHR";
441
+ INTERNAL_FORMATS[INTERNAL_FORMATS["COMPRESSED_RGBA_ASTC_10x8_KHR"] = 37818] = "COMPRESSED_RGBA_ASTC_10x8_KHR";
442
+ INTERNAL_FORMATS[INTERNAL_FORMATS["COMPRESSED_RGBA_ASTC_12x10_KHR"] = 37820] = "COMPRESSED_RGBA_ASTC_12x10_KHR";
443
+ INTERNAL_FORMATS[INTERNAL_FORMATS["COMPRESSED_RGBA_ASTC_12x12_KHR"] = 37821] = "COMPRESSED_RGBA_ASTC_12x12_KHR";
444
+ INTERNAL_FORMATS[INTERNAL_FORMATS["COMPRESSED_RGBA_ASTC_4x4_KHR"] = 37808] = "COMPRESSED_RGBA_ASTC_4x4_KHR";
445
+ INTERNAL_FORMATS[INTERNAL_FORMATS["COMPRESSED_RGBA_ASTC_5x4_KHR"] = 37809] = "COMPRESSED_RGBA_ASTC_5x4_KHR";
446
+ INTERNAL_FORMATS[INTERNAL_FORMATS["COMPRESSED_RGBA_ASTC_5x5_KHR"] = 37810] = "COMPRESSED_RGBA_ASTC_5x5_KHR";
447
+ INTERNAL_FORMATS[INTERNAL_FORMATS["COMPRESSED_RGBA_ASTC_6x5_KHR"] = 37811] = "COMPRESSED_RGBA_ASTC_6x5_KHR";
448
+ INTERNAL_FORMATS[INTERNAL_FORMATS["COMPRESSED_RGBA_ASTC_6x6_KHR"] = 37812] = "COMPRESSED_RGBA_ASTC_6x6_KHR";
449
+ INTERNAL_FORMATS[INTERNAL_FORMATS["COMPRESSED_RGBA_ASTC_8x5_KHR"] = 37813] = "COMPRESSED_RGBA_ASTC_8x5_KHR";
450
+ INTERNAL_FORMATS[INTERNAL_FORMATS["COMPRESSED_RGBA_ASTC_8x6_KHR"] = 37814] = "COMPRESSED_RGBA_ASTC_8x6_KHR";
451
+ INTERNAL_FORMATS[INTERNAL_FORMATS["COMPRESSED_RGBA_ASTC_8x8_KHR"] = 37815] = "COMPRESSED_RGBA_ASTC_8x8_KHR";
452
+ INTERNAL_FORMATS[INTERNAL_FORMATS["COMPRESSED_SRGB8_ALPHA8_ASTC_10x10_KHR"] = 3781] = "COMPRESSED_SRGB8_ALPHA8_ASTC_10x10_KHR";
453
+ INTERNAL_FORMATS[INTERNAL_FORMATS["COMPRESSED_SRGB8_ALPHA8_ASTC_10x5_KHR"] = 37847] = "COMPRESSED_SRGB8_ALPHA8_ASTC_10x5_KHR";
454
+ INTERNAL_FORMATS[INTERNAL_FORMATS["COMPRESSED_SRGB8_ALPHA8_ASTC_10x6_KHR"] = 37849] = "COMPRESSED_SRGB8_ALPHA8_ASTC_10x6_KHR";
455
+ INTERNAL_FORMATS[INTERNAL_FORMATS["COMPRESSED_SRGB8_ALPHA8_ASTC_10x8_KHR"] = 37850] = "COMPRESSED_SRGB8_ALPHA8_ASTC_10x8_KHR";
456
+ INTERNAL_FORMATS[INTERNAL_FORMATS["COMPRESSED_SRGB8_ALPHA8_ASTC_12x10_KHR"] = 37852] = "COMPRESSED_SRGB8_ALPHA8_ASTC_12x10_KHR";
457
+ INTERNAL_FORMATS[INTERNAL_FORMATS["COMPRESSED_SRGB8_ALPHA8_ASTC_12x12_KHR"] = 37853] = "COMPRESSED_SRGB8_ALPHA8_ASTC_12x12_KHR";
458
+ INTERNAL_FORMATS[INTERNAL_FORMATS["COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR"] = 37840] = "COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR";
459
+ INTERNAL_FORMATS[INTERNAL_FORMATS["COMPRESSED_SRGB8_ALPHA8_ASTC_5x4_KHR"] = 37841] = "COMPRESSED_SRGB8_ALPHA8_ASTC_5x4_KHR";
460
+ INTERNAL_FORMATS[INTERNAL_FORMATS["COMPRESSED_SRGB8_ALPHA8_ASTC_5x5_KHR"] = 37842] = "COMPRESSED_SRGB8_ALPHA8_ASTC_5x5_KHR";
461
+ INTERNAL_FORMATS[INTERNAL_FORMATS["COMPRESSED_SRGB8_ALPHA8_ASTC_6x5_KHR"] = 37843] = "COMPRESSED_SRGB8_ALPHA8_ASTC_6x5_KHR";
462
+ INTERNAL_FORMATS[INTERNAL_FORMATS["COMPRESSED_SRGB8_ALPHA8_ASTC_6x6_KHR"] = 37844] = "COMPRESSED_SRGB8_ALPHA8_ASTC_6x6_KHR";
463
+ INTERNAL_FORMATS[INTERNAL_FORMATS["COMPRESSED_SRGB8_ALPHA8_ASTC_8x5_KHR"] = 37845] = "COMPRESSED_SRGB8_ALPHA8_ASTC_8x5_KHR";
464
+ INTERNAL_FORMATS[INTERNAL_FORMATS["COMPRESSED_SRGB8_ALPHA8_ASTC_8x6_KHR"] = 37846] = "COMPRESSED_SRGB8_ALPHA8_ASTC_8x6_KHR";
465
+ INTERNAL_FORMATS[INTERNAL_FORMATS["COMPRESSED_SRGB8_ALPHA8_ASTC_8x8_KHR"] = 37847] = "COMPRESSED_SRGB8_ALPHA8_ASTC_8x8_KHR";
466
+ })(INTERNAL_FORMATS || (INTERNAL_FORMATS = {}));
467
+
468
+ var INTERNAL_FORMAT_TO_BLOCK_SIZE = (_a = {}, _a[INTERNAL_FORMATS.COMPRESSED_RGB_S3TC_DXT1_EXT] = [4, 4], _a[INTERNAL_FORMATS.COMPRESSED_RGBA_S3TC_DXT1_EXT] = [4, 4], _a[INTERNAL_FORMATS.COMPRESSED_RGBA_S3TC_DXT3_EXT] = [4, 4], _a[INTERNAL_FORMATS.COMPRESSED_RGBA_S3TC_DXT5_EXT] = [4, 4], _a[INTERNAL_FORMATS.COMPRESSED_SRGB_S3TC_DXT1_EXT] = [4, 4], _a[INTERNAL_FORMATS.COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT] = [4, 4], _a[INTERNAL_FORMATS.COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT] = [4, 4], _a[INTERNAL_FORMATS.COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT] = [4, 4], _a[INTERNAL_FORMATS.COMPRESSED_R11_EAC] = [4, 4], _a[INTERNAL_FORMATS.COMPRESSED_SIGNED_R11_EAC] = [4, 4], _a[INTERNAL_FORMATS.COMPRESSED_RG11_EAC] = [4, 4], _a[INTERNAL_FORMATS.COMPRESSED_SIGNED_RG11_EAC] = [4, 4], _a[INTERNAL_FORMATS.COMPRESSED_RGB8_ETC2] = [4, 4], _a[INTERNAL_FORMATS.COMPRESSED_RGBA8_ETC2_EAC] = [4, 4], _a[INTERNAL_FORMATS.COMPRESSED_SRGB8_ETC2] = [4, 4], _a[INTERNAL_FORMATS.COMPRESSED_SRGB8_ALPHA8_ETC2_EAC] = [4, 4], _a[INTERNAL_FORMATS.COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2] = [4, 4], _a[INTERNAL_FORMATS.COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2] = [4, 4], _a[INTERNAL_FORMATS.COMPRESSED_RGB_PVRTC_4BPPV1_IMG] = [4, 4], _a[INTERNAL_FORMATS.COMPRESSED_RGBA_PVRTC_4BPPV1_IMG] = [4, 4], _a[INTERNAL_FORMATS.COMPRESSED_RGB_PVRTC_2BPPV1_IMG] = [8, 4], _a[INTERNAL_FORMATS.COMPRESSED_RGBA_PVRTC_2BPPV1_IMG] = [8, 4], _a[INTERNAL_FORMATS.COMPRESSED_RGB_ETC1_WEBGL] = [4, 4], _a[INTERNAL_FORMATS.COMPRESSED_RGB_ATC_WEBGL] = [4, 4], _a[INTERNAL_FORMATS.COMPRESSED_RGBA_ATC_EXPLICIT_ALPHA_WEBGL] = [4, 4], _a[INTERNAL_FORMATS.COMPRESSED_RGBA_ATC_INTERPOLATED_ALPHA_WEBGL] = [4, 4], _a[INTERNAL_FORMATS.COMPRESSED_RGBA_ASTC_4x4_KHR] = [4, 4], _a[INTERNAL_FORMATS.COMPRESSED_RGBA_ASTC_5x5_KHR] = [5, 5], _a[INTERNAL_FORMATS.COMPRESSED_RGBA_ASTC_6x6_KHR] = [6, 6], _a[INTERNAL_FORMATS.COMPRESSED_RGBA_ASTC_8x8_KHR] = [8, 8], _a[INTERNAL_FORMATS.COMPRESSED_RGBA_ASTC_10x10_KHR] = [10, 10], _a[INTERNAL_FORMATS.COMPRESSED_RGBA_ASTC_12x12_KHR] = [12, 12], _a[INTERNAL_FORMATS.COMPRESSED_RGBA_ASTC_10x5_KHR] = [10, 5], _a[INTERNAL_FORMATS.COMPRESSED_RGBA_ASTC_10x6_KHR] = [10, 6], _a[INTERNAL_FORMATS.COMPRESSED_RGBA_ASTC_10x8_KHR] = [10, 8], _a[INTERNAL_FORMATS.COMPRESSED_RGBA_ASTC_12x10_KHR] = [12, 10], _a[INTERNAL_FORMATS.COMPRESSED_RGBA_ASTC_5x4_KHR] = [5, 4], _a[INTERNAL_FORMATS.COMPRESSED_RGBA_ASTC_6x5_KHR] = [6, 5], _a[INTERNAL_FORMATS.COMPRESSED_RGBA_ASTC_8x5_KHR] = [8, 5], _a[INTERNAL_FORMATS.COMPRESSED_RGBA_ASTC_8x6_KHR] = [8, 6], _a);
469
+ var INTERNAL_FORMATS_TO_EXTENSION_NAME = (_b = {}, _b[INTERNAL_FORMATS.COMPRESSED_RGB_S3TC_DXT1_EXT] = 'WEBGL_compressed_texture_s3tc', _b[INTERNAL_FORMATS.COMPRESSED_RGBA_S3TC_DXT1_EXT] = 'WEBGL_compressed_texture_s3tc', _b[INTERNAL_FORMATS.COMPRESSED_RGBA_S3TC_DXT3_EXT] = 'WEBGL_compressed_texture_s3tc', _b[INTERNAL_FORMATS.COMPRESSED_RGBA_S3TC_DXT5_EXT] = 'WEBGL_compressed_texture_s3tc', _b[INTERNAL_FORMATS.COMPRESSED_SRGB_S3TC_DXT1_EXT] = 'WEBGL_compressed_texture_s3tc_srgb', _b[INTERNAL_FORMATS.COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT] = 'WEBGL_compressed_texture_s3tc_srgb', _b[INTERNAL_FORMATS.COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT] = 'WEBGL_compressed_texture_s3tc_srgb', _b[INTERNAL_FORMATS.COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT] = 'WEBGL_compressed_texture_s3tc_srgb', _b[INTERNAL_FORMATS.COMPRESSED_R11_EAC] = 'WEBGL_compressed_texture_etc', _b[INTERNAL_FORMATS.COMPRESSED_SIGNED_R11_EAC] = 'WEBGL_compressed_texture_etc', _b[INTERNAL_FORMATS.COMPRESSED_RG11_EAC] = 'WEBGL_compressed_texture_etc', _b[INTERNAL_FORMATS.COMPRESSED_SIGNED_RG11_EAC] = 'WEBGL_compressed_texture_etc', _b[INTERNAL_FORMATS.COMPRESSED_RGB8_ETC2] = 'WEBGL_compressed_texture_etc', _b[INTERNAL_FORMATS.COMPRESSED_RGBA8_ETC2_EAC] = 'WEBGL_compressed_texture_etc', _b[INTERNAL_FORMATS.COMPRESSED_SRGB8_ETC2] = 'WEBGL_compressed_texture_etc', _b[INTERNAL_FORMATS.COMPRESSED_SRGB8_ALPHA8_ETC2_EAC] = 'WEBGL_compressed_texture_etc', _b[INTERNAL_FORMATS.COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2] = 'WEBGL_compressed_texture_etc', _b[INTERNAL_FORMATS.COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2] = 'WEBGL_compressed_texture_etc', _b[INTERNAL_FORMATS.COMPRESSED_RGB_PVRTC_4BPPV1_IMG] = 'WEBGL_compressed_texture_pvrtc', _b[INTERNAL_FORMATS.COMPRESSED_RGBA_PVRTC_4BPPV1_IMG] = 'WEBGL_compressed_texture_pvrtc', _b[INTERNAL_FORMATS.COMPRESSED_RGB_PVRTC_2BPPV1_IMG] = 'WEBGL_compressed_texture_pvrtc', _b[INTERNAL_FORMATS.COMPRESSED_RGBA_PVRTC_2BPPV1_IMG] = 'WEBGL_compressed_texture_pvrtc', _b[INTERNAL_FORMATS.COMPRESSED_RGB_ETC1_WEBGL] = 'WEBGL_compressed_texture_etc1', _b[INTERNAL_FORMATS.COMPRESSED_RGB_ATC_WEBGL] = 'WEBGL_compressed_texture_atc', _b[INTERNAL_FORMATS.COMPRESSED_RGBA_ATC_EXPLICIT_ALPHA_WEBGL] = 'WEBGL_compressed_texture_atc', _b[INTERNAL_FORMATS.COMPRESSED_RGBA_ATC_INTERPOLATED_ALPHA_WEBGL] = 'WEBGL_compressed_texture_atc', _b[INTERNAL_FORMATS.COMPRESSED_RGBA_ASTC_4x4_KHR] = 'WEBGL_compressed_texture_astc', _b[INTERNAL_FORMATS.COMPRESSED_RGBA_ASTC_5x5_KHR] = 'WEBGL_compressed_texture_astc', _b[INTERNAL_FORMATS.COMPRESSED_RGBA_ASTC_6x6_KHR] = 'WEBGL_compressed_texture_astc', _b[INTERNAL_FORMATS.COMPRESSED_RGBA_ASTC_8x8_KHR] = 'WEBGL_compressed_texture_astc', _b[INTERNAL_FORMATS.COMPRESSED_RGBA_ASTC_10x10_KHR] = 'WEBGL_compressed_texture_astc', _b[INTERNAL_FORMATS.COMPRESSED_RGBA_ASTC_12x12_KHR] = 'WEBGL_compressed_texture_astc', _b);
470
+
471
+ var CompressedTextureResource = function () {
472
+ function CompressedTextureResource() {
473
+ this.levelBuffers = [];
474
+ }
475
+
476
+ CompressedTextureResource.prototype.upload = function (gl) {
477
+ var levels = this.levels;
478
+ var name = INTERNAL_FORMATS_TO_EXTENSION_NAME[this.internalFormat];
479
+
480
+ if (!gl[name]) {
481
+ gl[name] = true;
482
+
483
+ if (name === 'WEBGL_compressed_texture_pvrtc') {
484
+ gl.getExtension(name) || gl.getExtension('WEBKIT_WEBGL_compressed_texture_pvrtc');
485
+ } else {
486
+ gl.getExtension(name);
487
+ }
488
+ }
489
+
490
+ for (var i = 0; i < this.levels; ++i) {
491
+ var _a = this.levelBuffers[i],
492
+ levelWidth = _a.levelWidth,
493
+ levelHeight = _a.levelHeight,
494
+ levelBuffer = _a.levelBuffer;
495
+ gl.compressedTexImage2D(gl.TEXTURE_2D, i, this.internalFormat, levelWidth, levelHeight, 0, levelBuffer);
496
+ }
497
+
498
+ if (levels > 1) {
499
+ gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR);
500
+ gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR_MIPMAP_NEAREST);
501
+ } else {
502
+ gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR);
503
+ gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR);
504
+ }
505
+ };
506
+
507
+ return CompressedTextureResource;
508
+ }();
509
+
510
+ var FILE_HEADER_SIZE = 64;
511
+ var KTX_FIELDS = {
512
+ FILE_IDENTIFIER: 0,
513
+ ENDIANNESS: 12,
514
+ GL_TYPE: 16,
515
+ GL_TYPE_SIZE: 20,
516
+ GL_FORMAT: 24,
517
+ GL_INTERNAL_FORMAT: 28,
518
+ GL_BASE_INTERNAL_FORMAT: 32,
519
+ PIXEL_WIDTH: 36,
520
+ PIXEL_HEIGHT: 40,
521
+ PIXEL_DEPTH: 44,
522
+ NUMBER_OF_ARRAY_ELEMENTS: 48,
523
+ NUMBER_OF_FACES: 52,
524
+ NUMBER_OF_MIPMAP_LEVELS: 56,
525
+ BYTES_OF_KEY_VALUE_DATA: 60
526
+ };
527
+ var FILE_IDENTIFIER = [0xAB, 0x4B, 0x54, 0x58, 0x20, 0x31, 0x31, 0xBB, 0x0D, 0x0A, 0x1A, 0x0A];
528
+ var ENDIANNESS = 0x04030201;
529
+
530
+ var KTXTextureResource = function (_super) {
531
+ __extends(KTXTextureResource, _super);
532
+
533
+ function KTXTextureResource(source, config) {
534
+ var _a;
535
+
536
+ var _this = _super.call(this) || this;
537
+
538
+ _this.complete = true;
539
+ _this.src = config.url;
540
+ var dataView = new DataView(source);
541
+
542
+ if (!validateKTX(dataView)) {
543
+ throw new Error('Not a valid KTX Texture');
544
+ }
545
+
546
+ var littleEndian = dataView.getUint32(KTX_FIELDS.ENDIANNESS, true) === ENDIANNESS;
547
+ _this.internalFormat = dataView.getUint32(KTX_FIELDS.GL_INTERNAL_FORMAT, littleEndian);
548
+ var pixelWidth = _this.formerWidth = dataView.getUint32(KTX_FIELDS.PIXEL_WIDTH, littleEndian);
549
+ var pixelHeight = _this.formerHeight = dataView.getUint32(KTX_FIELDS.PIXEL_HEIGHT, littleEndian) || 1;
550
+ var size = INTERNAL_FORMAT_TO_BLOCK_SIZE[_this.internalFormat];
551
+ _this.width = pixelWidth % size[0] === 0 ? pixelWidth : pixelWidth + size[0] - pixelWidth % size[0];
552
+ _this.height = pixelHeight % size[1] === 0 ? pixelHeight : pixelHeight + size[1] - pixelHeight % size[1];
553
+ var src = resource.resourcesMap[config.metadata.name].src[config.metadata.key];
554
+
555
+ var _b = (_a = src === null || src === void 0 ? void 0 : src.size) !== null && _a !== void 0 ? _a : {},
556
+ width = _b.width,
557
+ height = _b.height;
558
+
559
+ if (width && height) {
560
+ _this.naturalWidth = width;
561
+ _this.naturalHeight = height;
562
+ }
563
+
564
+ var pixelDepth = dataView.getUint32(KTX_FIELDS.PIXEL_DEPTH, littleEndian) || 1;
565
+ var numberOfArrayElements = dataView.getUint32(KTX_FIELDS.NUMBER_OF_ARRAY_ELEMENTS, littleEndian) || 1;
566
+ var numberOfFaces = dataView.getUint32(KTX_FIELDS.NUMBER_OF_FACES, littleEndian);
567
+ var numberOfMipmapLevels = _this.levels = dataView.getUint32(KTX_FIELDS.NUMBER_OF_MIPMAP_LEVELS, littleEndian);
568
+ var bytesOfKeyValueData = dataView.getUint32(KTX_FIELDS.BYTES_OF_KEY_VALUE_DATA, littleEndian);
569
+
570
+ if (pixelHeight === 0 || pixelDepth !== 1) {
571
+ throw new Error('Only 2D textures are supported!');
572
+ }
573
+
574
+ if (numberOfFaces !== 1) {
575
+ throw new Error('CubeTextures are not supported!');
576
+ }
577
+
578
+ if (numberOfArrayElements !== 1) {
579
+ throw new Error('It does not support array textures!');
580
+ }
581
+
582
+ var mipWidth = pixelWidth;
583
+ var mipHeight = pixelHeight;
584
+ var imageOffset = FILE_HEADER_SIZE + bytesOfKeyValueData;
585
+
586
+ for (var mipmapLevel = 0; mipmapLevel < numberOfMipmapLevels; mipmapLevel++) {
587
+ var imageSize = dataView.getUint32(imageOffset, littleEndian);
588
+ imageOffset += 4;
589
+ var size_1 = INTERNAL_FORMAT_TO_BLOCK_SIZE[_this.internalFormat];
590
+ var levelWidth = mipWidth % size_1[0] === 0 ? mipWidth : mipWidth + size_1[0] - mipWidth % size_1[0];
591
+ var levelHeight = mipHeight % size_1[1] === 0 ? mipHeight : mipHeight + size_1[1] - mipHeight % size_1[1];
592
+ var mip = {
593
+ levelID: mipmapLevel,
594
+ levelWidth: levelWidth,
595
+ levelHeight: levelHeight,
596
+ levelBuffer: new Uint8Array(source, imageOffset, imageSize)
597
+ };
598
+
599
+ _this.levelBuffers.push(mip);
600
+
601
+ imageOffset += imageSize;
602
+ imageOffset += 3 - (imageOffset + 3) % 4;
603
+ mipWidth = mipWidth >> 1 || 1;
604
+ mipHeight = mipHeight >> 1 || 1;
605
+ }
606
+
607
+ return _this;
608
+ }
609
+
610
+ return KTXTextureResource;
611
+ }(CompressedTextureResource);
612
+
613
+ function validateKTX(dataView) {
614
+ for (var i = 0; i < FILE_IDENTIFIER.length; i++) {
615
+ if (dataView.getUint8(i) !== FILE_IDENTIFIER[i]) {
616
+ return false;
617
+ }
618
+ }
619
+
620
+ return true;
621
+ }
622
+
623
+ var KTXLoadStrategy = function (_super) {
624
+ __extends(KTXLoadStrategy, _super);
625
+
626
+ function KTXLoadStrategy() {
627
+ return _super !== null && _super.apply(this, arguments) || this;
628
+ }
629
+
630
+ KTXLoadStrategy.prototype._complete = function (type, data) {
631
+ _super.prototype._complete.call(this, type, new KTXTextureResource(data, this.config));
632
+ };
633
+
634
+ return KTXLoadStrategy;
635
+ }(XhrLoadStrategy);
636
+
637
+ var KTXLoadStrategy$1 = KTXLoadStrategy;
638
+ var XhrResponseType = resourceLoader.XhrResponseType;
639
+
640
+ function addPreProcessResourceHandler(resource, gl) {
641
+ resource.addPreProcessResourceHandler(function normalizeResource(resource) {
642
+ var _a, _b, _c;
643
+
644
+ var textures = (_b = (_a = resource.src) === null || _a === void 0 ? void 0 : _a.image) === null || _b === void 0 ? void 0 : _b.texture;
645
+ if (!textures) return;
646
+
647
+ if (!Array.isArray(textures)) {
648
+ textures = [textures];
649
+ }
650
+
651
+ var formats = (_c = getSuportCompressedTextureFormats(gl)) !== null && _c !== void 0 ? _c : {};
652
+ var target = textures.find(function (texture) {
653
+ return formats[texture.type];
654
+ });
655
+
656
+ if (target) {
657
+ _extends(resource.src.image, target);
658
+ }
659
+ });
660
+ }
661
+
662
+ function addKTXStragetyAndRegister() {
663
+ _extends(RESOURCE_TYPE_STRATEGY, {
664
+ astc: KTXLoadStrategy$1,
665
+ etc: KTXLoadStrategy$1,
666
+ pvrtc: KTXLoadStrategy$1,
667
+ s3tc: KTXLoadStrategy$1,
668
+ atc: KTXLoadStrategy$1
669
+ });
670
+
671
+ KTXLoadStrategy$1.setExtensionXhrType('ktx', XhrResponseType.Buffer);
672
+ }
673
+
674
+ var GLTexture = glCore.GLTexture;
675
+ var GLTextureMixin = {
676
+ isCompressed: false,
677
+ uploadNotCompressed: GLTexture.prototype.upload,
678
+ upload: function upload(source) {
679
+ if (!(source instanceof CompressedTextureResource)) {
680
+ return this.uploadNotCompressed(source);
681
+ }
682
+
683
+ this.bind();
684
+ var gl = this.gl;
685
+ gl.pixelStorei(gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, this.premultiplyAlpha);
686
+ gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST_MIPMAP_NEAREST);
687
+ gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR);
688
+ this.isCompressed = true;
689
+ source.upload(gl);
690
+ },
691
+ enableMipmap: function enableMipmap() {
692
+ if (this.isCompressed) {
693
+ return;
694
+ }
695
+
696
+ var gl = this.gl;
697
+ this.bind();
698
+ this.mipmap = true;
699
+ gl.generateMipmap(gl.TEXTURE_2D);
700
+ }
701
+ };
702
+ var TextureMixin = {
703
+ oldFrom: Texture.from,
704
+ from: function from(source) {
705
+ if (!(source instanceof CompressedTextureResource)) {
706
+ return this.oldFrom(source);
707
+ }
708
+
709
+ return new Texture(BaseTexture.from(source));
710
+ }
711
+ };
712
+ var BaseTextureMixin = {
713
+ oldFrom: BaseTexture.from,
714
+ from: function from(source, scaleMode, sourceScale) {
715
+ if (!(source instanceof CompressedTextureResource)) {
716
+ return this.oldFrom(source, scaleMode, sourceScale);
717
+ }
718
+
719
+ var imageUrl = source.src;
720
+ var baseTexture = utils.BaseTextureCache[imageUrl];
721
+
722
+ if (!baseTexture) {
723
+ baseTexture = new BaseTexture(source, scaleMode);
724
+ baseTexture.imageUrl = imageUrl;
725
+
726
+ if (sourceScale) {
727
+ baseTexture.sourceScale = sourceScale;
728
+ }
729
+
730
+ BaseTexture.addToCache(baseTexture, imageUrl);
731
+ }
732
+
733
+ return baseTexture;
734
+ }
735
+ };
736
+
737
+ function registerCompressedTexture(gl) {
738
+ addPreProcessResourceHandler(resource, gl);
739
+ addKTXStragetyAndRegister();
740
+
741
+ _extends(glCore.GLTexture.prototype, GLTextureMixin);
742
+
743
+ _extends(Texture, TextureMixin);
744
+
745
+ _extends(BaseTexture, BaseTextureMixin);
746
+ }
747
+
748
+ var RENDERER_TYPE;
749
+
750
+ (function (RENDERER_TYPE) {
751
+ RENDERER_TYPE[RENDERER_TYPE["UNKNOWN"] = 0] = "UNKNOWN";
752
+ RENDERER_TYPE[RENDERER_TYPE["WEBGL"] = 1] = "WEBGL";
753
+ RENDERER_TYPE[RENDERER_TYPE["CANVAS"] = 2] = "CANVAS";
754
+ })(RENDERER_TYPE || (RENDERER_TYPE = {}));
755
+
756
+ var disableScroll = function disableScroll(renderer) {
757
+ renderer.plugins.interaction.autoPreventDefault = true;
758
+ renderer.view.style.touchAction = 'none';
759
+ };
760
+
761
+ var enableScroll = function enableScroll(renderer) {
762
+ renderer.plugins.interaction.autoPreventDefault = false;
763
+ renderer.view.style.touchAction = 'auto';
764
+ };
765
+
766
+ var Renderer$2 = function (_super) {
767
+ __extends(Renderer, _super);
768
+
769
+ function Renderer() {
770
+ var _this = _super !== null && _super.apply(this, arguments) || this;
771
+
772
+ _this.multiApps = [];
773
+ return _this;
774
+ }
775
+
776
+ Renderer.prototype.init = function (params) {
777
+ var _this = this;
778
+
779
+ this.params = params;
780
+ this.application = this.createApplication(params);
781
+ this.containerManager = new ContainerManager$1();
782
+ this.rendererManager = new RendererManager$1({
783
+ game: this.game,
784
+ rendererSystem: this
785
+ });
786
+ this.game.canvas = this.application.view;
787
+ this.transform = new Transform$1({
788
+ system: this,
789
+ containerManager: this.containerManager
790
+ });
791
+ this.game.on('sceneChanged', function (_a) {
792
+ var scene = _a.scene,
793
+ mode = _a.mode,
794
+ params = _a.params;
795
+ var application;
796
+
797
+ switch (mode) {
798
+ case LOAD_SCENE_MODE.SINGLE:
799
+ application = _this.application;
800
+ break;
801
+
802
+ case LOAD_SCENE_MODE.MULTI_CANVAS:
803
+ application = _this.createMultiApplication({
804
+ params: params
805
+ });
806
+ break;
807
+ }
808
+
809
+ scene.canvas = application.view;
810
+
811
+ _this.transform.emit('changeScene', {
812
+ scene: scene,
813
+ mode: mode,
814
+ application: application
815
+ });
816
+ });
817
+ var gl = this.application.renderer.gl;
818
+
819
+ if (gl) {
820
+ this.suportedCompressedTextureFormats = getSuportCompressedTextureFormats(gl);
821
+ registerCompressedTexture(gl);
822
+ }
823
+ };
824
+
825
+ Renderer.prototype.registerObserver = function (observerInfo) {
826
+ var _a;
827
+
828
+ var thisObserverInfo = this.constructor.observerInfo;
829
+
830
+ for (var key in observerInfo) {
831
+ if (!thisObserverInfo[key]) {
832
+ thisObserverInfo[key] = [];
833
+ }
834
+
835
+ (_a = thisObserverInfo[key]).push.apply(_a, __spread(observerInfo[key]));
836
+ }
837
+ };
838
+
839
+ Renderer.prototype.createMultiApplication = function (_a) {
840
+ var params = _a.params;
841
+ var app = this.createApplication(params);
842
+ this.multiApps.push(app);
843
+ return app;
844
+ };
845
+
846
+ Renderer.prototype.createApplication = function (params) {
847
+ params.view = params.canvas;
848
+
849
+ if (params.renderType === RENDERER_TYPE.CANVAS) {
850
+ params.forceCanvas = true;
851
+ }
852
+
853
+ var app;
854
+
855
+ try {
856
+ app = new Application(__assign({
857
+ sharedTicker: true
858
+ }, params));
859
+ } catch (e) {
860
+ if (e.message.match(/not support webgl/i) !== undefined) {
861
+ app = new Application(__assign(__assign({
862
+ sharedTicker: true
863
+ }, params), {
864
+ forceCanvas: true
865
+ }));
866
+ }
867
+ }
868
+
869
+ ticker.shared.stop();
870
+ ticker.shared.autoStart = false;
871
+
872
+ if (params.preventScroll !== undefined) {
873
+ console.warn('PreventScroll property will deprecate at next major version, please use enableScroll instead. https://eva.js.org/#/tutorials/game');
874
+ params.preventScroll ? enableScroll(app.renderer) : disableScroll(app.renderer);
875
+ }
876
+
877
+ if (params.enableScroll !== undefined) {
878
+ params.enableScroll ? enableScroll(app.renderer) : disableScroll(app.renderer);
879
+ }
880
+
881
+ if (params.preventScroll === undefined && params.enableScroll === undefined) {
882
+ enableScroll(app.renderer);
883
+ }
884
+
885
+ return app;
886
+ };
887
+
888
+ Renderer.prototype.update = function () {
889
+ var e_1, _a, e_2, _b;
890
+
891
+ var changes = this.componentObserver.clear();
892
+
893
+ try {
894
+ for (var changes_1 = __values(changes), changes_1_1 = changes_1.next(); !changes_1_1.done; changes_1_1 = changes_1.next()) {
895
+ var changed = changes_1_1.value;
896
+ this.transform.componentChanged(changed);
897
+ }
898
+ } catch (e_1_1) {
899
+ e_1 = {
900
+ error: e_1_1
901
+ };
902
+ } finally {
903
+ try {
904
+ if (changes_1_1 && !changes_1_1.done && (_a = changes_1.return)) _a.call(changes_1);
905
+ } finally {
906
+ if (e_1) throw e_1.error;
907
+ }
908
+ }
909
+
910
+ try {
911
+ for (var _c = __values(this.game.gameObjects), _d = _c.next(); !_d.done; _d = _c.next()) {
912
+ var gameObject = _d.value;
913
+ this.containerManager.updateTransform({
914
+ name: gameObject.id,
915
+ transform: gameObject.transform
916
+ });
917
+ this.rendererManager.update(gameObject);
918
+ }
919
+ } catch (e_2_1) {
920
+ e_2 = {
921
+ error: e_2_1
922
+ };
923
+ } finally {
924
+ try {
925
+ if (_d && !_d.done && (_b = _c.return)) _b.call(_c);
926
+ } finally {
927
+ if (e_2) throw e_2.error;
928
+ }
929
+ }
930
+ };
931
+
932
+ Renderer.prototype.lateUpdate = function (e) {
933
+ this.transform.update();
934
+ this.application.ticker.update(e.time);
935
+ };
936
+
937
+ Renderer.prototype.onDestroy = function () {
938
+ var e_3, _a;
939
+
940
+ this.application.destroy();
941
+
942
+ try {
943
+ for (var _b = __values(this.multiApps), _c = _b.next(); !_c.done; _c = _b.next()) {
944
+ var app = _c.value;
945
+ app && app.destroy();
946
+ }
947
+ } catch (e_3_1) {
948
+ e_3 = {
949
+ error: e_3_1
950
+ };
951
+ } finally {
952
+ try {
953
+ if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
954
+ } finally {
955
+ if (e_3) throw e_3.error;
956
+ }
957
+ }
958
+
959
+ this.transform.destroy();
960
+ this.transform = null;
961
+ this.params = null;
962
+ this.rendererManager = null;
963
+ this.containerManager = null;
964
+ this.application = null;
965
+ this.game = null;
966
+ this.multiApps = null;
967
+ };
968
+
969
+ Renderer.prototype.resize = function (width, height) {
970
+ this.params.width = width;
971
+ this.params.height = height;
972
+ this.application.renderer.resize(width, height);
973
+ };
974
+
975
+ Renderer.systemName = 'Renderer';
976
+ Renderer = __decorate([decorators.componentObserver({
977
+ Transform: ['_parent']
978
+ })], Renderer);
979
+ return Renderer;
980
+ }(System);
981
+
982
+ var Renderer$3 = Renderer$2;
983
+
984
+ var Renderer = function (_super) {
985
+ __extends(Renderer, _super);
986
+
987
+ function Renderer(params) {
988
+ var _this = _super.call(this, params) || this;
989
+
990
+ _this.asyncIdMap = {};
991
+ _this.observerInfo = _this.constructor.observerInfo;
992
+ return _this;
993
+ }
994
+
995
+ Renderer.prototype.componentChanged = function (_changed) {};
996
+
997
+ Renderer.prototype.rendererUpdate = function (_gameObject) {};
998
+
999
+ Renderer.prototype.update = function (e) {
1000
+ var e_1, _a;
1001
+
1002
+ var changes = this.componentObserver.clear();
1003
+
1004
+ try {
1005
+ for (var changes_1 = __values(changes), changes_1_1 = changes_1.next(); !changes_1_1.done; changes_1_1 = changes_1.next()) {
1006
+ var changed = changes_1_1.value;
1007
+ this.componentChanged(changed);
1008
+ }
1009
+ } catch (e_1_1) {
1010
+ e_1 = {
1011
+ error: e_1_1
1012
+ };
1013
+ } finally {
1014
+ try {
1015
+ if (changes_1_1 && !changes_1_1.done && (_a = changes_1.return)) _a.call(changes_1);
1016
+ } finally {
1017
+ if (e_1) throw e_1.error;
1018
+ }
1019
+ }
1020
+ };
1021
+
1022
+ Renderer.prototype.increaseAsyncId = function (id) {
1023
+ this.asyncIdMap[id] = (this.asyncIdMap[id] || 0) + 1;
1024
+ return this.asyncIdMap[id];
1025
+ };
1026
+
1027
+ Renderer.prototype.validateAsyncId = function (id, asyncId) {
1028
+ return this.asyncIdMap[id] === asyncId;
1029
+ };
1030
+
1031
+ return Renderer;
1032
+ }(System);
1033
+
1034
+ var Renderer$1 = Renderer;
1035
+
1036
+ var mixinPIXI = function mixinPIXI() {
1037
+ BaseTexture.prototype.destroy = function () {
1038
+ if (this.imageUrl) {
1039
+ delete utils.TextureCache[this.imageUrl];
1040
+ this.imageUrl = null;
1041
+ }
1042
+
1043
+ this.source = null;
1044
+ this.dispose();
1045
+ BaseTexture.removeFromCache(this);
1046
+ this.textureCacheIds = null;
1047
+ this._destroyed = true;
1048
+ };
1049
+ };
1050
+
1051
+ mixinPIXI();
1052
+ export { ContainerManager$1 as ContainerManager, RENDERER_TYPE, Renderer$1 as Renderer, RendererManager$1 as RendererManager, Renderer$3 as RendererSystem };