|
@@ -4,6 +4,7 @@ var BABYLON = BABYLON || {};
|
|
|
|
|
|
(function () {
|
|
(function () {
|
|
BABYLON.Engine = function (canvas, antialias, options) {
|
|
BABYLON.Engine = function (canvas, antialias, options) {
|
|
|
|
+ var that = this;
|
|
this._renderingCanvas = canvas;
|
|
this._renderingCanvas = canvas;
|
|
|
|
|
|
options = options || {};
|
|
options = options || {};
|
|
@@ -20,9 +21,26 @@ var BABYLON = BABYLON || {};
|
|
throw new Error("WebGL not supported");
|
|
throw new Error("WebGL not supported");
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ this._windowIsBackground = false;
|
|
|
|
+ window.addEventListener("blur", function () {
|
|
|
|
+ that._windowIsBackground = true;
|
|
|
|
+ });
|
|
|
|
+
|
|
|
|
+ window.addEventListener("focus", function () {
|
|
|
|
+ that._windowIsBackground = false;
|
|
|
|
+
|
|
|
|
+ if (that._runningLoop) {
|
|
|
|
+ // Register new frame
|
|
|
|
+ BABYLON.Tools.QueueNewFrame(function () {
|
|
|
|
+ that._renderLoop();
|
|
|
|
+ });
|
|
|
|
+ }
|
|
|
|
+ });
|
|
|
|
+
|
|
// Options
|
|
// Options
|
|
this.forceWireframe = false;
|
|
this.forceWireframe = false;
|
|
this.cullBackFaces = true;
|
|
this.cullBackFaces = true;
|
|
|
|
+ this.renderEvenInBackground = true;
|
|
|
|
|
|
// Scenes
|
|
// Scenes
|
|
this.scenes = [];
|
|
this.scenes = [];
|
|
@@ -64,7 +82,6 @@ var BABYLON = BABYLON || {};
|
|
|
|
|
|
// Fullscreen
|
|
// Fullscreen
|
|
this.isFullscreen = false;
|
|
this.isFullscreen = false;
|
|
- var that = this;
|
|
|
|
|
|
|
|
var onFullscreenChange = function () {
|
|
var onFullscreenChange = function () {
|
|
if (document.fullscreen !== undefined) {
|
|
if (document.fullscreen !== undefined) {
|
|
@@ -154,6 +171,10 @@ var BABYLON = BABYLON || {};
|
|
};
|
|
};
|
|
|
|
|
|
BABYLON.Engine.prototype._renderLoop = function () {
|
|
BABYLON.Engine.prototype._renderLoop = function () {
|
|
|
|
+ if (!this.renderEvenInBackground && this._windowIsBackground) {
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+
|
|
// Start new frame
|
|
// Start new frame
|
|
this.beginFrame();
|
|
this.beginFrame();
|
|
|
|
|