WebGLRenderer: Enable subframe upload in copyTextureToTexture, align API to 3d version#28281
WebGLRenderer: Enable subframe upload in copyTextureToTexture, align API to 3d version#28281gkjohnson merged 17 commits intomrdoob:devfrom
Conversation
📦 Bundle sizeFull ESM build, minified and gzipped.
🌳 Bundle size after tree-shakingMinimal build including a renderer, camera, empty scene, and dependencies.
|
| _gl.compressedTexSubImage2D( _gl.TEXTURE_2D, level, position.x, position.y, srcTexture.mipmaps[ 0 ].width, srcTexture.mipmaps[ 0 ].height, glFormat, srcTexture.mipmaps[ 0 ].data ); | ||
| _gl.compressedTexSubImage2D( _gl.TEXTURE_2D, level, position.x, position.y, image.width, image.height, glFormat, image.data ); |
There was a problem hiding this comment.
One other discrepancy I noticed between the copyTextureToTexture and copyTextureToTexture3D implementations is that the 3D variant used "level" to index into the source textures mipmap array whereas it was always 0 in the 2d version. I've aligned to what the 3d function was doing but am happy to change it either way.
|
In general, I'm okay with this change. When adding Actually, I would prefer to have |
Either way the end result is the same: one function signature incurs a breaking change. If you'd prefer an optional argument now would be the time to do it, though the argument grouping becomes a little strange. |
|
I vote for: copyTextureToTexture( position, srcTexture, dstTexture, level, srcBox );
copyTextureToTexture3D( position, srcTexture, dstTexture, level, srcBox );I agree the grouping is not ideal but always asking the users to define the source box like in the example feels inconvenient. There are for sure use cases where users want to copy the entire source texture into the destination texture and that should work as easy as possible. |
|
Just updated the signatures and update both examples! |
| }; | ||
|
|
||
| this.copyTextureToTexture = function ( position, srcTexture, dstTexture, level = 0 ) { | ||
| this.copyTextureToTexture = function ( position, srcTexture, dstTexture, level = 0, sourceBox = null ) { |
There was a problem hiding this comment.
I think srcRegion is more clear and follows the rest of the parameter names.
|
Or something like this? this.copyTextureToTexture = function ( srcCoords: Vector2 | Box2, srcTexture, dstTexture, level = 0 ) |
We can change the naming to something like the following: dstPosition, srcTexture, dstTexture, level = 0, srcRegion = nullThough in my opinion something like this might make the most sense. We can change to this with backwards compatibility for 10 releases: this.copyTextureToTexture = function ( srcTexture, dstTexture, srcRegion = null, dstPosition = null, level = 0 ) |
That looks much nicer indeed 👌 |
|
Okay! It should be ready now |
| this.copyTextureToTexture = function ( position, srcTexture, dstTexture, level = 0 ) { | ||
| this.copyTextureToTexture = function ( srcTexture, dstTexture, srcRegion = null, dstPosition = null, level = 0 ) { | ||
|
|
||
| // support previous signature with source box first |
There was a problem hiding this comment.
Should be like this?
// support previous signature with dstPosition first
There was a problem hiding this comment.
Oh yeah - copy paste error
Related issue: -
Description
Adds a Box2 "bounds" argument to
copyTextureToTextureso we can upload just a small portion of a texture.Specifically my use case is to be able copy just a single pixel of an id texture to a render target so it can be read back to the GPU to identify the id at the given pixel (see the EXT_mesh_features Cesium glTF extension). With this change we can copy just a single pixel from a large source texture to a 1x1 render target and then read it back whereas previously we'd have to copy to a render target of equivalent size. As far as I know there's no other way to reliably read just a single pixel from an arbitrary image.
From my testing with reading single pixel from a 2048 x 2048 image this improves the upload and read time from ~10ms to ~2ms. If async read is used presumably the ~2ms would go down quite a bit further, as well.
Benchmark code
This contribution is funded by the Cesium GIS Ecosystem Grant