Browse Source

Reset attribute divisor when changing from non-instanced

Ben Adams 10 years ago
parent
commit
45d639856b
2 changed files with 14 additions and 17 deletions
  1. 4 16
      src/renderers/WebGLRenderer.js
  2. 10 1
      src/renderers/webgl/WebGLState.js

+ 4 - 16
src/renderers/WebGLRenderer.js

@@ -910,8 +910,6 @@ THREE.WebGLRenderer = function ( parameters ) {
 
 				if ( geometryAttribute !== undefined ) {
 
-					state.enableAttribute( programAttribute );
-
 					var size = geometryAttribute.itemSize;
 					var buffer = objects.getAttributeBuffer( geometryAttribute );
 
@@ -921,18 +919,13 @@ THREE.WebGLRenderer = function ( parameters ) {
 						var stride = data.stride;
 						var offset = geometryAttribute.offset;
 
+						state.enableAttribute( programAttribute, data.meshPerAttribute, extension );
+
 						_gl.bindBuffer( _gl.ARRAY_BUFFER, buffer );
 						_gl.vertexAttribPointer( programAttribute, size, _gl.FLOAT, false, stride * data.array.BYTES_PER_ELEMENT, ( startIndex * stride + offset ) * data.array.BYTES_PER_ELEMENT );
 
 						if ( data instanceof THREE.InstancedInterleavedBuffer ) {
 
-							if ( extension === null ) {
-
-								console.error( 'THREE.WebGLRenderer.setupVertexAttributes: using THREE.InstancedBufferAttribute but hardware does not support extension ANGLE_instanced_arrays.' );
-								return;
-
-							}
-
 							extension.vertexAttribDivisorANGLE( programAttribute, data.meshPerAttribute );
 
 							if ( geometry.maxInstancedCount === undefined ) {
@@ -945,18 +938,13 @@ THREE.WebGLRenderer = function ( parameters ) {
 
 					} else {
 
+						state.enableAttribute( programAttribute, geometryAttribute.meshPerAttribute, extension );
+
 						_gl.bindBuffer( _gl.ARRAY_BUFFER, buffer );
 						_gl.vertexAttribPointer( programAttribute, size, _gl.FLOAT, false, 0, startIndex * size * 4 ); // 4 bytes per Float32
 
 						if ( geometryAttribute instanceof THREE.InstancedBufferAttribute ) {
 
-							if ( extension === null ) {
-
-								console.error( 'THREE.WebGLRenderer.setupVertexAttributes: using THREE.InstancedBufferAttribute but hardware does not support extension ANGLE_instanced_arrays.' );
-								return;
-
-							}
-
 							extension.vertexAttribDivisorANGLE( programAttribute, geometryAttribute.meshPerAttribute );
 
 							if ( geometry.maxInstancedCount === undefined ) {

+ 10 - 1
src/renderers/webgl/WebGLState.js

@@ -68,7 +68,7 @@ THREE.WebGLState = function ( gl, extensions, paramThreeToGL ) {
 
 	};
 
-	this.enableAttribute = function ( attribute ) {
+	this.enableAttribute = function ( attribute, meshPerAttribute, extension ) {
 
 		newAttributes[ attribute ] = 1;
 
@@ -79,6 +79,15 @@ THREE.WebGLState = function ( gl, extensions, paramThreeToGL ) {
 
 		}
 
+		meshPerAttribute = meshPerAttribute || 0;
+
+		if ( attributeDivisors[ attribute ] !== meshPerAttribute ) {
+
+			extension.vertexAttribDivisorANGLE( attribute, meshPerAttribute );
+			attributeDivisors[ attribute ] !== meshPerAttribute;
+
+		}
+
 	};
 
 	this.disableUnusedAttributes = function () {