ソースを参照

Fixed a bug with VertexAttribute caching

David Catuhe 8 年 前
コミット
3474b93782

ファイルの差分が大きいため隠しています
+ 19 - 19
dist/preview release/babylon.core.js


ファイルの差分が大きいため隠しています
+ 4605 - 4626
dist/preview release/babylon.d.ts


ファイルの差分が大きいため隠しています
+ 39 - 39
dist/preview release/babylon.js


+ 142 - 84
dist/preview release/babylon.max.js

@@ -6288,7 +6288,8 @@ var BABYLON;
         });
         texture.onLoadedCallbacks = [];
     };
-    var partialLoad = function (url, index, loadedImages, scene, onfinish) {
+    var partialLoad = function (url, index, loadedImages, scene, onfinish, onErrorCallBack) {
+        if (onErrorCallBack === void 0) { onErrorCallBack = null; }
         var img;
         var onload = function () {
             loadedImages[index] = img;
@@ -6300,15 +6301,19 @@ var BABYLON;
         };
         var onerror = function () {
             scene._removePendingData(img);
+            if (onErrorCallBack) {
+                onErrorCallBack();
+            }
         };
         img = BABYLON.Tools.LoadImage(url, onload, onerror, scene.database);
         scene._addPendingData(img);
     };
-    var cascadeLoad = function (rootUrl, scene, onfinish, files) {
+    var cascadeLoad = function (rootUrl, scene, onfinish, files, onError) {
+        if (onError === void 0) { onError = null; }
         var loadedImages = [];
         loadedImages._internalCount = 0;
         for (var index = 0; index < 6; index++) {
-            partialLoad(files[index], index, loadedImages, scene, onfinish);
+            partialLoad(files[index], index, loadedImages, scene, onfinish, onError);
         }
     };
     var InstancingAttributeInfo = (function () {
@@ -7360,40 +7365,40 @@ var BABYLON;
             }
         };
         Engine.prototype.bindBuffers = function (vertexBuffers, indexBuffer, effect) {
-            if (this._cachedVertexBuffers !== vertexBuffers || this._cachedEffectForVertexBuffers !== effect) {
-                this._cachedVertexBuffers = vertexBuffers;
-                this._cachedEffectForVertexBuffers = effect;
-                var attributes = effect.getAttributesNames();
-                for (var index = 0; index < attributes.length; index++) {
-                    var order = effect.getAttributeLocation(index);
-                    if (order >= 0) {
-                        var vertexBuffer = vertexBuffers[attributes[index]];
-                        if (!vertexBuffer) {
-                            if (this._vertexAttribArraysEnabled[order]) {
-                                this._gl.disableVertexAttribArray(order);
-                                this._vertexAttribArraysEnabled[order] = false;
-                            }
-                            continue;
-                        }
-                        if (!this._vertexAttribArraysEnabled[order]) {
-                            this._gl.enableVertexAttribArray(order);
-                            this._vertexAttribArraysEnabled[order] = true;
-                        }
-                        var buffer = vertexBuffer.getBuffer();
-                        this.vertexAttribPointer(buffer, order, vertexBuffer.getSize(), this._gl.FLOAT, false, vertexBuffer.getStrideSize() * 4, vertexBuffer.getOffset() * 4);
-                        if (vertexBuffer.getIsInstanced()) {
-                            this._caps.instancedArrays.vertexAttribDivisorANGLE(order, 1);
-                            this._currentInstanceLocations.push(order);
-                            this._currentInstanceBuffers.push(buffer);
+            //   if (this._cachedVertexBuffers !== vertexBuffers || this._cachedEffectForVertexBuffers !== effect) {
+            this._cachedVertexBuffers = vertexBuffers;
+            this._cachedEffectForVertexBuffers = effect;
+            var attributes = effect.getAttributesNames();
+            for (var index = 0; index < attributes.length; index++) {
+                var order = effect.getAttributeLocation(index);
+                if (order >= 0) {
+                    var vertexBuffer = vertexBuffers[attributes[index]];
+                    if (!vertexBuffer) {
+                        if (this._vertexAttribArraysEnabled[order]) {
+                            this._gl.disableVertexAttribArray(order);
+                            this._vertexAttribArraysEnabled[order] = false;
                         }
+                        continue;
+                    }
+                    if (!this._vertexAttribArraysEnabled[order]) {
+                        this._gl.enableVertexAttribArray(order);
+                        this._vertexAttribArraysEnabled[order] = true;
+                    }
+                    var buffer = vertexBuffer.getBuffer();
+                    this.vertexAttribPointer(buffer, order, vertexBuffer.getSize(), this._gl.FLOAT, false, vertexBuffer.getStrideSize() * 4, vertexBuffer.getOffset() * 4);
+                    if (vertexBuffer.getIsInstanced()) {
+                        this._caps.instancedArrays.vertexAttribDivisorANGLE(order, 1);
+                        this._currentInstanceLocations.push(order);
+                        this._currentInstanceBuffers.push(buffer);
                     }
                 }
             }
-            if (indexBuffer != null && this._cachedIndexBuffer !== indexBuffer) {
-                this._cachedIndexBuffer = indexBuffer;
-                this.bindIndexBuffer(indexBuffer);
-                this._uintIndicesCurrentlySet = indexBuffer.is32Bits;
-            }
+            //   }
+            // if (indexBuffer != null && this._cachedIndexBuffer !== indexBuffer) {
+            this._cachedIndexBuffer = indexBuffer;
+            this.bindIndexBuffer(indexBuffer);
+            this._uintIndicesCurrentlySet = indexBuffer.is32Bits;
+            //}
         };
         Engine.prototype.unbindInstanceAttributes = function () {
             var boundBuffer;
@@ -7571,12 +7576,12 @@ var BABYLON;
             return results;
         };
         Engine.prototype.enableEffect = function (effect) {
-            if (!effect || !effect.getAttributesCount() || this._currentEffect === effect) {
-                if (effect && effect.onBind) {
-                    effect.onBind(effect);
-                }
-                return;
-            }
+            //if (!effect || !effect.getAttributesCount() || this._currentEffect === effect) {
+            //    if (effect && effect.onBind) {
+            //        effect.onBind(effect);
+            //    }
+            //    return;
+            //}
             // Use program
             this.setProgram(effect.getProgram());
             this._currentEffect = effect;
@@ -8226,8 +8231,10 @@ var BABYLON;
             this._loadedTexturesCache.push(texture);
             return texture;
         };
-        Engine.prototype.createCubeTexture = function (rootUrl, scene, files, noMipmap) {
+        Engine.prototype.createCubeTexture = function (rootUrl, scene, files, noMipmap, onLoad, onError) {
             var _this = this;
+            if (onLoad === void 0) { onLoad = null; }
+            if (onError === void 0) { onError = null; }
             var gl = this._gl;
             var texture = gl.createTexture();
             texture.isCube = true;
@@ -8254,7 +8261,7 @@ var BABYLON;
                     texture._width = info.width;
                     texture._height = info.height;
                     texture.isReady = true;
-                }, null, null, true);
+                }, null, null, true, onError);
             }
             else {
                 cascadeLoad(rootUrl, scene, function (imgs) {
@@ -8285,7 +8292,10 @@ var BABYLON;
                     texture._width = width;
                     texture._height = height;
                     texture.isReady = true;
-                }, files);
+                    if (onLoad) {
+                        onLoad();
+                    }
+                }, files, onError);
             }
             this._loadedTexturesCache.push(texture);
             return texture;
@@ -8638,6 +8648,15 @@ var BABYLON;
                 this._releaseTexture(texture);
             }
         };
