Browse Source

Simplify WebGLBindingStates by assuming that the properties related to WebGL resources are read-only

Takahiro 5 years ago
parent
commit
cde3463158

+ 6 - 62
src/core/BufferAttribute.js

@@ -20,79 +20,23 @@ function BufferAttribute( array, itemSize, normalized ) {
 
 	this.name = '';
 
-	this._array = array;
-	this._itemSize = itemSize;
+	this.array = array;
+	this.itemSize = itemSize;
 	this.count = array !== undefined ? array.length / itemSize : 0;
-	this._normalized = normalized === true;
+	this.normalized = normalized === true;
 
 	this.usage = StaticDrawUsage;
 	this.updateRange = { offset: 0, count: - 1 };
 
 	this.version = 0;
-	this.versionVAO = 0;
 
 }
 
-Object.defineProperties( BufferAttribute.prototype, {
+Object.defineProperty( BufferAttribute.prototype, 'needsUpdate', {
 
-	needsUpdate: {
+	set: function ( value ) {
 
-		set: function ( value ) {
-
-			if ( value === true ) this.version ++;
-
-		}
-
-	},
-
-	array: {
-
-		get: function () {
-
-			return this._array;
-
-		},
-
-		set: function ( value ) {
-
-			this._array = value;
-			this.versionVAO ++;
-
-		}
-
-	},
-
-	itemSize: {
-
-		get: function () {
-
-			return this._itemSize;
-
-		},
-
-		set: function ( value ) {
-
-			this._itemSize = value;
-			this.versionVAO ++;
-
-		}
-
-	},
-
-	normalized: {
-
-		get: function () {
-
-			return this._normalized;
-
-		},
-
-		set: function ( value ) {
-
-			this._normalized = value;
-			this.versionVAO ++;
-
-		}
+		if ( value === true ) this.version ++;
 
 	}
 

+ 1 - 22
src/core/InstancedBufferAttribute.js

@@ -18,9 +18,7 @@ function InstancedBufferAttribute( array, itemSize, normalized, meshPerAttribute
 
 	BufferAttribute.call( this, array, itemSize, normalized );
 
-	this._meshPerAttribute = meshPerAttribute || 1;
-
-	this.versionVAO = 0;
+	this.meshPerAttribute = meshPerAttribute || 1;
 
 }
 
@@ -54,25 +52,6 @@ InstancedBufferAttribute.prototype = Object.assign( Object.create( BufferAttribu
 
 } );
 
-Object.defineProperties( InstancedBufferAttribute.prototype, {
-
-	meshPerAttribute: {
-
-		get: function () {
-
-			return this._meshPerAttribute;
-
-		},
-
-		set: function ( value ) {
 
-			this._meshPerAttribute = value;
-			this.versionVAO ++;
-
-		}
-
-	}
-
-} );
 
 export { InstancedBufferAttribute };

+ 1 - 24
src/core/InstancedInterleavedBuffer.js

@@ -8,9 +8,7 @@ function InstancedInterleavedBuffer( array, stride, meshPerAttribute ) {
 
 	InterleavedBuffer.call( this, array, stride );
 
-	this._meshPerAttribute = meshPerAttribute || 1;
-
-	this.versionVAO = 0;
+	this.meshPerAttribute = meshPerAttribute || 1;
 
 }
 
@@ -53,25 +51,4 @@ InstancedInterleavedBuffer.prototype = Object.assign( Object.create( Interleaved
 
 } );
 
-Object.defineProperties( InstancedInterleavedBuffer.prototype, {
-
-	meshPerAttribute: {
-
-		get: function () {
-
-			return this._meshPerAttribute;
-
-		},
-
-		set: function ( value ) {
-
-			this._meshPerAttribute = value;
-			this.versionVAO ++;
-
-		}
-
-	}
-
-} );
-
 export { InstancedInterleavedBuffer };

+ 5 - 44
src/core/InterleavedBuffer.js

@@ -7,63 +7,24 @@ import { StaticDrawUsage } from '../constants.js';
 
 function InterleavedBuffer( array, stride ) {
 
-	this._array = array;
-	this._stride = stride;
+	this.array = array;
+	this.stride = stride;
 	this.count = array !== undefined ? array.length / stride : 0;
 
 	this.usage = StaticDrawUsage;
 	this.updateRange = { offset: 0, count: - 1 };
 
 	this.version = 0;
-	this.versionVAO = 0;
 
 	this.uuid = MathUtils.generateUUID();
 
 }
 
-Object.defineProperties( InterleavedBuffer.prototype, {
+Object.defineProperty( InterleavedBuffer.prototype, 'needsUpdate', {
 
-	needsUpdate: {
+	set: function ( value ) {
 
-		set: function ( value ) {
-
-			if ( value === true ) this.version ++;
-
-		}
-
-	},
-
-	array: {
-
-		get: function () {
-
-			return this._array;
-
-		},
-
-		set: function ( value ) {
-
-			this._array = value;
-			this.versionVAO ++;
-
-		}
-
-	},
-
-	stride: {
-
-		get: function () {
-
-			return this._stride;
-
-		},
-
-		set: function ( value ) {
-
-			this._stride = value;
-			this.versionVAO ++;
-
-		}
+		if ( value === true ) this.version ++;
 
 	}
 

+ 4 - 74
src/core/InterleavedBufferAttribute.js

@@ -11,13 +11,11 @@ function InterleavedBufferAttribute( interleavedBuffer, itemSize, offset, normal
 
 	this.name = '';
 
-	this._data = interleavedBuffer;
-	this._itemSize = itemSize;
-	this._offset = offset;
+	this.data = interleavedBuffer;
+	this.itemSize = itemSize;
+	this.offset = offset;
 
-	this._normalized = normalized === true;
-
-	this.versionVAO = 0;
+	this.normalized = normalized === true;
 
 }
 
@@ -41,74 +39,6 @@ Object.defineProperties( InterleavedBufferAttribute.prototype, {
 
 		}
 
-	},
-
-	data: {
-
-		get: function () {
-
-			return this._data;
-
-		},
-
-		set: function ( value ) {
-
-			this._data = value;
-			this.versionVAO ++;
-
-		}
-
-	},
-
-	itemSize: {
-
-		get: function () {
-
-			return this._itemSize;
-
-		},
-
-		set: function ( value ) {
-
-			this._itemSize = value;
-			this.versionVAO ++;
-
-		}
-
-	},
-
-	offset: {
-
-		get: function () {
-
-			return this._offset;
-
-		},
-
-		set: function ( value ) {
-
-			this._offset = value;
-			this.versionVAO ++;
-
-		}
-
-	},
-
-	normalized: {
-
-		get: function () {
-
-			return this._normalized;
-
-		},
-
-		set: function ( value ) {
-
-			this._normalized = value;
-			this.versionVAO ++;
-
-		}
-
 	}
 
 } );

+ 2 - 11
src/renderers/webgl/WebGLBindingStates.js

@@ -185,12 +185,7 @@ function WebGLBindingStates( gl, extensions, attributes, capabilities ) {
 
 			if ( cachedAttribute.attribute !== geometryAttribute ) return true;
 
-			if ( cachedAttribute.version !== geometryAttribute.versionVAO ) return true;
-
-			if ( cachedAttribute.data.buffer !== geometryAttribute.data ) return true;
-
-			if ( geometryAttribute.data &&
-				cachedAttribute.data.version !== geometryAttribute.data.versionVAO ) return true;
+			if ( cachedAttribute.data !== geometryAttribute.data ) return true;
 
 		}
 
@@ -209,14 +204,10 @@ function WebGLBindingStates( gl, extensions, attributes, capabilities ) {
 
 			const data = {};
 			data.attribute = attribute;
-			data.version = attribute.versionVAO;
-
-			data.data = {};
 
 			if ( attribute.data ) {
 
-				data.data.buffer = attribute.data;
-				data.data.version = attribute.data.versionVAO;
+				data.data = attribute.data;
 
 			}