copyTextureToTexture3D method

void copyTextureToTexture3D(
  1. Box3 sourceBox,
  2. Vector3 position,
  3. Texture srcTexture,
  4. Texture dstTexture, {
  5. int level = 0,
})

Implementation

void copyTextureToTexture3D(
  Box3 sourceBox,
  Vector3 position,
  Texture srcTexture,
  Texture dstTexture, {
  int level = 0,
}) {
  var width = sourceBox.max.x - sourceBox.min.x + 1;
  var height = sourceBox.max.y - sourceBox.min.y + 1;
  var depth = sourceBox.max.z - sourceBox.min.z + 1;
  var glFormat = utils.convert(dstTexture.format);
  var glType = utils.convert(dstTexture.type);
  var glTarget;

  if (dstTexture is Data3DTexture) {
    textures.setTexture3D(dstTexture, 0);
    glTarget = _gl.TEXTURE_3D;
  } else if (dstTexture is DataArrayTexture) {
    textures.setTexture2DArray(dstTexture, 0);
    glTarget = _gl.TEXTURE_2D_ARRAY;
  } else {
    print(
        'three.WebGLRenderer.copyTextureToTexture3D: only supports three.DataTexture3D and three.DataTexture2DArray.');
    return;
  }

  _gl.pixelStorei(_gl.UNPACK_FLIP_Y_WEBGL, dstTexture.flipY ? 1 : 0);
  _gl.pixelStorei(_gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, dstTexture.premultiplyAlpha);
  _gl.pixelStorei(_gl.UNPACK_ALIGNMENT, dstTexture.unpackAlignment);

  var unpackRowLen = _gl.getParameter(_gl.UNPACK_ROW_LENGTH);
  var unpackImageHeight = _gl.getParameter(_gl.UNPACK_IMAGE_HEIGHT);
  var unpackSkipPixels = _gl.getParameter(_gl.UNPACK_SKIP_PIXELS);
  var unpackSkipRows = _gl.getParameter(_gl.UNPACK_SKIP_ROWS);
  var unpackSkipImages = _gl.getParameter(_gl.UNPACK_SKIP_IMAGES);

  var image = srcTexture.isCompressedTexture ? srcTexture.mipmaps[0] : srcTexture.image;

  _gl.pixelStorei(_gl.UNPACK_ROW_LENGTH, image.width);
  _gl.pixelStorei(_gl.UNPACK_IMAGE_HEIGHT, image.height);
  _gl.pixelStorei(_gl.UNPACK_SKIP_PIXELS, sourceBox.min.x);
  _gl.pixelStorei(_gl.UNPACK_SKIP_ROWS, sourceBox.min.y);
  _gl.pixelStorei(_gl.UNPACK_SKIP_IMAGES, sourceBox.min.z);

  if (srcTexture is DataTexture || srcTexture is Data3DTexture) {
    _gl.texSubImage3D(
        glTarget, level, position.x, position.y, position.z, width, height, depth, glFormat, glType, image.data);
  } else {
    if (srcTexture.isCompressedTexture) {
      print('three.WebGLRenderer.copyTextureToTexture3D: untested support for compressed srcTexture.');
      _gl.compressedTexSubImage3D(
          glTarget, level, position.x, position.y, position.z, width, height, depth, glFormat, image.data);
    } else {
      _gl.texSubImage3D(
          glTarget, level, position.x, position.y, position.z, width, height, depth, glFormat, glType, image);
    }
  }

  _gl.pixelStorei(_gl.UNPACK_ROW_LENGTH, unpackRowLen);
  _gl.pixelStorei(_gl.UNPACK_IMAGE_HEIGHT, unpackImageHeight);
  _gl.pixelStorei(_gl.UNPACK_SKIP_PIXELS, unpackSkipPixels);
  _gl.pixelStorei(_gl.UNPACK_SKIP_ROWS, unpackSkipRows);
  _gl.pixelStorei(_gl.UNPACK_SKIP_IMAGES, unpackSkipImages);

  // Generate mipmaps only when copying level 0
  if (level == 0 && dstTexture.generateMipmaps) _gl.generateMipmap(glTarget);

  state.unbindTexture();
}