|
@@ -847,17 +847,37 @@ THREE.WebGLRenderer = function ( parameters ) {
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
- if ( object instanceof THREE.Mesh ) {
|
|
|
|
|
|
+ if ( geometry.attributes.index !== undefined ) {
|
|
|
|
|
|
- renderMesh( material, geometry, program, updateBuffers );
|
|
|
|
|
|
+ if ( object instanceof THREE.Mesh ) {
|
|
|
|
|
|
- } else if ( object instanceof THREE.Line ) {
|
|
|
|
|
|
+ renderIndexedMesh( material, geometry, program, updateBuffers );
|
|
|
|
|
|
- renderLine( material, geometry, object, program, updateBuffers );
|
|
|
|
|
|
+ } else if ( object instanceof THREE.Line ) {
|
|
|
|
|
|
- } else if ( object instanceof THREE.PointCloud ) {
|
|
|
|
|
|
+ renderIndexedLine( material, geometry, object, program, updateBuffers );
|
|
|
|
|
|
- renderPointCloud( material, geometry, program, updateBuffers );
|
|
|
|
|
|
+ } else if ( object instanceof THREE.PointCloud ) {
|
|
|
|
+
|
|
|
|
+ renderIndexedPointCloud( material, geometry, program, updateBuffers );
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ } else {
|
|
|
|
+
|
|
|
|
+ if ( object instanceof THREE.Mesh ) {
|
|
|
|
+
|
|
|
|
+ renderMesh( material, geometry, program, updateBuffers );
|
|
|
|
+
|
|
|
|
+ } else if ( object instanceof THREE.Line ) {
|
|
|
|
+
|
|
|
|
+ renderLine( material, geometry, object, program, updateBuffers );
|
|
|
|
+
|
|
|
|
+ } else if ( object instanceof THREE.PointCloud ) {
|
|
|
|
+
|
|
|
|
+ renderPointCloud( material, geometry, program, updateBuffers );
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
@@ -994,7 +1014,7 @@ THREE.WebGLRenderer = function ( parameters ) {
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
- function renderMesh( material, geometry, program, updateBuffers ) {
|
|
|
|
|
|
+ function renderIndexedMesh( material, geometry, program, updateBuffers ) {
|
|
|
|
|
|
var mode = _gl.TRIANGLES;
|
|
var mode = _gl.TRIANGLES;
|
|
|
|
|
|
@@ -1003,53 +1023,80 @@ THREE.WebGLRenderer = function ( parameters ) {
|
|
mode = _gl.LINES;
|
|
mode = _gl.LINES;
|
|
state.setLineWidth( material.wireframeLinewidth * pixelRatio );
|
|
state.setLineWidth( material.wireframeLinewidth * pixelRatio );
|
|
|
|
|
|
- /*
|
|
|
|
- if ( geometry._wireframe === undefined ) {
|
|
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ var index = geometry.attributes.index;
|
|
|
|
+ var indexBuffer = objects.getAttributeBuffer( index );
|
|
|
|
|
|
- geometry._wireframe = new THREE.WireframeGeometry( geometry );
|
|
|
|
- objects.updateAttribute( geometry._wireframe.attributes.position );
|
|
|
|
|
|
+ var type, size;
|
|
|
|
|
|
- }
|
|
|
|
|
|
+ if ( index.array instanceof Uint32Array && extensions.get( 'OES_element_index_uint' ) ) {
|
|
|
|
|
|
- geometry = geometry._wireframe;
|
|
|
|
- */
|
|
|
|
|
|
+ type = _gl.UNSIGNED_INT;
|
|
|
|
+ size = 4;
|
|
|
|
+
|
|
|
|
+ } else {
|
|
|
|
+
|
|
|
|
+ type = _gl.UNSIGNED_SHORT;
|
|
|
|
+ size = 2;
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
- var index = geometry.attributes.index;
|
|
|
|
|
|
+ var drawcall = geometry.drawcalls;
|
|
|
|
+
|
|
|
|
+ if ( drawcall.length === 0 ) {
|
|
|
|
+
|
|
|
|
+ if ( updateBuffers ) {
|
|
|
|
+
|
|
|
|
+ setupVertexAttributes( material, program, geometry, 0 );
|
|
|
|
+ _gl.bindBuffer( _gl.ELEMENT_ARRAY_BUFFER, indexBuffer );
|
|
|
|
|
|
- if ( index ) {
|
|
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if ( geometry instanceof THREE.InstancedBufferGeometry && geometry.maxInstancedCount > 0 ) {
|
|
|
|
|
|
- // indexed triangles
|
|
|
|
|
|
+ var extension = extensions.get( 'ANGLE_instanced_arrays' );
|
|
|
|
|
|
- var type, size;
|
|
|
|
|
|
+ if ( extension === null ) {
|
|
|
|
|
|
- var indexBuffer = objects.getAttributeBuffer( index );
|
|
|
|
|
|
+ console.error( 'THREE.WebGLRenderer.renderMesh: using THREE.InstancedBufferGeometry but hardware does not support extension ANGLE_instanced_arrays.' );
|
|
|
|
+ return;
|
|
|
|
|
|
- if ( index.array instanceof Uint32Array && extensions.get( 'OES_element_index_uint' ) ) {
|
|
|
|
|
|
+ }
|
|
|
|
|
|
- type = _gl.UNSIGNED_INT;
|
|
|
|
- size = 4;
|
|
|
|
|
|
+ extension.drawElementsInstancedANGLE( mode, index.array.length, type, 0, geometry.maxInstancedCount ); // Draw the instanced meshes
|
|
|
|
|
|
} else {
|
|
} else {
|
|
|
|
|
|
- type = _gl.UNSIGNED_SHORT;
|
|
|
|
- size = 2;
|
|
|
|
|
|
+ _gl.drawElements( mode, index.array.length, type, 0 );
|
|
|
|
|
|
}
|
|
}
|
|
|
|
+ _infoRender.calls ++;
|
|
|
|
+ _infoRender.vertices += index.array.length; // not really true, here vertices can be shared
|
|
|
|
+ _infoRender.faces += index.array.length / 3;
|
|
|
|
+
|
|
|
|
+ } else {
|
|
|
|
+
|
|
|
|
+ // if there is more than 1 chunk
|
|
|
|
+ // must set attribute pointers to use new drawcall for each chunk
|
|
|
|
+ // even if geometry and materials didn't change
|
|
|
|
+
|
|
|
|
+ updateBuffers = true;
|
|
|
|
|
|
- var drawcall = geometry.drawcalls;
|
|
|
|
|
|
+ for ( var i = 0, il = drawcall.length; i < il; i ++ ) {
|
|
|
|
|
|
- if ( drawcall.length === 0 ) {
|
|
|
|
|
|
+ var startIndex = drawcall[ i ].index;
|
|
|
|
|
|
if ( updateBuffers ) {
|
|
if ( updateBuffers ) {
|
|
|
|
|
|
- setupVertexAttributes( material, program, geometry, 0 );
|
|
|
|
|
|
+ setupVertexAttributes( material, program, geometry, startIndex );
|
|
_gl.bindBuffer( _gl.ELEMENT_ARRAY_BUFFER, indexBuffer );
|
|
_gl.bindBuffer( _gl.ELEMENT_ARRAY_BUFFER, indexBuffer );
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
- if ( geometry instanceof THREE.InstancedBufferGeometry && geometry.maxInstancedCount > 0 ) {
|
|
|
|
|
|
+ // render indexed triangles
|
|
|
|
+
|
|
|
|
+ if ( geometry instanceof THREE.InstancedBufferGeometry && drawcall[ i ].instances > 0 ) {
|
|
|
|
|
|
var extension = extensions.get( 'ANGLE_instanced_arrays' );
|
|
var extension = extensions.get( 'ANGLE_instanced_arrays' );
|
|
|
|
|
|
@@ -1060,144 +1107,110 @@ THREE.WebGLRenderer = function ( parameters ) {
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
- extension.drawElementsInstancedANGLE( mode, index.array.length, type, 0, geometry.maxInstancedCount ); // Draw the instanced meshes
|
|
|
|
|
|
+ extension.drawElementsInstancedANGLE( mode, drawcall[ i ].count, type, drawcall[ i ].start * size, drawcall[ i ].count, type, drawcall[ i ].instances ); // Draw the instanced meshes
|
|
|
|
|
|
} else {
|
|
} else {
|
|
|
|
|
|
- _gl.drawElements( mode, index.array.length, type, 0 );
|
|
|
|
|
|
+ _gl.drawElements( mode, drawcall[ i ].count, type, drawcall[ i ].start * size );
|
|
|
|
|
|
}
|
|
}
|
|
- _infoRender.calls ++;
|
|
|
|
- _infoRender.vertices += index.array.length; // not really true, here vertices can be shared
|
|
|
|
- _infoRender.faces += index.array.length / 3;
|
|
|
|
|
|
|
|
- } else {
|
|
|
|
|
|
+ _infoRender.calls ++;
|
|
|
|
+ _infoRender.vertices += drawcall[ i ].count; // not really true, here vertices can be shared
|
|
|
|
+ _infoRender.faces += drawcall[ i ].count / 3;
|
|
|
|
|
|
- // if there is more than 1 chunk
|
|
|
|
- // must set attribute pointers to use new drawcall for each chunk
|
|
|
|
- // even if geometry and materials didn't change
|
|
|
|
|
|
+ }
|
|
|
|
|
|
- updateBuffers = true;
|
|
|
|
|
|
+ }
|
|
|
|
|
|
- for ( var i = 0, il = drawcall.length; i < il; i ++ ) {
|
|
|
|
|
|
+ }
|
|
|
|
|
|
- var startIndex = drawcall[ i ].index;
|
|
|
|
|
|
+ function renderMesh( material, geometry, program, updateBuffers ) {
|
|
|
|
|
|
- if ( updateBuffers ) {
|
|
|
|
|
|
+ var mode = _gl.TRIANGLES;
|
|
|
|
|
|
- setupVertexAttributes( material, program, geometry, startIndex );
|
|
|
|
- _gl.bindBuffer( _gl.ELEMENT_ARRAY_BUFFER, indexBuffer );
|
|
|
|
|
|
+ if ( material.wireframe === true ) {
|
|
|
|
|
|
- }
|
|
|
|
|
|
+ mode = _gl.LINES;
|
|
|
|
+ state.setLineWidth( material.wireframeLinewidth * pixelRatio );
|
|
|
|
|
|
- // render indexed triangles
|
|
|
|
|
|
+ }
|
|
|
|
|
|
- if ( geometry instanceof THREE.InstancedBufferGeometry && drawcall[ i ].instances > 0 ) {
|
|
|
|
|
|
+ if ( updateBuffers ) {
|
|
|
|
|
|
- var extension = extensions.get( 'ANGLE_instanced_arrays' );
|
|
|
|
|
|
+ setupVertexAttributes( material, program, geometry, 0 );
|
|
|
|
|
|
- if ( extension === null ) {
|
|
|
|
|
|
+ }
|
|
|
|
|
|
- console.error( 'THREE.WebGLRenderer.renderMesh: using THREE.InstancedBufferGeometry but hardware does not support extension ANGLE_instanced_arrays.' );
|
|
|
|
- return;
|
|
|
|
|
|
+ // non-indexed triangles
|
|
|
|
|
|
- }
|
|
|
|
|
|
+ var drawcall = geometry.drawcalls;
|
|
|
|
|
|
- extension.drawElementsInstancedANGLE( mode, drawcall[ i ].count, type, drawcall[ i ].start * size, drawcall[ i ].count, type, drawcall[ i ].instances ); // Draw the instanced meshes
|
|
|
|
|
|
+ if ( drawcall.length === 0 ) {
|
|
|
|
|
|
- } else {
|
|
|
|
|
|
+ var position = geometry.attributes.position;
|
|
|
|
|
|
- _gl.drawElements( mode, drawcall[ i ].count, type, drawcall[ i ].start * size );
|
|
|
|
|
|
+ // render non-indexed triangles
|
|
|
|
|
|
- }
|
|
|
|
|
|
+ if ( geometry instanceof THREE.InstancedBufferGeometry && geometry.maxInstancedCount > 0 ) {
|
|
|
|
|
|
- _infoRender.calls ++;
|
|
|
|
- _infoRender.vertices += drawcall[ i ].count; // not really true, here vertices can be shared
|
|
|
|
- _infoRender.faces += drawcall[ i ].count / 3;
|
|
|
|
|
|
+ var extension = extensions.get( 'ANGLE_instanced_arrays' );
|
|
|
|
|
|
- }
|
|
|
|
|
|
+ if ( extension === null ) {
|
|
|
|
|
|
- }
|
|
|
|
|
|
+ console.error( 'THREE.WebGLRenderer.renderMesh: using THREE.InstancedBufferGeometry but hardware does not support extension ANGLE_instanced_arrays.' );
|
|
|
|
+ return;
|
|
|
|
|
|
- } else {
|
|
|
|
|
|
+ }
|
|
|
|
|
|
- if ( updateBuffers ) {
|
|
|
|
|
|
+ if ( position instanceof THREE.InterleavedBufferAttribute ) {
|
|
|
|
|
|
- setupVertexAttributes( material, program, geometry, 0 );
|
|
|
|
|
|
+ extension.drawArraysInstancedANGLE( mode, 0, position.data.count, geometry.maxInstancedCount ); // Draw the instanced meshes
|
|
|
|
|
|
- }
|
|
|
|
|
|
+ } else {
|
|
|
|
|
|
- // non-indexed triangles
|
|
|
|
|
|
+ extension.drawArraysInstancedANGLE( mode, 0, position.count, geometry.maxInstancedCount ); // Draw the instanced meshes
|
|
|
|
|
|
- var drawcall = geometry.drawcalls;
|
|
|
|
|
|
+ }
|
|
|
|
|
|
- if ( drawcall.length === 0 ) {
|
|
|
|
|
|
+ } else {
|
|
|
|
|
|
- var position = geometry.attributes.position;
|
|
|
|
|
|
+ if ( position instanceof THREE.InterleavedBufferAttribute ) {
|
|
|
|
|
|
- // render non-indexed triangles
|
|
|
|
|
|
+ _gl.drawArrays( mode, 0, position.data.count );
|
|
|
|
|
|
- if ( geometry instanceof THREE.InstancedBufferGeometry && geometry.maxInstancedCount > 0 ) {
|
|
|
|
|
|
+ } else {
|
|
|
|
|
|
- var extension = extensions.get( 'ANGLE_instanced_arrays' );
|
|
|
|
|
|
+ _gl.drawArrays( mode, 0, position.count );
|
|
|
|
|
|
- if ( extension === null ) {
|
|
|
|
|
|
+ }
|
|
|
|
|
|
- console.error( 'THREE.WebGLRenderer.renderMesh: using THREE.InstancedBufferGeometry but hardware does not support extension ANGLE_instanced_arrays.' );
|
|
|
|
- return;
|
|
|
|
|
|
+ }
|
|
|
|
|
|
- }
|
|
|
|
|
|
+ _infoRender.calls ++;
|
|
|
|
+ _infoRender.vertices += position.count;
|
|
|
|
+ _infoRender.faces += position.array.length / 3;
|
|
|
|
|
|
- if ( position instanceof THREE.InterleavedBufferAttribute ) {
|
|
|
|
|
|
+ } else {
|
|
|
|
|
|
- extension.drawArraysInstancedANGLE( mode, 0, position.data.count, geometry.maxInstancedCount ); // Draw the instanced meshes
|
|
|
|
|
|
+ for ( var i = 0, il = drawcall.length; i < il; i ++ ) {
|
|
|
|
|
|
- } else {
|
|
|
|
|
|
+ // render non-indexed triangles
|
|
|
|
|
|
- extension.drawArraysInstancedANGLE( mode, 0, position.count, geometry.maxInstancedCount ); // Draw the instanced meshes
|
|
|
|
|
|
+ if ( geometry instanceof THREE.InstancedBufferGeometry ) {
|
|
|
|
|
|
- }
|
|
|
|
|
|
+ console.error( 'THREE.WebGLRenderer.renderMesh: cannot use drawCalls with THREE.InstancedBufferGeometry.' );
|
|
|
|
+ return;
|
|
|
|
|
|
} else {
|
|
} else {
|
|
|
|
|
|
- if ( position instanceof THREE.InterleavedBufferAttribute ) {
|
|
|
|
-
|
|
|
|
- _gl.drawArrays( mode, 0, position.data.count );
|
|
|
|
-
|
|
|
|
- } else {
|
|
|
|
-
|
|
|
|
- _gl.drawArrays( mode, 0, position.count );
|
|
|
|
-
|
|
|
|
- }
|
|
|
|
|
|
+ _gl.drawArrays( mode, drawcall[ i ].start, drawcall[ i ].count );
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
_infoRender.calls ++;
|
|
_infoRender.calls ++;
|
|
- _infoRender.vertices += position.count;
|
|
|
|
- _infoRender.faces += position.array.length / 3;
|
|
|
|
-
|
|
|
|
- } else {
|
|
|
|
-
|
|
|
|
- for ( var i = 0, il = drawcall.length; i < il; i ++ ) {
|
|
|
|
-
|
|
|
|
- // render non-indexed triangles
|
|
|
|
-
|
|
|
|
- if ( geometry instanceof THREE.InstancedBufferGeometry ) {
|
|
|
|
-
|
|
|
|
- console.error( 'THREE.WebGLRenderer.renderMesh: cannot use drawCalls with THREE.InstancedBufferGeometry.' );
|
|
|
|
- return;
|
|
|
|
-
|
|
|
|
- } else {
|
|
|
|
-
|
|
|
|
- _gl.drawArrays( mode, drawcall[ i ].start, drawcall[ i ].count );
|
|
|
|
-
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- _infoRender.calls ++;
|
|
|
|
- _infoRender.vertices += drawcall[ i ].count;
|
|
|
|
- _infoRender.faces += ( drawcall[ i ].count ) / 3;
|
|
|
|
-
|
|
|
|
- }
|
|
|
|
|
|
+ _infoRender.vertices += drawcall[ i ].count;
|
|
|
|
+ _infoRender.faces += ( drawcall[ i ].count ) / 3;
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
@@ -1205,7 +1218,7 @@ THREE.WebGLRenderer = function ( parameters ) {
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
- function renderLine( material, geometry, object, program, updateBuffers ) {
|
|
|
|
|
|
+ function renderIndexedLine( material, geometry, object, program, updateBuffers ) {
|
|
|
|
|
|
var mode = object instanceof THREE.LineSegments ? _gl.LINES : _gl.LINE_STRIP;
|
|
var mode = object instanceof THREE.LineSegments ? _gl.LINES : _gl.LINE_STRIP;
|
|
|
|
|
|
@@ -1215,212 +1228,203 @@ THREE.WebGLRenderer = function ( parameters ) {
|
|
state.setLineWidth( lineWidth * pixelRatio );
|
|
state.setLineWidth( lineWidth * pixelRatio );
|
|
|
|
|
|
var index = geometry.attributes.index;
|
|
var index = geometry.attributes.index;
|
|
|
|
+ var indexBuffer = objects.getAttributeBuffer( index );
|
|
|
|
|
|
- if ( index ) {
|
|
|
|
|
|
+ var type, size;
|
|
|
|
|
|
- // indexed lines
|
|
|
|
|
|
+ if ( index.array instanceof Uint32Array && extensions.get( 'OES_element_index_uint' ) ) {
|
|
|
|
|
|
- var type, size;
|
|
|
|
|
|
+ type = _gl.UNSIGNED_INT;
|
|
|
|
+ size = 4;
|
|
|
|
|
|
- var indexBuffer = objects.getAttributeBuffer( index );
|
|
|
|
|
|
+ } else {
|
|
|
|
|
|
- if ( index.array instanceof Uint32Array && extensions.get( 'OES_element_index_uint' ) ) {
|
|
|
|
|
|
+ type = _gl.UNSIGNED_SHORT;
|
|
|
|
+ size = 2;
|
|
|
|
|
|
- type = _gl.UNSIGNED_INT;
|
|
|
|
- size = 4;
|
|
|
|
|
|
+ }
|
|
|
|
|
|
- } else {
|
|
|
|
|
|
+ var drawcall = geometry.drawcalls;
|
|
|
|
|
|
- type = _gl.UNSIGNED_SHORT;
|
|
|
|
- size = 2;
|
|
|
|
|
|
+ if ( drawcall.length === 0 ) {
|
|
|
|
+
|
|
|
|
+ if ( updateBuffers ) {
|
|
|
|
+
|
|
|
|
+ setupVertexAttributes( material, program, geometry, 0 );
|
|
|
|
+ _gl.bindBuffer( _gl.ELEMENT_ARRAY_BUFFER, indexBuffer );
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
- var drawcall = geometry.drawcalls;
|
|
|
|
|
|
+ _gl.drawElements( mode, index.array.length, type, 0 ); // 2 bytes per Uint16Array
|
|
|
|
+
|
|
|
|
+ _infoRender.calls ++;
|
|
|
|
+ _infoRender.vertices += index.array.length; // not really true, here vertices can be shared
|
|
|
|
|
|
- if ( drawcall.length === 0 ) {
|
|
|
|
|
|
+ } else {
|
|
|
|
+
|
|
|
|
+ // if there is more than 1 chunk
|
|
|
|
+ // must set attribute pointers to use new drawcall for each chunk
|
|
|
|
+ // even if geometry and materials didn't change
|
|
|
|
+
|
|
|
|
+ if ( drawcall.length > 1 ) updateBuffers = true;
|
|
|
|
+
|
|
|
|
+ for ( var i = 0, il = drawcall.length; i < il; i ++ ) {
|
|
|
|
+
|
|
|
|
+ var startIndex = drawcall[ i ].index;
|
|
|
|
|
|
if ( updateBuffers ) {
|
|
if ( updateBuffers ) {
|
|
|
|
|
|
- setupVertexAttributes( material, program, geometry, 0 );
|
|
|
|
|
|
+ setupVertexAttributes( material, program, geometry, startIndex );
|
|
_gl.bindBuffer( _gl.ELEMENT_ARRAY_BUFFER, indexBuffer );
|
|
_gl.bindBuffer( _gl.ELEMENT_ARRAY_BUFFER, indexBuffer );
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
- _gl.drawElements( mode, index.array.length, type, 0 ); // 2 bytes per Uint16Array
|
|
|
|
|
|
+ _gl.drawElements( mode, drawcall[ i ].count, type, drawcall[ i ].start * size ); // 2 bytes per Uint16Array
|
|
|
|
|
|
_infoRender.calls ++;
|
|
_infoRender.calls ++;
|
|
- _infoRender.vertices += index.array.length; // not really true, here vertices can be shared
|
|
|
|
|
|
+ _infoRender.vertices += drawcall[ i ].count; // not really true, here vertices can be shared
|
|
|
|
|
|
- } else {
|
|
|
|
|
|
+ }
|
|
|
|
|
|
- // if there is more than 1 chunk
|
|
|
|
- // must set attribute pointers to use new drawcall for each chunk
|
|
|
|
- // even if geometry and materials didn't change
|
|
|
|
|
|
+ }
|
|
|
|
|
|
- if ( drawcall.length > 1 ) updateBuffers = true;
|
|
|
|
|
|
+ }
|
|
|
|
|
|
- for ( var i = 0, il = drawcall.length; i < il; i ++ ) {
|
|
|
|
|
|
+ function renderLine( material, geometry, object, program, updateBuffers ) {
|
|
|
|
|
|
- var startIndex = drawcall[ i ].index;
|
|
|
|
|
|
+ var mode = object instanceof THREE.LineSegments ? _gl.LINES : _gl.LINE_STRIP;
|
|
|
|
|
|
- if ( updateBuffers ) {
|
|
|
|
|
|
+ // In case user is not using Line*Material by mistake
|
|
|
|
+ var lineWidth = material.linewidth !== undefined ? material.linewidth : 1;
|
|
|
|
|
|
- setupVertexAttributes( material, program, geometry, startIndex );
|
|
|
|
- _gl.bindBuffer( _gl.ELEMENT_ARRAY_BUFFER, indexBuffer );
|
|
|
|
|
|
+ state.setLineWidth( lineWidth * pixelRatio );
|
|
|
|
|
|
- }
|
|
|
|
|
|
+ if ( updateBuffers ) {
|
|
|
|
|
|
- // render indexed lines
|
|
|
|
|
|
+ setupVertexAttributes( material, program, geometry, 0 );
|
|
|
|
|
|
- _gl.drawElements( mode, drawcall[ i ].count, type, drawcall[ i ].start * size ); // 2 bytes per Uint16Array
|
|
|
|
|
|
+ }
|
|
|
|
|
|
- _infoRender.calls ++;
|
|
|
|
- _infoRender.vertices += drawcall[ i ].count; // not really true, here vertices can be shared
|
|
|
|
|
|
+ var position = geometry.attributes.position;
|
|
|
|
+ var drawcall = geometry.drawcalls;
|
|
|
|
|
|
- }
|
|
|
|
|
|
+ if ( drawcall.length === 0 ) {
|
|
|
|
|
|
- }
|
|
|
|
|
|
+ _gl.drawArrays( mode, 0, position.array.length / 3 );
|
|
|
|
+
|
|
|
|
+ _infoRender.calls ++;
|
|
|
|
+ _infoRender.vertices += position.array.length / 3;
|
|
|
|
|
|
} else {
|
|
} else {
|
|
|
|
|
|
- // non-indexed lines
|
|
|
|
|
|
+ for ( var i = 0, il = drawcall.length; i < il; i ++ ) {
|
|
|
|
|
|
- if ( updateBuffers ) {
|
|
|
|
|
|
+ _gl.drawArrays( mode, drawcall[ i ].index, drawcall[ i ].count );
|
|
|
|
|
|
- setupVertexAttributes( material, program, geometry, 0 );
|
|
|
|
|
|
+ _infoRender.calls ++;
|
|
|
|
+ _infoRender.vertices += drawcall[ i ].count;
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
- var position = geometry.attributes.position;
|
|
|
|
- var drawcall = geometry.drawcalls;
|
|
|
|
|
|
+ }
|
|
|
|
|
|
- if ( drawcall.length === 0 ) {
|
|
|
|
|
|
+ }
|
|
|
|
|
|
- _gl.drawArrays( mode, 0, position.array.length / 3 );
|
|
|
|
|
|
+ function renderIndexedPointCloud( material, geometry, program, updateBuffers ) {
|
|
|
|
|
|
- _infoRender.calls ++;
|
|
|
|
- _infoRender.vertices += position.array.length / 3;
|
|
|
|
|
|
+ var mode = _gl.POINTS;
|
|
|
|
|
|
- } else {
|
|
|
|
|
|
+ var index = geometry.attributes.index;
|
|
|
|
+ var indexBuffer = objects.getAttributeBuffer( index );
|
|
|
|
|
|
- for ( var i = 0, il = drawcall.length; i < il; i ++ ) {
|
|
|
|
|
|
+ var type, size;
|
|
|
|
|
|
- _gl.drawArrays( mode, drawcall[ i ].index, drawcall[ i ].count );
|
|
|
|
|
|
+ if ( index.array instanceof Uint32Array && extensions.get( 'OES_element_index_uint' ) ) {
|
|
|
|
|
|
- _infoRender.calls ++;
|
|
|
|
- _infoRender.vertices += drawcall[ i ].count;
|
|
|
|
|
|
+ type = _gl.UNSIGNED_INT;
|
|
|
|
+ size = 4;
|
|
|
|
|
|
- }
|
|
|
|
|
|
+ } else {
|
|
|
|
|
|
- }
|
|
|
|
|
|
+ type = _gl.UNSIGNED_SHORT;
|
|
|
|
+ size = 2;
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- function renderPointCloud( material, geometry, program, updateBuffers ) {
|
|
|
|
-
|
|
|
|
- var mode = _gl.POINTS;
|
|
|
|
-
|
|
|
|
- var index = geometry.attributes.index;
|
|
|
|
|
|
+ var drawcall = geometry.drawcalls;
|
|
|
|
|
|
- if ( index ) {
|
|
|
|
|
|
+ if ( drawcall.length === 0 ) {
|
|
|
|
|
|
- // indexed points
|
|
|
|
|
|
+ if ( updateBuffers ) {
|
|
|
|
|
|
- var type, size;
|
|
|
|
|
|
+ setupVertexAttributes( material, program, geometry, 0 );
|
|
|
|
+ _gl.bindBuffer( _gl.ELEMENT_ARRAY_BUFFER, indexBuffer );
|
|
|
|
|
|
- var indexBuffer = objects.getAttributeBuffer( index );
|
|
|
|
|
|
+ }
|
|
|
|
|
|
- if ( index.array instanceof Uint32Array && extensions.get( 'OES_element_index_uint' ) ) {
|
|
|
|
|
|
+ _gl.drawElements( mode, index.array.length, type, 0 );
|
|
|
|
|
|
- type = _gl.UNSIGNED_INT;
|
|
|
|
- size = 4;
|
|
|
|
|
|
+ _infoRender.calls ++;
|
|
|
|
+ _infoRender.points += index.array.length;
|
|
|
|
|
|
- } else {
|
|
|
|
|
|
+ } else {
|
|
|
|
|
|
- type = _gl.UNSIGNED_SHORT;
|
|
|
|
- size = 2;
|
|
|
|
|
|
+ // if there is more than 1 chunk
|
|
|
|
+ // must set attribute pointers to use new drawcall for each chunk
|
|
|
|
+ // even if geometry and materials didn't change
|
|
|
|
|
|
- }
|
|
|
|
|
|
+ if ( drawcall.length > 1 ) updateBuffers = true;
|
|
|
|
|
|
- var drawcall = geometry.drawcalls;
|
|
|
|
|
|
+ for ( var i = 0, il = drawcall.length; i < il; i ++ ) {
|
|
|
|
|
|
- if ( drawcall.length === 0 ) {
|
|
|
|
|
|
+ var startIndex = drawcall[ i ].index;
|
|
|
|
|
|
if ( updateBuffers ) {
|
|
if ( updateBuffers ) {
|
|
|
|
|
|
- setupVertexAttributes( material, program, geometry, 0 );
|
|
|
|
|
|
+ setupVertexAttributes( material, program, geometry, startIndex );
|
|
_gl.bindBuffer( _gl.ELEMENT_ARRAY_BUFFER, indexBuffer );
|
|
_gl.bindBuffer( _gl.ELEMENT_ARRAY_BUFFER, indexBuffer );
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
- _gl.drawElements( mode, index.array.length, type, 0 );
|
|
|
|
|
|
+ _gl.drawElements( mode, drawcall[ i ].count, type, drawcall[ i ].start * size );
|
|
|
|
|
|
_infoRender.calls ++;
|
|
_infoRender.calls ++;
|
|
- _infoRender.points += index.array.length;
|
|
|
|
|
|
+ _infoRender.points += drawcall[ i ].count;
|
|
|
|
|
|
- } else {
|
|
|
|
-
|
|
|
|
- // if there is more than 1 chunk
|
|
|
|
- // must set attribute pointers to use new drawcall for each chunk
|
|
|
|
- // even if geometry and materials didn't change
|
|
|
|
|
|
+ }
|
|
|
|
|
|
- if ( drawcall.length > 1 ) updateBuffers = true;
|
|
|
|
|
|
+ }
|
|
|
|
|
|
- for ( var i = 0, il = drawcall.length; i < il; i ++ ) {
|
|
|
|
|
|
+ }
|
|
|
|
|
|
- var startIndex = drawcall[ i ].index;
|
|
|
|
|
|
+ function renderPointCloud( material, geometry, program, updateBuffers ) {
|
|
|
|
|
|
- if ( updateBuffers ) {
|
|
|
|
|
|
+ var mode = _gl.POINTS;
|
|
|
|
|
|
- setupVertexAttributes( material, program, geometry, startIndex );
|
|
|
|
- _gl.bindBuffer( _gl.ELEMENT_ARRAY_BUFFER, indexBuffer );
|
|
|
|
|
|
+ if ( updateBuffers ) {
|
|
|
|
|
|
- }
|
|
|
|
|
|
+ setupVertexAttributes( material, program, geometry, 0 );
|
|
|
|
|
|
- // render indexed points
|
|
|
|
|
|
+ }
|
|
|
|
|
|
- _gl.drawElements( mode, drawcall[ i ].count, type, drawcall[ i ].start * size );
|
|
|
|
|
|
+ var position = geometry.attributes.position;
|
|
|
|
+ var drawcall = geometry.drawcalls;
|
|
|
|
|
|
- _infoRender.calls ++;
|
|
|
|
- _infoRender.points += drawcall[ i ].count;
|
|
|
|
|
|
+ if ( drawcall.length === 0 ) {
|
|
|
|
|
|
- }
|
|
|
|
|
|
+ _gl.drawArrays( mode, 0, position.array.length / 3 );
|
|
|
|
|
|
- }
|
|
|
|
|
|
+ _infoRender.calls ++;
|
|
|
|
+ _infoRender.points += position.array.length / 3;
|
|
|
|
|
|
} else {
|
|
} else {
|
|
|
|
|
|
- // non-indexed points
|
|
|
|
-
|
|
|
|
- if ( updateBuffers ) {
|
|
|
|
-
|
|
|
|
- setupVertexAttributes( material, program, geometry, 0 );
|
|
|
|
-
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- var position = geometry.attributes.position;
|
|
|
|
- var drawcall = geometry.drawcalls;
|
|
|
|
|
|
+ for ( var i = 0, il = drawcall.length; i < il; i ++ ) {
|
|
|
|
|
|
- if ( drawcall.length === 0 ) {
|
|
|
|
-
|
|
|
|
- _gl.drawArrays( mode, 0, position.array.length / 3 );
|
|
|
|
|
|
+ _gl.drawArrays( mode, drawcall[ i ].index, drawcall[ i ].count );
|
|
|
|
|
|
_infoRender.calls ++;
|
|
_infoRender.calls ++;
|
|
- _infoRender.points += position.array.length / 3;
|
|
|
|
-
|
|
|
|
- } else {
|
|
|
|
-
|
|
|
|
- for ( var i = 0, il = drawcall.length; i < il; i ++ ) {
|
|
|
|
-
|
|
|
|
- _gl.drawArrays( mode, drawcall[ i ].index, drawcall[ i ].count );
|
|
|
|
-
|
|
|
|
- _infoRender.calls ++;
|
|
|
|
- _infoRender.points += drawcall[ i ].count;
|
|
|
|
-
|
|
|
|
- }
|
|
|
|
|
|
+ _infoRender.points += drawcall[ i ].count;
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|