Browse Source

WebGLRenderer: Removed Object.keys() micro-optimizations for now.

Mr.doob 10 years ago
parent
commit
1ee4b5fc8e

+ 1 - 3
src/core/BufferGeometry.js

@@ -12,8 +12,7 @@ THREE.BufferGeometry = function () {
 	this.name = '';
 	this.type = 'BufferGeometry';
 
-	this.attributes = {}; // TODO: Change to Array and remove attributeKeys?
-	this.attributesKeys = [];
+	this.attributes = {};
 
 	this.morphAttributes = [];
 
@@ -42,7 +41,6 @@ THREE.BufferGeometry.prototype = {
 		}
 
 		this.attributes[ name ] = attribute;
-		this.attributesKeys = Object.keys( this.attributes );
 
 	},
 

+ 8 - 11
src/renderers/WebGLRenderer.js

@@ -889,18 +889,15 @@ THREE.WebGLRenderer = function ( parameters ) {
 		}
 
 		var geometryAttributes = geometry.attributes;
-
 		var programAttributes = program.attributes;
-		var programAttributesKeys = program.attributesKeys;
 
-		for ( var i = 0, l = programAttributesKeys.length; i < l; i ++ ) {
+		for ( var name in programAttributes ) {
 
-			var key = programAttributesKeys[ i ];
-			var programAttribute = programAttributes[ key ];
+			var programAttribute = programAttributes[ name ];
 
 			if ( programAttribute >= 0 ) {
 
-				var geometryAttribute = geometryAttributes[ key ];
+				var geometryAttribute = geometryAttributes[ name ];
 
 				if ( geometryAttribute !== undefined ) {
 
@@ -963,15 +960,15 @@ THREE.WebGLRenderer = function ( parameters ) {
 
 				} else if ( material.defaultAttributeValues !== undefined ) {
 
-					if ( material.defaultAttributeValues[ key ] !== undefined ) {
+					if ( material.defaultAttributeValues[ name ] !== undefined ) {
 
-						if ( material.defaultAttributeValues[ key ].length === 2 ) {
+						if ( material.defaultAttributeValues[ name ].length === 2 ) {
 
-							_gl.vertexAttrib2fv( programAttribute, material.defaultAttributeValues[ key ] );
+							_gl.vertexAttrib2fv( programAttribute, material.defaultAttributeValues[ name ] );
 
-						} else if ( material.defaultAttributeValues[ key ].length === 3 ) {
+						} else if ( material.defaultAttributeValues[ name ].length === 3 ) {
 
-							_gl.vertexAttrib3fv( programAttribute, material.defaultAttributeValues[ key ] );
+							_gl.vertexAttrib3fv( programAttribute, material.defaultAttributeValues[ name ] );
 
 						}
 

+ 3 - 5
src/renderers/webgl/WebGLObjects.js

@@ -179,14 +179,12 @@ THREE.WebGLObjects = function ( gl, info ) {
 		if ( geometry instanceof THREE.BufferGeometry ) {
 
 			var attributes = geometry.attributes;
-			var attributesKeys = geometry.attributesKeys;
 
-			for ( var i = 0, l = attributesKeys.length; i < l; i ++ ) {
+			for ( var name in attributes ) {
 
-				var key = attributesKeys[ i ];
-				var attribute = attributes[ key ];
+				var attribute = attributes[ name ];
 
-				var bufferType = ( key === 'index' ) ? gl.ELEMENT_ARRAY_BUFFER : gl.ARRAY_BUFFER;
+				var bufferType = ( name === 'index' ) ? gl.ELEMENT_ARRAY_BUFFER : gl.ARRAY_BUFFER;
 
 				var data = ( attribute instanceof THREE.InterleavedBufferAttribute ) ? attribute.data : attribute;
 

+ 0 - 1
src/renderers/webgl/WebGLProgram.js

@@ -460,7 +460,6 @@ THREE.WebGLProgram = ( function () {
 		}
 
 		this.attributes = cacheAttributeLocations( gl, program, identifiers );
-		this.attributesKeys = Object.keys( this.attributes );
 
 		//