|
@@ -2579,45 +2579,103 @@ THREE.WebGLRenderer = function ( parameters ) {
|
|
|
|
|
|
// indexed triangles
|
|
|
|
|
|
+ var type, size;
|
|
|
+
|
|
|
+ if ( _glExtensionElementIndexUint !== null && index.array instanceof Uint32Array ) {
|
|
|
+
|
|
|
+ type = _gl.UNSIGNED_INT;
|
|
|
+ size = 4;
|
|
|
+
|
|
|
+ } else {
|
|
|
+
|
|
|
+ type = _gl.UNSIGNED_SHORT;
|
|
|
+ size = 2;
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
if ( index ) {
|
|
|
|
|
|
var offsets = geometry.offsets;
|
|
|
|
|
|
- // if there is more than 1 chunk
|
|
|
- // must set attribute pointers to use new offsets for each chunk
|
|
|
- // even if geometry and materials didn't change
|
|
|
+ if ( offsets.length === 0 ) {
|
|
|
|
|
|
- if ( offsets.length > 1 ) updateBuffers = true;
|
|
|
+ for ( attributeName in programAttributes ) {
|
|
|
|
|
|
- for ( var i = 0, il = offsets.length; i < il; i ++ ) {
|
|
|
+ attributePointer = programAttributes[ attributeName ];
|
|
|
+ attributeItem = geometryAttributes[ attributeName ];
|
|
|
|
|
|
- var startIndex = offsets[ i ].index;
|
|
|
+ if ( attributePointer >= 0 ) {
|
|
|
|
|
|
- if ( updateBuffers ) {
|
|
|
+ if ( attributeItem ) {
|
|
|
+
|
|
|
+ attributeSize = attributeItem.itemSize;
|
|
|
+ _gl.bindBuffer( _gl.ARRAY_BUFFER, attributeItem.buffer );
|
|
|
+ enableAttribute( attributePointer );
|
|
|
+ _gl.vertexAttribPointer( attributePointer, attributeSize, _gl.FLOAT, false, 0, startIndex * attributeSize * 4 ); // 4 bytes per Float32
|
|
|
|
|
|
- for ( attributeName in programAttributes ) {
|
|
|
+ } else if ( material.defaultAttributeValues ) {
|
|
|
|
|
|
- attributePointer = programAttributes[ attributeName ];
|
|
|
- attributeItem = geometryAttributes[ attributeName ];
|
|
|
+ if ( material.defaultAttributeValues[ attributeName ].length === 2 ) {
|
|
|
|
|
|
- if ( attributePointer >= 0 ) {
|
|
|
+ _gl.vertexAttrib2fv( attributePointer, material.defaultAttributeValues[ attributeName ] );
|
|
|
|
|
|
- if ( attributeItem ) {
|
|
|
+ } else if ( material.defaultAttributeValues[ attributeName ].length === 3 ) {
|
|
|
|
|
|
- attributeSize = attributeItem.itemSize;
|
|
|
- _gl.bindBuffer( _gl.ARRAY_BUFFER, attributeItem.buffer );
|
|
|
- enableAttribute( attributePointer );
|
|
|
- _gl.vertexAttribPointer( attributePointer, attributeSize, _gl.FLOAT, false, 0, startIndex * attributeSize * 4 ); // 4 bytes per Float32
|
|
|
+ _gl.vertexAttrib3fv( attributePointer, material.defaultAttributeValues[ attributeName ] );
|
|
|
|
|
|
- } else if ( material.defaultAttributeValues ) {
|
|
|
+ }
|
|
|
|
|
|
- if ( material.defaultAttributeValues[ attributeName ].length === 2 ) {
|
|
|
+ }
|
|
|
|
|
|
- _gl.vertexAttrib2fv( attributePointer, material.defaultAttributeValues[ attributeName ] );
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ _gl.drawElements( _gl.TRIANGLES, index.array.length, type, 0 );
|
|
|
+
|
|
|
+ _this.info.render.calls ++;
|
|
|
+ _this.info.render.vertices += index.array.length; // not really true, here vertices can be shared
|
|
|
+ _this.info.render.faces += index.array.length / 3;
|
|
|
+
|
|
|
+ } else {
|
|
|
|
|
|
- } else if ( material.defaultAttributeValues[ attributeName ].length === 3 ) {
|
|
|
+ // if there is more than 1 chunk
|
|
|
+ // must set attribute pointers to use new offsets for each chunk
|
|
|
+ // even if geometry and materials didn't change
|
|
|
|
|
|
- _gl.vertexAttrib3fv( attributePointer, material.defaultAttributeValues[ attributeName ] );
|
|
|
+ updateBuffers = true;
|
|
|
+
|
|
|
+ for ( var i = 0, il = offsets.length; i < il; i ++ ) {
|
|
|
+
|
|
|
+ var startIndex = offsets[ i ].index;
|
|
|
+
|
|
|
+ if ( updateBuffers ) {
|
|
|
+
|
|
|
+ for ( attributeName in programAttributes ) {
|
|
|
+
|
|
|
+ attributePointer = programAttributes[ attributeName ];
|
|
|
+ attributeItem = geometryAttributes[ attributeName ];
|
|
|
+
|
|
|
+ if ( attributePointer >= 0 ) {
|
|
|
+
|
|
|
+ if ( attributeItem ) {
|
|
|
+
|
|
|
+ attributeSize = attributeItem.itemSize;
|
|
|
+ _gl.bindBuffer( _gl.ARRAY_BUFFER, attributeItem.buffer );
|
|
|
+ enableAttribute( attributePointer );
|
|
|
+ _gl.vertexAttribPointer( attributePointer, attributeSize, _gl.FLOAT, false, 0, startIndex * attributeSize * 4 ); // 4 bytes per Float32
|
|
|
+
|
|
|
+ } else if ( material.defaultAttributeValues ) {
|
|
|
+
|
|
|
+ if ( material.defaultAttributeValues[ attributeName ].length === 2 ) {
|
|
|
+
|
|
|
+ _gl.vertexAttrib2fv( attributePointer, material.defaultAttributeValues[ attributeName ] );
|
|
|
+
|
|
|
+ } else if ( material.defaultAttributeValues[ attributeName ].length === 3 ) {
|
|
|
+
|
|
|
+ _gl.vertexAttrib3fv( attributePointer, material.defaultAttributeValues[ attributeName ] );
|
|
|
+
|
|
|
+ }
|
|
|
|
|
|
}
|
|
|
|
|
@@ -2625,33 +2683,21 @@ THREE.WebGLRenderer = function ( parameters ) {
|
|
|
|
|
|
}
|
|
|
|
|
|
+ // indices
|
|
|
+
|
|
|
+ _gl.bindBuffer( _gl.ELEMENT_ARRAY_BUFFER, index.buffer );
|
|
|
+
|
|
|
}
|
|
|
|
|
|
- // indices
|
|
|
+ // render indexed triangles
|
|
|
|
|
|
- _gl.bindBuffer( _gl.ELEMENT_ARRAY_BUFFER, index.buffer );
|
|
|
+ _gl.drawElements( _gl.TRIANGLES, offsets[ i ].count, type, offsets[ i ].start * size );
|
|
|
|
|
|
- }
|
|
|
+ _this.info.render.calls ++;
|
|
|
+ _this.info.render.vertices += offsets[ i ].count; // not really true, here vertices can be shared
|
|
|
+ _this.info.render.faces += offsets[ i ].count / 3;
|
|
|
|
|
|
- // render indexed triangles
|
|
|
- var type, size;
|
|
|
-
|
|
|
- if ( _glExtensionElementIndexUint !== null && index.array instanceof Uint32Array ) {
|
|
|
-
|
|
|
- type = _gl.UNSIGNED_INT;
|
|
|
- size = 4;
|
|
|
-
|
|
|
- } else {
|
|
|
-
|
|
|
- type = _gl.UNSIGNED_SHORT;
|
|
|
- size = 2;
|
|
|
-
|
|
|
}
|
|
|
- _gl.drawElements( _gl.TRIANGLES, offsets[ i ].count, type, offsets[ i ].start * size ); // 2 bytes per Uint16
|
|
|
-
|
|
|
- _this.info.render.calls ++;
|
|
|
- _this.info.render.vertices += offsets[ i ].count; // not really true, here vertices can be shared
|
|
|
- _this.info.render.faces += offsets[ i ].count / 3;
|
|
|
|
|
|
}
|
|
|
|