2
0
Эх сурвалжийг харах

Implement and use update counter

dubejf 10 жил өмнө
parent
commit
9af4f0b1ef

+ 16 - 1
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;

+ 16 - 1
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;

+ 4 - 2
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;
 
 	}