transferFromGLTexture() {
    if (this.glTextureFragments) {
      this.tensor = ndarray(new this.arrayType(this.glTextureShape[0] * this.glTextureShape[1]), this.glTextureShape)
      let offset = 0
      for (let k = 0; k < this.glTextureFragments.length; k++) {
        webgl2.bindOutputTexture(this.glTextureFragments[k], this.glTextureFragmentShape)
        const fragmentData = webgl2.readData(this.glTextureFragmentShape)
        // last fragment may need to be truncated
        if (k === this.glTextureFragments.length - 1) {
          const truncate = this.tensor.data.length - offset
          this.tensor.data.set(fragmentData.subarray(0, truncate), offset)
        } else {
          this.tensor.data.set(fragmentData, offset)
        }
        offset += fragmentData.length
      }
    } else {
      webgl2.bindOutputTexture(this.glTexture, this.glTextureShape)
      this.tensor = ndarray(new this.arrayType([]), this.glTextureShape)
      this.tensor.data = webgl2.readData(this.glTextureShape)
    }

    if (this.is1D && this.glTextureShape[0] === 1) {
      // collapse to 1D
      this.tensor = squeeze(this.tensor, [0])
    }
  }
Transfer data from webgl texture on GPU to ndarray on CPU