Browse Source

dynamic buffer attr : fixed significant update overhead

raub 7 years ago
parent
commit
adc861fd29

+ 8 - 2
examples/webgl_buffergeometry_points_dynamicbufferattribute.html

@@ -124,12 +124,18 @@
 
 				var posAttr = new THREE.DynamicBufferAttribute( gl, pos, gl.FLOAT, 3, particles );
 				geometry.addAttribute( 'position', posAttr );
-				
+
 				setInterval(function () {
 					posAttr.buffer = (posAttr.buffer === pos) ? pos2 : pos;
 					posAttr.needsUpdate = true;
 				}, 2000);
-				
+
+				var drawCount = 0;
+				setInterval(function () {
+					drawCount = 1 + (drawCount + Math.floor(1000 * Math.random())) % particles;
+					geometry.setDrawRange(0, drawCount);
+				}, 20);
+
 				geometry.addAttribute( 'color', new THREE.DynamicBufferAttribute( gl, rgb, gl.FLOAT, 3, particles ) );
 
 				geometry.computeBoundingSphere();

+ 6 - 0
src/renderers/webgl/WebGLAttributes.js

@@ -125,6 +125,12 @@ function WebGLAttributes( gl ) {
 
 		if (attribute.isDynamicBufferAttribute) {
 
+			var cached = buffers[ attribute.uuid ];
+
+			if (cached && cached.version >= attribute.version) {
+				return;
+			}
+
 			buffers[ attribute.uuid ] = {
 				buffer: attribute.buffer,
 				type: attribute.type,