Explorar el Código

Fixed cache issue with VAO

David Catuhe hace 8 años
padre
commit
e07f5015d5

La diferencia del archivo ha sido suprimido porque es demasiado grande
+ 21 - 21
dist/preview release/babylon.core.js


La diferencia del archivo ha sido suprimido porque es demasiado grande
+ 1202 - 1199
dist/preview release/babylon.d.ts


La diferencia del archivo ha sido suprimido porque es demasiado grande
+ 32 - 32
dist/preview release/babylon.js


+ 30 - 2
dist/preview release/babylon.max.js

@@ -7446,7 +7446,6 @@ var BABYLON;
         Engine.prototype._resetVertexBufferBinding = function () {
             this.bindArrayBuffer(null);
             this._cachedVertexBuffers = null;
-            this._unBindVertexArrayObject();
         };
         Engine.prototype.createVertexBuffer = function (vertices) {
             var vbo = this._gl.createBuffer();
@@ -7526,9 +7525,15 @@ var BABYLON;
             return vbo;
         };
         Engine.prototype.bindArrayBuffer = function (buffer) {
+            if (!this._vaoRecordInProgress) {
+                this._unBindVertexArrayObject();
+            }
             this.bindBuffer(buffer, this._gl.ARRAY_BUFFER);
         };
         Engine.prototype.bindIndexBuffer = function (buffer) {
+            if (!this._vaoRecordInProgress) {
+                this._unBindVertexArrayObject();
+            }
             this.bindBuffer(buffer, this._gl.ELEMENT_ARRAY_BUFFER);
         };
         Engine.prototype.bindBuffer = function (buffer, target) {
@@ -7583,7 +7588,6 @@ var BABYLON;
                 this._cachedIndexBuffer = indexBuffer;
                 this.bindIndexBuffer(indexBuffer);
                 this._uintIndicesCurrentlySet = indexBuffer.is32Bits;
-                this._unBindVertexArrayObject();
             }
         };
         Engine.prototype._bindVertexBuffersAttributes = function (vertexBuffers, effect) {
@@ -7641,6 +7645,7 @@ var BABYLON;
                 this._cachedVertexBuffers = vertexBuffer;
                 this._cachedEffectForVertexBuffers = effect;
                 var attributesCount = effect.getAttributesCount();
+                this._unBindVertexArrayObject();
                 this.unbindAllAttributes();
                 var offset = 0;
                 for (var index = 0; index < attributesCount; index++) {
@@ -8070,6 +8075,8 @@ var BABYLON;
             this._cachedIndexBuffer = null;
             this._cachedEffectForVertexBuffers = null;
             this._unBindVertexArrayObject();
+            this.bindIndexBuffer(null);
+            this.bindArrayBuffer(null);
         };
         Engine.prototype.setSamplingMode = function (texture, samplingMode) {
             var gl = this._gl;
@@ -19962,6 +19969,7 @@ var BABYLON;
          * @param {boolean} doNotCloneChildren When cloning, skip cloning child meshes of source, default False.
          *                  When false, achieved by calling a clone(), also passing False.
          *                  This will make creation of children, recursive.
+         * @param {boolean} clonePhysicsImpostor When cloning, include cloning mesh physics impostor, default True.
          */
         function Mesh(name, scene, parent, source, doNotCloneChildren, clonePhysicsImpostor) {
             if (parent === void 0) { parent = null; }
@@ -19993,7 +20001,11 @@ var BABYLON;
             _this._instancesBufferSize = 32 * 16 * 4; // let's start with a maximum of 32 instances
             _this._sideOrientation = Mesh._DEFAULTSIDE;
             _this._areNormalsFrozen = false; // Will be used by ribbons mainly
+            // Will be used to save a source mesh reference, If any
+            _this._source = null;
             if (source) {
+                // Source mesh
+                _this._source = source;
                 // Geometry
                 if (source._geometry) {
                     source._geometry.applyToMesh(_this);
@@ -20131,6 +20143,13 @@ var BABYLON;
             enumerable: true,
             configurable: true
         });
+        Object.defineProperty(Mesh.prototype, "source", {
+            get: function () {
+                return this._source;
+            },
+            enumerable: true,
+            configurable: true
+        });
         // Methods
         Mesh.prototype.getClassName = function () {
             return "Mesh";
@@ -21128,9 +21147,18 @@ var BABYLON;
          * This also frees the memory allocated under the hood to all the buffers used by WebGL.
          */
         Mesh.prototype.dispose = function (doNotRecurse) {
+            var _this = this;
             if (this._geometry) {
                 this._geometry.releaseForMesh(this, true);
             }
+            // Sources
+            var meshes = this.getScene().meshes;
+            meshes.forEach(function (mesh) {
+                if (mesh._source && mesh._source === _this) {
+                    mesh._source = null;
+                }
+            });
+            this._source = null;
             // Instances
             if (this._instancesBuffer) {
                 this._instancesBuffer.dispose();

La diferencia del archivo ha sido suprimido porque es demasiado grande
+ 32 - 32
dist/preview release/babylon.noworker.js


+ 11 - 4
src/babylon.engine.ts

@@ -1248,7 +1248,6 @@
         private _resetVertexBufferBinding(): void {
             this.bindArrayBuffer(null);
             this._cachedVertexBuffers = null;
-            this._unBindVertexArrayObject();
         }
 
         public createVertexBuffer(vertices: number[] | Float32Array): WebGLBuffer {
@@ -1339,10 +1338,16 @@
         }
 
         public bindArrayBuffer(buffer: WebGLBuffer): void {
+            if (!this._vaoRecordInProgress) {
+                this._unBindVertexArrayObject();
+            }   
             this.bindBuffer(buffer, this._gl.ARRAY_BUFFER);
         }
 
         private bindIndexBuffer(buffer: WebGLBuffer): void {
+            if (!this._vaoRecordInProgress) {
+                this._unBindVertexArrayObject();
+            }            
             this.bindBuffer(buffer, this._gl.ELEMENT_ARRAY_BUFFER);
         }
 
@@ -1384,8 +1389,6 @@
                 this._cachedIndexBuffer = indexBuffer;
                 this.bindIndexBuffer(indexBuffer);
                 this._uintIndicesCurrentlySet = indexBuffer.is32Bits;
-
-                this._unBindVertexArrayObject();
             }
         }
 
@@ -1430,7 +1433,8 @@
         public recordVertexArrayObject(vertexBuffers: { [key: string]: VertexBuffer; }, indexBuffer: WebGLBuffer, effect: Effect): WebGLVertexArrayObject {
             var vao = this._gl.createVertexArray();
 
-            this._vaoRecordInProgress = true;
+            this._vaoRecordInProgress = true;                
+            
             this._gl.bindVertexArray(vao);
             
             this._mustWipeVertexAttributes = true;
@@ -1464,6 +1468,7 @@
 
                 let attributesCount = effect.getAttributesCount();
 
+                this._unBindVertexArrayObject();
                 this.unbindAllAttributes();
 
                 var offset = 0;
@@ -2011,6 +2016,8 @@
             this._cachedIndexBuffer = null;
             this._cachedEffectForVertexBuffers = null;
             this._unBindVertexArrayObject();
+            this.bindIndexBuffer(null);
+            this.bindArrayBuffer(null);
         }
 
         public setSamplingMode(texture: WebGLTexture, samplingMode: number): void {