WebGLAttributeUtils.js 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. class WebGLAttributeUtils {
  2. constructor( backend ) {
  3. this.backend = backend;
  4. }
  5. createAttribute( attribute, bufferType ) {
  6. const backend = this.backend;
  7. const { gl } = backend;
  8. const array = attribute.array;
  9. const usage = attribute.usage || gl.STATIC_DRAW;
  10. const bufferGPU = gl.createBuffer();
  11. gl.bindBuffer( bufferType, bufferGPU );
  12. gl.bufferData( bufferType, array, usage );
  13. gl.bindBuffer( bufferType, null );
  14. //attribute.onUploadCallback();
  15. let type;
  16. if ( array instanceof Float32Array ) {
  17. type = gl.FLOAT;
  18. } else if ( array instanceof Uint16Array ) {
  19. if ( attribute.isFloat16BufferAttribute ) {
  20. type = gl.HALF_FLOAT;
  21. } else {
  22. type = gl.UNSIGNED_SHORT;
  23. }
  24. } else if ( array instanceof Int16Array ) {
  25. type = gl.SHORT;
  26. } else if ( array instanceof Uint32Array ) {
  27. type = gl.UNSIGNED_INT;
  28. } else if ( array instanceof Int32Array ) {
  29. type = gl.INT;
  30. } else if ( array instanceof Int8Array ) {
  31. type = gl.BYTE;
  32. } else if ( array instanceof Uint8Array ) {
  33. type = gl.UNSIGNED_BYTE;
  34. } else if ( array instanceof Uint8ClampedArray ) {
  35. type = gl.UNSIGNED_BYTE;
  36. } else {
  37. throw new Error( 'THREE.WebGLBackend: Unsupported buffer data format: ' + array );
  38. }
  39. backend.set( attribute, {
  40. bufferGPU,
  41. type,
  42. bytesPerElement: array.BYTES_PER_ELEMENT,
  43. version: attribute.version
  44. } );
  45. }
  46. }
  47. export default WebGLAttributeUtils;