@esotericsoftware/spine-webgl 4.2.92 → 4.2.94
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.
- package/dist/WebGL.d.ts +2 -2
- package/dist/WebGL.js +9 -9
- package/dist/esm/spine-webgl.min.mjs +2 -2
- package/dist/esm/spine-webgl.mjs +41 -14
- package/dist/esm/spine-webgl.mjs.map +2 -2
- package/dist/iife/spine-webgl.js +41 -14
- package/dist/iife/spine-webgl.js.map +2 -2
- package/dist/iife/spine-webgl.min.js +2 -2
- package/package.json +2 -2
package/dist/esm/spine-webgl.mjs
CHANGED
|
@@ -5642,7 +5642,7 @@ var AssetManagerBase = class {
|
|
|
5642
5642
|
return blob ? createImageBitmap(blob, { premultiplyAlpha: "none", colorSpaceConversion: "none" }) : null;
|
|
5643
5643
|
}).then((bitmap) => {
|
|
5644
5644
|
if (bitmap) {
|
|
5645
|
-
const texture = this.
|
|
5645
|
+
const texture = this.createTexture(path, bitmap);
|
|
5646
5646
|
this.success(success, path, texture);
|
|
5647
5647
|
resolve(texture);
|
|
5648
5648
|
}
|
|
@@ -5652,7 +5652,7 @@ var AssetManagerBase = class {
|
|
|
5652
5652
|
let image = new Image();
|
|
5653
5653
|
image.crossOrigin = "anonymous";
|
|
5654
5654
|
image.onload = () => {
|
|
5655
|
-
const texture = this.
|
|
5655
|
+
const texture = this.createTexture(path, image);
|
|
5656
5656
|
this.success(success, path, texture);
|
|
5657
5657
|
resolve(texture);
|
|
5658
5658
|
};
|
|
@@ -5676,7 +5676,7 @@ var AssetManagerBase = class {
|
|
|
5676
5676
|
this.cache.assetsLoaded[path] = new Promise((resolve, reject) => {
|
|
5677
5677
|
this.downloader.downloadText(path, (atlasText) => {
|
|
5678
5678
|
try {
|
|
5679
|
-
|
|
5679
|
+
const atlas = this.createTextureAtlas(path, atlasText);
|
|
5680
5680
|
let toLoad = atlas.pages.length, abort = false;
|
|
5681
5681
|
for (let page of atlas.pages) {
|
|
5682
5682
|
this.loadTexture(
|
|
@@ -5720,7 +5720,7 @@ var AssetManagerBase = class {
|
|
|
5720
5720
|
this.cache.assetsLoaded[path] = new Promise((resolve, reject) => {
|
|
5721
5721
|
this.downloader.downloadText(path, (atlasText) => {
|
|
5722
5722
|
try {
|
|
5723
|
-
const atlas =
|
|
5723
|
+
const atlas = this.createTextureAtlas(path, atlasText);
|
|
5724
5724
|
this.success(success, path, atlas);
|
|
5725
5725
|
resolve(atlas);
|
|
5726
5726
|
} catch (e) {
|
|
@@ -5826,9 +5826,12 @@ var AssetManagerBase = class {
|
|
|
5826
5826
|
}
|
|
5827
5827
|
// dispose asset only if it's not used by others
|
|
5828
5828
|
disposeAsset(path) {
|
|
5829
|
-
|
|
5830
|
-
|
|
5829
|
+
const asset = this.cache.assets[path];
|
|
5830
|
+
if (asset instanceof TextureAtlas) {
|
|
5831
|
+
asset.dispose();
|
|
5832
|
+
return;
|
|
5831
5833
|
}
|
|
5834
|
+
this.disposeAssetInternal(path);
|
|
5832
5835
|
}
|
|
5833
5836
|
hasErrors() {
|
|
5834
5837
|
return Object.keys(this.errors).length > 0;
|
|
@@ -5836,6 +5839,30 @@ var AssetManagerBase = class {
|
|
|
5836
5839
|
getErrors() {
|
|
5837
5840
|
return this.errors;
|
|
5838
5841
|
}
|
|
5842
|
+
disposeAssetInternal(path) {
|
|
5843
|
+
if (this.cache.assetsRefCount[path] > 0 && --this.cache.assetsRefCount[path] === 0) {
|
|
5844
|
+
return this.remove(path);
|
|
5845
|
+
}
|
|
5846
|
+
}
|
|
5847
|
+
createTextureAtlas(path, atlasText) {
|
|
5848
|
+
const atlas = new TextureAtlas(atlasText);
|
|
5849
|
+
atlas.dispose = () => {
|
|
5850
|
+
if (this.cache.assetsRefCount[path] <= 0) return;
|
|
5851
|
+
this.disposeAssetInternal(path);
|
|
5852
|
+
for (const page of atlas.pages) {
|
|
5853
|
+
page.texture?.dispose();
|
|
5854
|
+
}
|
|
5855
|
+
};
|
|
5856
|
+
return atlas;
|
|
5857
|
+
}
|
|
5858
|
+
createTexture(path, image) {
|
|
5859
|
+
const texture = this.textureLoader(image);
|
|
5860
|
+
const textureDispose = texture.dispose.bind(texture);
|
|
5861
|
+
texture.dispose = () => {
|
|
5862
|
+
if (this.disposeAssetInternal(path)) textureDispose();
|
|
5863
|
+
};
|
|
5864
|
+
return texture;
|
|
5865
|
+
}
|
|
5839
5866
|
};
|
|
5840
5867
|
var AssetCache = class _AssetCache {
|
|
5841
5868
|
assets = {};
|
|
@@ -11284,10 +11311,10 @@ function getValue(map, property, defaultValue) {
|
|
|
11284
11311
|
var ManagedWebGLRenderingContext = class {
|
|
11285
11312
|
canvas;
|
|
11286
11313
|
gl;
|
|
11287
|
-
restorables =
|
|
11288
|
-
constructor(canvasOrContext, contextConfig = { alpha:
|
|
11314
|
+
restorables = [];
|
|
11315
|
+
constructor(canvasOrContext, contextConfig = { alpha: true }) {
|
|
11289
11316
|
if (!(canvasOrContext instanceof WebGLRenderingContext || typeof WebGL2RenderingContext !== "undefined" && canvasOrContext instanceof WebGL2RenderingContext)) {
|
|
11290
|
-
|
|
11317
|
+
const canvas = canvasOrContext;
|
|
11291
11318
|
this.gl = canvas.getContext("webgl2", contextConfig) || canvas.getContext("webgl", contextConfig);
|
|
11292
11319
|
this.canvas = canvas;
|
|
11293
11320
|
canvas.addEventListener("webglcontextlost", this.contextLostHandler);
|
|
@@ -11297,13 +11324,13 @@ var ManagedWebGLRenderingContext = class {
|
|
|
11297
11324
|
this.canvas = this.gl.canvas;
|
|
11298
11325
|
}
|
|
11299
11326
|
}
|
|
11300
|
-
contextLostHandler(e) {
|
|
11327
|
+
contextLostHandler = (e) => {
|
|
11301
11328
|
if (e) e.preventDefault();
|
|
11302
|
-
}
|
|
11303
|
-
contextRestoredHandler(
|
|
11329
|
+
};
|
|
11330
|
+
contextRestoredHandler = () => {
|
|
11304
11331
|
for (let i = 0, n = this.restorables.length; i < n; i++)
|
|
11305
11332
|
this.restorables[i].restore();
|
|
11306
|
-
}
|
|
11333
|
+
};
|
|
11307
11334
|
dispose() {
|
|
11308
11335
|
this.canvas.removeEventListener("webglcontextlost", this.contextLostHandler);
|
|
11309
11336
|
this.canvas.removeEventListener("webglcontextrestored", this.contextRestoredHandler);
|
|
@@ -11312,7 +11339,7 @@ var ManagedWebGLRenderingContext = class {
|
|
|
11312
11339
|
this.restorables.push(restorable);
|
|
11313
11340
|
}
|
|
11314
11341
|
removeRestorable(restorable) {
|
|
11315
|
-
|
|
11342
|
+
const index = this.restorables.indexOf(restorable);
|
|
11316
11343
|
if (index > -1) this.restorables.splice(index, 1);
|
|
11317
11344
|
}
|
|
11318
11345
|
};
|