copyTextureToTexture method
void
copyTextureToTexture(})
Implementation
void copyTextureToTexture(position, Texture srcTexture, dstTexture, {int level = 0}) {
final width = srcTexture.image.width;
final height = srcTexture.image.height;
final glFormat = utils.convert(dstTexture.format);
final 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(WebGL.UNPACK_FLIP_Y_WEBGL, dstTexture.flipY ? 1 : 0);
_gl.pixelStorei(WebGL.UNPACK_PREMULTIPLY_ALPHA_WEBGL, dstTexture.premultiplyAlpha);
_gl.pixelStorei(WebGL.UNPACK_ALIGNMENT, dstTexture.unpackAlignment);
if (srcTexture is DataTexture) {
_gl.texSubImage2D(WebGL.TEXTURE_2D, level, position.x, position.y, width, height, glFormat, glType, srcTexture.image.data);
}
else {
if (srcTexture is CompressedTexture) {
_gl.compressedTexSubImage2D(WebGL.TEXTURE_2D, level, position.x, position.y, srcTexture.mipmaps[0].width,srcTexture.mipmaps[0].height, glFormat, srcTexture.mipmaps[0].data);
}
else {
_gl.texSubImage2D(WebGL.TEXTURE_2D, level, position.x, position.y, 0, 0, glFormat, glType, srcTexture.image);
}
}
// Generate mipmaps only when copying level 0
if (level == 0 && dstTexture.generateMipmaps) {
_gl.generateMipmap(WebGL.TEXTURE_2D);
}
state.unbindTexture();
}