copyTextureToTexture sourcebox, flipY from source
Related issue: #21942
Description
This PR aligns the apis of copyTextureToTexture and copyTextureToTexture3D in the WebGLRenderer :
- copyTextureToTexture was missing a source box parameter (only full images could be copied)
- a source level is added to enable copying a higher level than 0 from the source image for advanced uses.
- the parameters are reordered in both functions as
( srcTexture, dstTexture, dstPosition = undefined, srcBox = undefined, dstLevel = 0, srcLevel = 0 )as all parameters but textures have sensible defaults (destination position at origin, full source box and levels at 0). - usage of the previous api is detected by checking if the first argument is a texture, to reorder the parameters and print a deprecation warning.
examples/webgl_materials_texture_partialupdate.html
- it now demonstrates copying sub parts of an input 2D texture

The box is reduced so that it points to valid pixels in both the source and destination textures. As an alternative, this code could be simplified if this burden is given to the user (big boxes will trigger webgl error).
finally, the UNPACK parameters are now taken from the source texture rather than the destination texture. It makes more sense in my use cases (otherwise I always end up at least copying flipY and unpackAlignment from the srcTexture to the dstTexture before the copy as a workaround)
/cc @DavidPeicho
What about this version ? https://github.com/mbredif/three.js/blob/copyTextureToTexture_merged/src/renderers/WebGLRenderer.js#L2083-L2227 . As @DavidPeicho mentioned, the 2 copy functions could be merged to factor common code. I also removed the box shrinking code to simplify the implementation.
I quite like the second version! Thanks!
It's indeed a bit of code, but that's the issue with abstracting a method that has so many options.