mirror of
https://github.com/EsotericSoftware/spine-runtimes.git
synced 2026-03-03 22:29:13 +08:00
[ts] Fix webglcontextlost/restored not correctly bound. Close #2938.
This commit is contained in:
parent
bf26fb9683
commit
6cfe4cb1a5
@ -27,16 +27,16 @@
|
|||||||
* THE SPINE RUNTIMES, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
* THE SPINE RUNTIMES, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
*****************************************************************************/
|
*****************************************************************************/
|
||||||
|
|
||||||
import { Disposable, type Restorable } from "@esotericsoftware/spine-core";
|
import type { Disposable, Restorable } from "@esotericsoftware/spine-core";
|
||||||
|
|
||||||
export class ManagedWebGLRenderingContext implements Disposable {
|
export class ManagedWebGLRenderingContext implements Disposable {
|
||||||
public canvas: HTMLCanvasElement | OffscreenCanvas;
|
public canvas: HTMLCanvasElement | OffscreenCanvas;
|
||||||
public gl: WebGLRenderingContext;
|
public gl: WebGLRenderingContext;
|
||||||
private restorables = new Array<Restorable>();
|
private restorables = [] as Restorable[];
|
||||||
|
|
||||||
constructor (canvasOrContext: HTMLCanvasElement | WebGLRenderingContext, contextConfig: any = { alpha: "true" }) {
|
constructor (canvasOrContext: HTMLCanvasElement | WebGLRenderingContext, contextConfig: WebGLContextAttributes = { alpha: true }) {
|
||||||
if (!((canvasOrContext instanceof WebGLRenderingContext) || (typeof WebGL2RenderingContext !== 'undefined' && canvasOrContext instanceof WebGL2RenderingContext))) {
|
if (!((canvasOrContext instanceof WebGLRenderingContext) || (typeof WebGL2RenderingContext !== 'undefined' && canvasOrContext instanceof WebGL2RenderingContext))) {
|
||||||
let canvas: HTMLCanvasElement = canvasOrContext;
|
const canvas: HTMLCanvasElement = canvasOrContext;
|
||||||
this.gl = <WebGLRenderingContext>(canvas.getContext("webgl2", contextConfig) || canvas.getContext("webgl", contextConfig));
|
this.gl = <WebGLRenderingContext>(canvas.getContext("webgl2", contextConfig) || canvas.getContext("webgl", contextConfig));
|
||||||
this.canvas = canvas;
|
this.canvas = canvas;
|
||||||
canvas.addEventListener("webglcontextlost", this.contextLostHandler);
|
canvas.addEventListener("webglcontextlost", this.contextLostHandler);
|
||||||
@ -47,11 +47,11 @@ export class ManagedWebGLRenderingContext implements Disposable {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private contextLostHandler (e: Event) {
|
private contextLostHandler = (e: Event) => {
|
||||||
if (e) e.preventDefault();
|
if (e) e.preventDefault();
|
||||||
}
|
}
|
||||||
|
|
||||||
private contextRestoredHandler (e: Event) {
|
private contextRestoredHandler = () => {
|
||||||
for (let i = 0, n = this.restorables.length; i < n; i++)
|
for (let i = 0, n = this.restorables.length; i < n; i++)
|
||||||
this.restorables[i].restore();
|
this.restorables[i].restore();
|
||||||
}
|
}
|
||||||
@ -66,7 +66,7 @@ export class ManagedWebGLRenderingContext implements Disposable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
removeRestorable (restorable: Restorable) {
|
removeRestorable (restorable: Restorable) {
|
||||||
let index = this.restorables.indexOf(restorable);
|
const index = this.restorables.indexOf(restorable);
|
||||||
if (index > -1) this.restorables.splice(index, 1);
|
if (index > -1) this.restorables.splice(index, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user