Add auto context restoration
This commit is contained in:
parent
40b9644171
commit
2e57f090e6
1 changed files with 353 additions and 137 deletions
|
|
@ -0,0 +1,27 @@
|
|||
let isEnabled = false;
|
||||
|
||||
export const enableContextLostSimulator = (canvas: HTMLCanvasElement) => {
|
||||
if (isEnabled) {
|
||||
return;
|
||||
}
|
||||
|
||||
isEnabled = true;
|
||||
|
||||
const gl = canvas.getContext('webgl2')!;
|
||||
const ext = gl.getExtension('WEBGL_lose_context');
|
||||
|
||||
const simulateContextLost = () => {
|
||||
ext!.loseContext();
|
||||
console.log('lost');
|
||||
|
||||
const restoreTimeout = Math.random() * 500;
|
||||
setTimeout(() => {
|
||||
ext!.restoreContext();
|
||||
console.log('restored');
|
||||
}, restoreTimeout);
|
||||
|
||||
setTimeout(() => simulateContextLost(), restoreTimeout + Math.random() * 500);
|
||||
};
|
||||
|
||||
setTimeout(simulateContextLost, 1000);
|
||||
};
|
||||
Loading…
Reference in a new issue