+        Engine.prototype.unbindAllAttributes = function () {
+            for (var i = 0, ul = this._vertexAttribArraysEnabled.length; i < ul; i++) {
+                if (i >= this._caps.maxVertexAttribs || !this._vertexAttribArraysEnabled[i]) {
+                    continue;
+                }
+                this._gl.disableVertexAttribArray(i);
+                this._vertexAttribArraysEnabled[i] = false;
+            }
+        };
         // Dispose
         Engine.prototype.dispose = function () {
             this.hideLoadingUI();
@@ -8653,12 +8672,7 @@ var BABYLON;
                 this._gl.deleteProgram(this._compiledEffects[name]._program);
             }
             // Unbind
-            for (var i = 0, ul = this._vertexAttribArraysEnabled.length; i < ul; i++) {
-                if (i >= this._caps.maxVertexAttribs || !this._vertexAttribArraysEnabled[i]) {
-                    continue;
-                }
-                this._gl.disableVertexAttribArray(i);
-            }
+            this.unbindAllAttributes();
             this._gl = null;
             //WebVR
             this.disableVR();
@@ -10994,6 +11008,8 @@ var BABYLON;
             }
             // SubMeshes
             this.releaseSubMeshes();
+            // Engine
+            this.getScene().getEngine().unbindAllAttributes();
             // Remove from scene
             this.getScene().removeMesh(this);
             if (!doNotRecurse) {
@@ -19458,9 +19474,9 @@ var BABYLON;
             if (!this._geometry) {
                 var result = [];
                 if (this._delayInfo) {
-                    for (var kind in this._delayInfo) {
+                    this._delayInfo.forEach(function (kind, index, array) {
                         result.push(kind);
-                    }
+                    });
                 }
                 return result;
             }
@@ -22657,7 +22673,7 @@ var BABYLON;
             if (instance) {
                 path3D = (instance.path3D).update(curve);
                 pathArray = extrusionPathArray(shape, curve, instance.path3D, instance.pathArray, scale, rotation, scaleFunction, rotateFunction, instance.cap, custom);
-                instance = BABYLON.Mesh.CreateRibbon(null, pathArray, null, null, null, null, null, null, instance);
+                instance = BABYLON.Mesh.CreateRibbon(null, pathArray, null, null, null, scene, null, null, instance);
                 return instance;
             }
             // extruded shape creation
@@ -23166,7 +23182,9 @@ var BABYLON;
 (function (BABYLON) {
     var CubeTexture = (function (_super) {
         __extends(CubeTexture, _super);
-        function CubeTexture(rootUrl, scene, extensions, noMipmap, files) {
+        function CubeTexture(rootUrl, scene, extensions, noMipmap, files, onLoad, onError) {
+            if (onLoad === void 0) { onLoad = null; }
+            if (onError === void 0) { onError = null; }
             _super.call(this, scene);
             this.coordinatesMode = BABYLON.Texture.CUBIC_MODE;
             this.name = rootUrl;
@@ -23190,12 +23208,20 @@ var BABYLON;
             this._files = files;
             if (!this._texture) {
                 if (!scene.useDelayedTextureLoading) {
-                    this._texture = scene.getEngine().createCubeTexture(rootUrl, scene, files, noMipmap);
+                    this._texture = scene.getEngine().createCubeTexture(rootUrl, scene, files, noMipmap, onLoad, onError);
                 }
                 else {
                     this.delayLoadState = BABYLON.Engine.DELAYLOADSTATE_NOTLOADED;
                 }
             }
+            else {
+                if (this._texture.isReady) {
+                    BABYLON.Tools.SetImmediate(function () { return onLoad(); });
+                }
+                else {
+                    this._texture.onLoadedCallbacks.push(onLoad);
+                }
+            }
             this.isCube = true;
             this._textureMatrix = BABYLON.Matrix.Identity();
         }
@@ -32808,9 +32834,9 @@ var BABYLON;
                 return;
             }
             var tags = tagsString.split(" ");
-            for (var t in tags) {
-                Tags._AddTagTo(obj, tags[t]);
-            }
+            tags.forEach(function (tag, index, array) {
+                Tags._AddTagTo(obj, tag);
+            });
         };
         Tags._AddTagTo = function (obj, tag) {
             tag = tag.trim();
@@ -32882,44 +32908,46 @@ var BABYLON;
                 var result;
                 var or = parenthesisContent.split("||");
                 for (var i in or) {
-                    var ori = AndOrNotEvaluator._SimplifyNegation(or[i].trim());
-                    var and = ori.split("&&");
-                    if (and.length > 1) {
-                        for (var j = 0; j < and.length; ++j) {
-                            var andj = AndOrNotEvaluator._SimplifyNegation(and[j].trim());
-                            if (andj !== "true" && andj !== "false") {
-                                if (andj[0] === "!") {
-                                    result = !evaluateCallback(andj.substring(1));
+                    if (or.hasOwnProperty(i)) {
+                        var ori = AndOrNotEvaluator._SimplifyNegation(or[i].trim());
+                        var and = ori.split("&&");
+                        if (and.length > 1) {
+                            for (var j = 0; j < and.length; ++j) {
+                                var andj = AndOrNotEvaluator._SimplifyNegation(and[j].trim());
+                                if (andj !== "true" && andj !== "false") {
+                                    if (andj[0] === "!") {
+                                        result = !evaluateCallback(andj.substring(1));
+                                    }
+                                    else {
+                                        result = evaluateCallback(andj);
+                                    }
                                 }
                                 else {
-                                    result = evaluateCallback(andj);
+                                    result = andj === "true" ? true : false;
+                                }
+                                if (!result) {
+                                    ori = "false";
+                                    break;
                                 }
                             }
-                            else {
-                                result = andj === "true" ? true : false;
+                        }
+                        if (result || ori === "true") {
+                            result = true;
+                            break;
+                        }
+                        // result equals false (or undefined)
+                        if (ori !== "true" && ori !== "false") {
+                            if (ori[0] === "!") {
+                                result = !evaluateCallback(ori.substring(1));
                             }
-                            if (!result) {
-                                ori = "false";
-                                break;
+                            else {
+                                result = evaluateCallback(ori);
                             }
                         }
-                    }
-                    if (result || ori === "true") {
-                        result = true;
-                        break;
-                    }
-                    // result equals false (or undefined)
-                    if (ori !== "true" && ori !== "false") {
-                        if (ori[0] === "!") {
-                            result = !evaluateCallback(ori.substring(1));
-                        }
                         else {
-                            result = evaluateCallback(ori);
+                            result = ori === "true" ? true : false;
                         }
                     }
-                    else {
-                        result = ori === "true" ? true : false;
-                    }
                 }
                 // the whole parenthesis scope is replaced by 'true' or 'false'
                 return result ? "true" : "false";
@@ -49487,6 +49515,7 @@ var BABYLON;
                     scale = this._renderingSize.height / this._designSize.height;
                 }
                 this.size = this._designSize.clone();
+                this.actualSize = this._designSize.clone();
                 this.scale = scale;
             }
             var context = new BABYLON.PrepareRender2DContext();
@@ -54033,6 +54062,35 @@ var BABYLON;
         return TextureAssetTask;
     }());
     BABYLON.TextureAssetTask = TextureAssetTask;
+    var CubeTextureAssetTask = (function () {
+        function CubeTextureAssetTask(name, url, extensions, noMipmap, files) {
+            this.name = name;
+            this.url = url;
+            this.extensions = extensions;
+            this.noMipmap = noMipmap;
+            this.files = files;
+            this.isCompleted = false;
+        }
+        CubeTextureAssetTask.prototype.run = function (scene, onSuccess, onError) {
+            var _this = this;
+            var onload = function () {
+                _this.isCompleted = true;
+                if (_this.onSuccess) {
+                    _this.onSuccess(_this);
+                }
+                onSuccess();
+            };
+            var onerror = function () {
+                if (_this.onError) {
+                    _this.onError(_this);
+                }
+                onError();
+            };
+            this.texture = new BABYLON.CubeTexture(this.url, scene, this.extensions, this.noMipmap, this.files, onload, onerror);
+        };
+        return CubeTextureAssetTask;
+    }());
+    BABYLON.CubeTextureAssetTask = CubeTextureAssetTask;
     var AssetsManager = (function () {
         function AssetsManager(scene) {
             this.tasks = new Array();

ファイルの差分が大きいため隠しています
+ 35 - 35
dist/preview release/babylon.noworker.js


+ 1 - 0
src/Canvas2d/babylon.canvas2d.js

@@ -1118,6 +1118,7 @@ var BABYLON;
                     scale = this._renderingSize.height / this._designSize.height;
                 }
                 this.size = this._designSize.clone();
+                this.actualSize = this._designSize.clone();
                 this.scale = scale;
             }
             var context = new BABYLON.PrepareRender2DContext();

+ 12 - 2
src/Materials/Textures/babylon.cubeTexture.js

@@ -7,7 +7,9 @@ var BABYLON;
 (function (BABYLON) {
     var CubeTexture = (function (_super) {
         __extends(CubeTexture, _super);
-        function CubeTexture(rootUrl, scene, extensions, noMipmap, files) {
+        function CubeTexture(rootUrl, scene, extensions, noMipmap, files, onLoad, onError) {
+            if (onLoad === void 0) { onLoad = null; }
+            if (onError === void 0) { onError = null; }
             _super.call(this, scene);
             this.coordinatesMode = BABYLON.Texture.CUBIC_MODE;
             this.name = rootUrl;
@@ -31,12 +33,20 @@ var BABYLON;
             this._files = files;
             if (!this._texture) {
                 if (!scene.useDelayedTextureLoading) {
-                    this._texture = scene.getEngine().createCubeTexture(rootUrl, scene, files, noMipmap);
+                    this._texture = scene.getEngine().createCubeTexture(rootUrl, scene, files, noMipmap, onLoad, onError);
                 }
                 else {
                     this.delayLoadState = BABYLON.Engine.DELAYLOADSTATE_NOTLOADED;
                 }
             }
+            else {
+                if (this._texture.isReady) {
+                    BABYLON.Tools.SetImmediate(function () { return onLoad(); });
+                }
+                else {
+                    this._texture.onLoadedCallbacks.push(onLoad);
+                }
+            }
             this.isCube = true;
             this._textureMatrix = BABYLON.Matrix.Identity();
         }

+ 2 - 0
src/Mesh/babylon.abstractMesh.js

@@ -1013,6 +1013,8 @@ var BABYLON;
             }
             // SubMeshes
             this.releaseSubMeshes();
+            // Engine
+            this.getScene().getEngine().unbindAllAttributes();
             // Remove from scene
             this.getScene().removeMesh(this);
             if (!doNotRecurse) {

+ 3 - 0
src/Mesh/babylon.abstractMesh.ts

@@ -1183,6 +1183,9 @@
             // SubMeshes
             this.releaseSubMeshes();
 
+            // Engine
+            this.getScene().getEngine().unbindAllAttributes();
+
             // Remove from scene
             this.getScene().removeMesh(this);
 

+ 2 - 2
src/Mesh/babylon.mesh.js

@@ -423,9 +423,9 @@ var BABYLON;
             if (!this._geometry) {
                 var result = [];
                 if (this._delayInfo) {
-                    for (var kind in this._delayInfo) {
+                    this._delayInfo.forEach(function (kind, index, array) {
                         result.push(kind);
-                    }
+                    });
                 }
                 return result;
             }

+ 1 - 1
src/Mesh/babylon.meshBuilder.js

@@ -1043,7 +1043,7 @@ var BABYLON;
             if (instance) {
                 path3D = (instance.path3D).update(curve);
                 pathArray = extrusionPathArray(shape, curve, instance.path3D, instance.pathArray, scale, rotation, scaleFunction, rotateFunction, instance.cap, custom);
-                instance = BABYLON.Mesh.CreateRibbon(null, pathArray, null, null, null, null, null, null, instance);
+                instance = BABYLON.Mesh.CreateRibbon(null, pathArray, null, null, null, scene, null, null, instance);
                 return instance;
             }
             // extruded shape creation

+ 30 - 28
src/Tools/babylon.andOrNotEvaluator.js

@@ -31,44 +31,46 @@ var BABYLON;
                 var result;
                 var or = parenthesisContent.split("||");
                 for (var i in or) {
-                    var ori = AndOrNotEvaluator._SimplifyNegation(or[i].trim());
-                    var and = ori.split("&&");
-                    if (and.length > 1) {
-                        for (var j = 0; j < and.length; ++j) {
-                            var andj = AndOrNotEvaluator._SimplifyNegation(and[j].trim());
-                            if (andj !== "true" && andj !== "false") {
-                                if (andj[0] === "!") {
-                                    result = !evaluateCallback(andj.substring(1));
+                    if (or.hasOwnProperty(i)) {
+                        var ori = AndOrNotEvaluator._SimplifyNegation(or[i].trim());
+                        var and = ori.split("&&");
+                        if (and.length > 1) {
+                            for (var j = 0; j < and.length; ++j) {
+                                var andj = AndOrNotEvaluator._SimplifyNegation(and[j].trim());
+                                if (andj !== "true" && andj !== "false") {
+                                    if (andj[0] === "!") {
+                                        result = !evaluateCallback(andj.substring(1));
+                                    }
+                                    else {
+                                        result = evaluateCallback(andj);
+                                    }
                                 }
                                 else {
-                                    result = evaluateCallback(andj);
+                                    result = andj === "true" ? true : false;
+                                }
+                                if (!result) {
+                                    ori = "false";
+                                    break;
                                 }
                             }
-                            else {
-                                result = andj === "true" ? true : false;
+                        }
+                        if (result || ori === "true") {
+                            result = true;
+                            break;
+                        }
+                        // result equals false (or undefined)
+                        if (ori !== "true" && ori !== "false") {
+                            if (ori[0] === "!") {
+                                result = !evaluateCallback(ori.substring(1));
                             }
-                            if (!result) {
-                                ori = "false";
-                                break;
+                            else {
+                                result = evaluateCallback(ori);
                             }
                         }
-                    }
-                    if (result || ori === "true") {
-                        result = true;
-                        break;
-                    }
-                    // result equals false (or undefined)
-                    if (ori !== "true" && ori !== "false") {
-                        if (ori[0] === "!") {
-                            result = !evaluateCallback(ori.substring(1));
-                        }
                         else {
-                            result = evaluateCallback(ori);
+                            result = ori === "true" ? true : false;
                         }
                     }
-                    else {
-                        result = ori === "true" ? true : false;
-                    }
                 }
                 // the whole parenthesis scope is replaced by 'true' or 'false'
                 return result ? "true" : "false";

+ 29 - 0
src/Tools/babylon.assetsManager.js

@@ -138,6 +138,35 @@ var BABYLON;
         return TextureAssetTask;
     }());
     BABYLON.TextureAssetTask = TextureAssetTask;
+    var CubeTextureAssetTask = (function () {
+        function CubeTextureAssetTask(name, url, extensions, noMipmap, files) {
+            this.name = name;
+            this.url = url;
+            this.extensions = extensions;
+            this.noMipmap = noMipmap;
+            this.files = files;
+            this.isCompleted = false;
+        }
+        CubeTextureAssetTask.prototype.run = function (scene, onSuccess, onError) {
+            var _this = this;
+            var onload = function () {
+                _this.isCompleted = true;
+                if (_this.onSuccess) {
+                    _this.onSuccess(_this);
+                }
+                onSuccess();
+            };
+            var onerror = function () {
+                if (_this.onError) {
+                    _this.onError(_this);
+                }
+                onError();
+            };
+            this.texture = new BABYLON.CubeTexture(this.url, scene, this.extensions, this.noMipmap, this.files, onload, onerror);
+        };
+        return CubeTextureAssetTask;
+    }());
+    BABYLON.CubeTextureAssetTask = CubeTextureAssetTask;
     var AssetsManager = (function () {
         function AssetsManager(scene) {
             this.tasks = new Array();

+ 3 - 3
src/Tools/babylon.tags.js

@@ -60,9 +60,9 @@ var BABYLON;
                 return;
             }
             var tags = tagsString.split(" ");
-            for (var t in tags) {
-                Tags._AddTagTo(obj, tags[t]);
-            }
+            tags.forEach(function (tag, index, array) {
+                Tags._AddTagTo(obj, tag);
+            });
         };
         Tags._AddTagTo = function (obj, tag) {
             tag = tag.trim();

+ 62 - 48
src/babylon.engine.js

@@ -82,7 +82,8 @@ var BABYLON;
         });
         texture.onLoadedCallbacks = [];
     };
-    var partialLoad = function (url, index, loadedImages, scene, onfinish) {
+    var partialLoad = function (url, index, loadedImages, scene, onfinish, onErrorCallBack) {
+        if (onErrorCallBack === void 0) { onErrorCallBack = null; }
         var img;
         var onload = function () {
             loadedImages[index] = img;
@@ -94,15 +95,19 @@ var BABYLON;
         };
         var onerror = function () {
             scene._removePendingData(img);
+            if (onErrorCallBack) {
+                onErrorCallBack();
+            }
         };
         img = BABYLON.Tools.LoadImage(url, onload, onerror, scene.database);
         scene._addPendingData(img);
     };
-    var cascadeLoad = function (rootUrl, scene, onfinish, files) {
+    var cascadeLoad = function (rootUrl, scene, onfinish, files, onError) {
+        if (onError === void 0) { onError = null; }
         var loadedImages = [];
         loadedImages._internalCount = 0;
         for (var index = 0; index < 6; index++) {
-            partialLoad(files[index], index, loadedImages, scene, onfinish);
+            partialLoad(files[index], index, loadedImages, scene, onfinish, onError);
         }
     };
     var InstancingAttributeInfo = (function () {
@@ -1154,40 +1159,40 @@ var BABYLON;
             }
         };
         Engine.prototype.bindBuffers = function (vertexBuffers, indexBuffer, effect) {
-            if (this._cachedVertexBuffers !== vertexBuffers || this._cachedEffectForVertexBuffers !== effect) {
-                this._cachedVertexBuffers = vertexBuffers;
-                this._cachedEffectForVertexBuffers = effect;
-                var attributes = effect.getAttributesNames();
-                for (var index = 0; index < attributes.length; index++) {
-                    var order = effect.getAttributeLocation(index);
-                    if (order >= 0) {
-                        var vertexBuffer = vertexBuffers[attributes[index]];
-                        if (!vertexBuffer) {
-                            if (this._vertexAttribArraysEnabled[order]) {
-                                this._gl.disableVertexAttribArray(order);
-                                this._vertexAttribArraysEnabled[order] = false;
-                            }
-                            continue;
-                        }
-                        if (!this._vertexAttribArraysEnabled[order]) {
-                            this._gl.enableVertexAttribArray(order);
-                            this._vertexAttribArraysEnabled[order] = true;
-                        }
-                        var buffer = vertexBuffer.getBuffer();
-                        this.vertexAttribPointer(buffer, order, vertexBuffer.getSize(), this._gl.FLOAT, false, vertexBuffer.getStrideSize() * 4, vertexBuffer.getOffset() * 4);
-                        if (vertexBuffer.getIsInstanced()) {
-                            this._caps.instancedArrays.vertexAttribDivisorANGLE(order, 1);
-                            this._currentInstanceLocations.push(order);
-                            this._currentInstanceBuffers.push(buffer);
+            //   if (this._cachedVertexBuffers !== vertexBuffers || this._cachedEffectForVertexBuffers !== effect) {
+            this._cachedVertexBuffers = vertexBuffers;
+            this._cachedEffectForVertexBuffers = effect;
+            var attributes = effect.getAttributesNames();
+            for (var index = 0; index < attributes.length; index++) {
+                var order = effect.getAttributeLocation(index);
+                if (order >= 0) {
+                    var vertexBuffer = vertexBuffers[attributes[index]];
+                    if (!vertexBuffer) {
+                        if (this._vertexAttribArraysEnabled[order]) {
+                            this._gl.disableVertexAttribArray(order);
+                            this._vertexAttribArraysEnabled[order] = false;
                         }
+                        continue;
+                    }
+                    if (!this._vertexAttribArraysEnabled[order]) {
+                        this._gl.enableVertexAttribArray(order);
+                        this._vertexAttribArraysEnabled[order] = true;
+                    }
+                    var buffer = vertexBuffer.getBuffer();
+                    this.vertexAttribPointer(buffer, order, vertexBuffer.getSize(), this._gl.FLOAT, false, vertexBuffer.getStrideSize() * 4, vertexBuffer.getOffset() * 4);
+                    if (vertexBuffer.getIsInstanced()) {
+                        this._caps.instancedArrays.vertexAttribDivisorANGLE(order, 1);
+                        this._currentInstanceLocations.push(order);
+                        this._currentInstanceBuffers.push(buffer);
                     }
                 }
             }
-            if (indexBuffer != null && this._cachedIndexBuffer !== indexBuffer) {
-                this._cachedIndexBuffer = indexBuffer;
-                this.bindIndexBuffer(indexBuffer);
-                this._uintIndicesCurrentlySet = indexBuffer.is32Bits;
-            }
+            //   }
+            // if (indexBuffer != null && this._cachedIndexBuffer !== indexBuffer) {
+            this._cachedIndexBuffer = indexBuffer;
+            this.bindIndexBuffer(indexBuffer);
+            this._uintIndicesCurrentlySet = indexBuffer.is32Bits;
+            //}
         };
         Engine.prototype.unbindInstanceAttributes = function () {
             var boundBuffer;
@@ -1365,12 +1370,12 @@ var BABYLON;
             return results;
         };
         Engine.prototype.enableEffect = function (effect) {
-            if (!effect || !effect.getAttributesCount() || this._currentEffect === effect) {
-                if (effect && effect.onBind) {
-                    effect.onBind(effect);
-                }
-                return;
-            }
+            //if (!effect || !effect.getAttributesCount() || this._currentEffect === effect) {
+            //    if (effect && effect.onBind) {
+            //        effect.onBind(effect);
+            //    }
+            //    return;
+            //}
             // Use program
             this.setProgram(effect.getProgram());
             this._currentEffect = effect;
@@ -2020,8 +2025,10 @@ var BABYLON;
             this._loadedTexturesCache.push(texture);
             return texture;
         };
-        Engine.prototype.createCubeTexture = function (rootUrl, scene, files, noMipmap) {
+        Engine.prototype.createCubeTexture = function (rootUrl, scene, files, noMipmap, onLoad, onError) {
             var _this = this;
+            if (onLoad === void 0) { onLoad = null; }
+            if (onError === void 0) { onError = null; }
             var gl = this._gl;
             var texture = gl.createTexture();
             texture.isCube = true;
@@ -2048,7 +2055,7 @@ var BABYLON;
                     texture._width = info.width;
                     texture._height = info.height;
                     texture.isReady = true;
-                }, null, null, true);
+                }, null, null, true, onError);
             }
             else {
                 cascadeLoad(rootUrl, scene, function (imgs) {
@@ -2079,7 +2086,10 @@ var BABYLON;
                     texture._width = width;
                     texture._height = height;
                     texture.isReady = true;
-                }, files);
+                    if (onLoad) {
+                        onLoad();
+                    }
+                }, files, onError);
             }
             this._loadedTexturesCache.push(texture);
             return texture;
@@ -2432,6 +2442,15 @@ var BABYLON;
                 this._releaseTexture(texture);
             }
         };
+        Engine.prototype.unbindAllAttributes = function () {
+            for (var i = 0, ul = this._vertexAttribArraysEnabled.length; i < ul; i++) {
+                if (i >= this._caps.maxVertexAttribs || !this._vertexAttribArraysEnabled[i]) {
+                    continue;
+                }
+                this._gl.disableVertexAttribArray(i);
+                this._vertexAttribArraysEnabled[i] = false;
+            }
+        };
         // Dispose
         Engine.prototype.dispose = function () {
             this.hideLoadingUI();
@@ -2447,12 +2466,7 @@ var BABYLON;
                 this._gl.deleteProgram(this._compiledEffects[name]._program);
             }
             // Unbind
-            for (var i = 0, ul = this._vertexAttribArraysEnabled.length; i < ul; i++) {
-                if (i >= this._caps.maxVertexAttribs || !this._vertexAttribArraysEnabled[i]) {
-                    continue;
-                }
-                this._gl.disableVertexAttribArray(i);
-            }
+            this.unbindAllAttributes();
             this._gl = null;
             //WebVR
             this.disableVR();

+ 21 - 16
src/babylon.engine.ts

@@ -1349,7 +1349,7 @@
         }
 
         public bindBuffers(vertexBuffers: { [key: string]: VertexBuffer; }, indexBuffer: WebGLBuffer, effect: Effect): void {
-            if (this._cachedVertexBuffers !== vertexBuffers || this._cachedEffectForVertexBuffers !== effect) {
+         //   if (this._cachedVertexBuffers !== vertexBuffers || this._cachedEffectForVertexBuffers !== effect) {
                 this._cachedVertexBuffers = vertexBuffers;
                 this._cachedEffectForVertexBuffers = effect;
 
@@ -1384,13 +1384,13 @@
                         }
                     }
                 }
-            }
+         //   }
 
-            if (indexBuffer != null && this._cachedIndexBuffer !== indexBuffer) {
+           // if (indexBuffer != null && this._cachedIndexBuffer !== indexBuffer) {
                 this._cachedIndexBuffer = indexBuffer;
                 this.bindIndexBuffer(indexBuffer);
                 this._uintIndicesCurrentlySet = indexBuffer.is32Bits;
-            }
+            //}
         }
 
         public unbindInstanceAttributes() {
@@ -1615,13 +1615,13 @@
         }
 
         public enableEffect(effect: Effect): void {
-            if (!effect || !effect.getAttributesCount() || this._currentEffect === effect) {
+            //if (!effect || !effect.getAttributesCount() || this._currentEffect === effect) {
 
-                if (effect && effect.onBind) {
-                    effect.onBind(effect);
-                }
-                return;
-            }
+            //    if (effect && effect.onBind) {
+            //        effect.onBind(effect);
+            //    }
+            //    return;
+            //}
 
             // Use program
             this.setProgram(effect.getProgram());
@@ -2926,6 +2926,16 @@
             }
         }
 
+        public unbindAllAttributes() {
+            for (var i = 0, ul = this._vertexAttribArraysEnabled.length; i < ul; i++) {
+                if (i >= this._caps.maxVertexAttribs || !this._vertexAttribArraysEnabled[i]) {
+                    continue;
+                }
+                this._gl.disableVertexAttribArray(i);
+                this._vertexAttribArraysEnabled[i] = false;
+            }
+        }
+
         // Dispose
         public dispose(): void {
             this.hideLoadingUI();
@@ -2946,12 +2956,7 @@
             }
 
             // Unbind
-            for (var i = 0, ul = this._vertexAttribArraysEnabled.length; i < ul; i++) {
-                if (i >= this._caps.maxVertexAttribs || !this._vertexAttribArraysEnabled[i]) {
-                    continue;
-                }
-                this._gl.disableVertexAttribArray(i);
-            }
+            this.unbindAllAttributes();
 
             this._gl = null;