From 9af4f0b1ef13a5b949518ed6c52ade59ab8df9e6 Mon Sep 17 00:00:00 2001 From: dubejf Date: Sun, 12 Jul 2015 14:00:45 -0400 Subject: [PATCH] Implement and use update counter --- src/core/BufferAttribute.js | 17 ++++++++++++++++- src/core/InterleavedBuffer.js | 17 ++++++++++++++++- src/renderers/webgl/WebGLObjects.js | 6 ++++-- 3 files changed, 36 insertions(+), 4 deletions(-) diff --git a/src/core/BufferAttribute.js b/src/core/BufferAttribute.js index 49cd1bf05f..b3d3502af9 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 79bf8ef0c5..7e8aec63f1 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 1b9258795c..ce4f1c4893 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; } -- GitLab