copyTextureToTexture method

void copyTextureToTexture(
  1. dynamic position,
  2. Texture srcTexture,
  3. dynamic dstTexture, {
  4. int level = 0,
})

Implementation

void copyTextureToTexture(position, Texture srcTexture, dstTexture,
    {int level = 0}) {
  var width = srcTexture.image.width;
  var height = srcTexture.image.height;
  var glFormat = utils.convert(dstTexture.format);
  var glType = utils.convert(dstTexture.type);

  textures.setTexture2D(dstTexture, 0);

  // As another texture upload may have changed pixelStorei
  // parameters, make sure they are correct for the dstTexture
  _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);

  if (srcTexture is DataTexture) {
    _gl.texSubImage2D(_gl.TEXTURE_2D, level, position.x, position.y, width,
        height, glFormat, glType, srcTexture.image.data);
  } else {
    if (srcTexture.isCompressedTexture) {
      _gl.compressedTexSubImage2D(
          _gl.TEXTURE_2D,
          level,
          position.x,
          position.y,
          srcTexture.mipmaps[0].width,
          srcTexture.mipmaps[0].height,
          glFormat,
          srcTexture.mipmaps[0].data);
    } else {
      _gl.texSubImage2D(_gl.TEXTURE_2D, level, position.x, position.y, null,
          null, glFormat, glType, srcTexture.image);
    }
  }

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

  state.unbindTexture();
}