WebGLIndexedBufferRenderer.js 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. /**
  2. * @author mrdoob / http://mrdoob.com/
  3. */
  4. function WebGLIndexedBufferRenderer( gl, extensions, info ) {
  5. var isWebGL2 = typeof WebGL2RenderingContext !== 'undefined' && gl instanceof WebGL2RenderingContext;
  6. var mode;
  7. function setMode( value ) {
  8. mode = value;
  9. }
  10. var type, bytesPerElement;
  11. function setIndex( value ) {
  12. type = value.type;
  13. bytesPerElement = value.bytesPerElement;
  14. }
  15. function render( start, count ) {
  16. gl.drawElements( mode, count, type, start * bytesPerElement );
  17. info.update( count, mode );
  18. }
  19. function renderInstances( geometry, start, count ) {
  20. var extension = extensions.get( 'ANGLE_instanced_arrays' );
  21. if ( extension === null ) {
  22. console.error( 'THREE.WebGLIndexedBufferRenderer: using THREE.InstancedBufferGeometry but hardware does not support extension ANGLE_instanced_arrays.' );
  23. return;
  24. }
  25. extension[ isWebGL2 ? 'drawElementsInstanced' : 'drawElementsInstancedANGLE' ]( mode, count, type, start * bytesPerElement, geometry.maxInstancedCount );
  26. info.update( count, mode, geometry.maxInstancedCount );
  27. }
  28. //
  29. this.setMode = setMode;
  30. this.setIndex = setIndex;
  31. this.render = render;
  32. this.renderInstances = renderInstances;
  33. }
  34. export { WebGLIndexedBufferRenderer };
粤ICP备19079148号