diff --git a/src/core/BufferAttribute.js b/src/core/BufferAttribute.js index 49cd1bf05fff805f5e5d8eb835c5ece926277996..b3d3502af9e293fd1d0476a10245787391ba5364 100644 --- a/src/core/BufferAttribute.js +++ b/src/core/BufferAttribute.js @@ -9,7 +9,8 @@ THREE.BufferAttribute = function ( array, itemSize ) { this.array = array; this.itemSize = itemSize; - this.needsUpdate = false; + this._needsUpdate = false; + this.updateCounter = 0; }; @@ -30,6 +31,20 @@ THREE.BufferAttribute.prototype = { }, + get needsUpdate() { + + return this._needsUpdate; + + }, + + set needsUpdate( value ) { + + if ( value === true ) this.updateCounter ++; + + this._needsUpdate = value; + + }, + copyAt: function ( index1, attribute, index2 ) { index1 *= this.itemSize; diff --git a/src/core/InterleavedBuffer.js b/src/core/InterleavedBuffer.js index 79bf8ef0c5f22c1cd5d97bd27e7660c6ae4e2a10..7e8aec63f1afc11eab3f3be1e35b51f088e9b438 100644 --- a/src/core/InterleavedBuffer.js +++ b/src/core/InterleavedBuffer.js @@ -9,7 +9,8 @@ THREE.InterleavedBuffer = function ( array, stride, dynamic ) { this.array = array; this.stride = stride; - this.needsUpdate = false; + this._needsUpdate = false; + this.updateCounter = 0; this.dynamic = dynamic || false; this.updateRange = { offset: 0, count: -1 }; @@ -32,6 +33,20 @@ THREE.InterleavedBuffer.prototype = { }, + get needsUpdate() { + + return this._needsUpdate; + + }, + + set needsUpdate( value ) { + + if ( value === true ) this.updateCounter ++; + + this._needsUpdate = value; + + }, + copyAt: function ( index1, attribute, index2 ) { index1 *= this.stride; diff --git a/src/renderers/webgl/WebGLObjects.js b/src/renderers/webgl/WebGLObjects.js index 1b9258795c4c778a4bd96c7e39f2017764b285c1..ce4f1c48934d6fb2ddf064ead9fa1e7bc293423e 100644 --- a/src/renderers/webgl/WebGLObjects.js +++ b/src/renderers/webgl/WebGLObjects.js @@ -185,7 +185,7 @@ THREE.WebGLObjects = function ( gl, properties, info ) { createBuffer( attributeProperties, data, bufferType ); - } else if ( data.needsUpdate === true ) { + } else if ( attributeProperties.updateCounter !== data.updateCounter ) { updateBuffer( attributeProperties, data, bufferType ); @@ -210,11 +210,12 @@ THREE.WebGLObjects = function ( gl, properties, info ) { gl.bufferData( bufferType, data.array, usage ); + attributeProperties.updateCounter = data.updateCounter; data.needsUpdate = false; } - function updateBuffer( attributeProperties, data, bufferType ) { + function updateBuffer ( attributeProperties, data, bufferType ) { gl.bindBuffer( bufferType, attributeProperties.__webglBuffer ); @@ -235,6 +236,7 @@ THREE.WebGLObjects = function ( gl, properties, info ) { } + attributeProperties.updateCounter = data.updateCounter; data.needsUpdate = false; }