code: protected ArrayBufferView getTypedArray(Buffer buffer, int type, int byteSize) {
      if (!(buffer instanceof HasArrayBufferView)) {
        throw new RuntimeException("Native buffer required " + buffer);
      }
      HasArrayBufferView arrayHolder = (HasArrayBufferView) buffer;
      int bufferElementSize = arrayHolder.getElementSize();
  
      ArrayBufferView webGLArray = arrayHolder.getTypedArray();
      if (byteSize == -1) {
        byteSize = buffer.remaining() * bufferElementSize;
      }
      if (byteSize == buffer.capacity() * bufferElementSize && type == arrayHolder.getElementType()) {
        return webGLArray;
      }
  
      int byteOffset = webGLArray.byteOffset() + buffer.position() * bufferElementSize;
  
      switch (type) {
      case FLOAT:
        return TypedArrays.createFloat32Array(webGLArray.buffer(), byteOffset, byteSize / 4);
      case UNSIGNED_BYTE:
        return TypedArrays.createUint8Array(webGLArray.buffer(), byteOffset, byteSize);
      case UNSIGNED_SHORT:
        return TypedArrays.createUint16Array(webGLArray.buffer(), byteOffset, byteSize / 2);
      case INT:
        return TypedArrays.createInt32Array(webGLArray.buffer(), byteOffset, byteSize / 4);
      case SHORT:
        return TypedArrays.createInt16Array(webGLArray.buffer(), byteOffset, byteSize / 2);
      case BYTE:
        return TypedArrays.createInt8Array(webGLArray.buffer(), byteOffset, byteSize);
      default:
        throw new IllegalArgumentException("Type: " + type);
      }
    }
docs: Returns the typed array of the given native buffer.
  Set byteSize to -1 to use remaining()