|
@@ -563,7 +563,6 @@
|
|
|
private _vrDisplayEnabled;
|
|
|
private _oldSize: BABYLON.Size;
|
|
|
private _oldHardwareScaleFactor: number;
|
|
|
- private _vrAnimationFrameHandler: number;
|
|
|
|
|
|
// Uniform buffers list
|
|
|
public disableUniformBuffers = false;
|
|
@@ -696,6 +695,8 @@
|
|
|
private _emptyTexture: InternalTexture;
|
|
|
private _emptyCubeTexture: InternalTexture;
|
|
|
|
|
|
+ private _frameHandler: number;
|
|
|
+
|
|
|
// Hardware supported Compressed Textures
|
|
|
private _texturesSupported = new Array<string>();
|
|
|
private _textureFormatInUse: string;
|
|
@@ -829,52 +830,52 @@
|
|
|
window.addEventListener("focus", this._onFocus);
|
|
|
|
|
|
canvas.addEventListener("pointerout", this._onCanvasPointerOut);
|
|
|
- } else {
|
|
|
- this._gl = <WebGLRenderingContext>canvasOrContext;
|
|
|
- this._renderingCanvas = this._gl.canvas
|
|
|
|
|
|
- if (this._gl.renderbufferStorageMultisample) {
|
|
|
- this._webGLVersion = 2.0;
|
|
|
- }
|
|
|
+ // Context lost
|
|
|
+ if (!this._doNotHandleContextLost) {
|
|
|
+ this._onContextLost = (evt: Event) => {
|
|
|
+ evt.preventDefault();
|
|
|
+ this._contextWasLost = true;
|
|
|
+ Tools.Warn("WebGL context lost.");
|
|
|
|
|
|
- options.stencil = this._gl.getContextAttributes().stencil;
|
|
|
- }
|
|
|
+ this.onContextLostObservable.notifyObservers(this);
|
|
|
+ };
|
|
|
|
|
|
- // Context lost
|
|
|
- if (!this._doNotHandleContextLost) {
|
|
|
- this._onContextLost = (evt: Event) => {
|
|
|
- evt.preventDefault();
|
|
|
- this._contextWasLost = true;
|
|
|
- Tools.Warn("WebGL context lost.");
|
|
|
+ this._onContextRestored = (evt: Event) => {
|
|
|
+ // Rebuild gl context
|
|
|
+ this._initGLContext();
|
|
|
|
|
|
- this.onContextLostObservable.notifyObservers(this);
|
|
|
- };
|
|
|
+ // Rebuild effects
|
|
|
+ this._rebuildEffects();
|
|
|
|
|
|
- this._onContextRestored = (evt: Event) => {
|
|
|
- // Rebuild gl context
|
|
|
- this._initGLContext();
|
|
|
+ // Rebuild textures
|
|
|
+ this._rebuildInternalTextures();
|
|
|
|
|
|
- // Rebuild effects
|
|
|
- this._rebuildEffects();
|
|
|
+ // Rebuild buffers
|
|
|
+ this._rebuildBuffers();
|
|
|
|
|
|
- // Rebuild textures
|
|
|
- this._rebuildInternalTextures();
|
|
|
+ // Cache
|
|
|
+ this.wipeCaches(true);
|
|
|
|
|
|
- // Rebuild buffers
|
|
|
- this._rebuildBuffers();
|
|
|
+ Tools.Warn("WebGL context successfully restored.");
|
|
|
|
|
|
- // Cache
|
|
|
- this.wipeCaches(true);
|
|
|
+ this.onContextRestoredObservable.notifyObservers(this);
|
|
|
|
|
|
- Tools.Warn("WebGL context successfully restored.");
|
|
|
+ this._contextWasLost = false;
|
|
|
+ };
|
|
|
|
|
|
- this.onContextRestoredObservable.notifyObservers(this);
|
|
|
+ canvas.addEventListener("webglcontextlost", this._onContextLost, false);
|
|
|
+ canvas.addEventListener("webglcontextrestored", this._onContextRestored, false);
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ this._gl = <WebGLRenderingContext>canvasOrContext;
|
|
|
+ this._renderingCanvas = this._gl.canvas
|
|
|
|
|
|
- this._contextWasLost = false;
|
|
|
- };
|
|
|
+ if (this._gl.renderbufferStorageMultisample) {
|
|
|
+ this._webGLVersion = 2.0;
|
|
|
+ }
|
|
|
|
|
|
- canvas.addEventListener("webglcontextlost", this._onContextLost, false);
|
|
|
- canvas.addEventListener("webglcontextrestored", this._onContextRestored, false);
|
|
|
+ options.stencil = this._gl.getContextAttributes().stencil;
|
|
|
}
|
|
|
|
|
|
// Viewport
|
|
@@ -1373,7 +1374,7 @@
|
|
|
|
|
|
if (this._activeRenderLoops.length > 0) {
|
|
|
// Register new frame
|
|
|
- Tools.QueueNewFrame(this._bindedRenderFunction, this._vrDisplayEnabled);
|
|
|
+ this._frameHandler = Tools.QueueNewFrame(this._bindedRenderFunction, this._vrDisplayEnabled);
|
|
|
} else {
|
|
|
this._renderingQueueLaunched = false;
|
|
|
}
|
|
@@ -1397,7 +1398,7 @@
|
|
|
if (!this._renderingQueueLaunched) {
|
|
|
this._renderingQueueLaunched = true;
|
|
|
this._bindedRenderFunction = this._renderLoop.bind(this);
|
|
|
- Tools.QueueNewFrame(this._bindedRenderFunction);
|
|
|
+ this._frameHandler = Tools.QueueNewFrame(this._bindedRenderFunction);
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -1620,7 +1621,6 @@
|
|
|
this.setSize(leftEye.renderWidth * 2, leftEye.renderHeight);
|
|
|
} else {
|
|
|
//When the specs are implemented, need to uncomment this.
|
|
|
- //this._vrDisplayEnabled.cancelAnimationFrame(this._vrAnimationFrameHandler);
|
|
|
this.setHardwareScalingLevel(this._oldHardwareScaleFactor);
|
|
|
this.setSize(this._oldSize.width, this._oldSize.height);
|
|
|
this._vrDisplayEnabled = undefined;
|