Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WebGLBackend: Bring back 3D functionality for copyTextureToTexture #30584

Merged
merged 2 commits into from
Mar 4, 2025

Conversation

zonkypop
Copy link
Contributor

@zonkypop zonkypop commented Feb 22, 2025

Issue

#30619

Description

In the WebGLBackend, copyTextureToTexture has only implemented copying for 2D textures.

This PR uses parts of the code from the original GL renderer to add functionality for copying between 2D and 3D textures in new WebGL fallback renderer.

Copy link

github-actions bot commented Feb 22, 2025

📦 Bundle size

Full ESM build, minified and gzipped.

Before After Diff
WebGL 336.02
78.26
336.02
78.26
+0 B
+0 B
WebGPU 522.67
145.12
523.07
145.25
+397 B
+131 B
WebGPU Nodes 522.14
145.01
522.54
145.14
+397 B
+130 B

🌳 Bundle size after tree-shaking

Minimal build including a renderer, camera, empty scene, and dependencies.

Before After Diff
WebGL 465.06
112.14
465.06
112.14
+0 B
+0 B
WebGPU 593.08
160.73
593.48
160.86
+397 B
+124 B
WebGPU Nodes 548.2
150.17
548.6
150.29
+397 B
+125 B

@zonkypop zonkypop changed the title Bring back 3d functionality for copyTextureToTexture WebGLBackend: Bring back 3D functionality for copyTextureToTexture Feb 26, 2025
@@ -699,68 +699,90 @@ class WebGLTextureUtils {
* @param {Texture} dstTexture - The destination texture.
* @param {?Vector4} [srcRegion=null] - The region of the source texture to copy.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you mind fixing the parameter type of srcRegion?

*/
copyTextureToTexture( srcTexture, dstTexture, srcRegion = null, dstPosition = null, level = 0 ) {
copyTextureToTexture( srcTexture, dstTexture, srcRegion = null, dstPosition = null, srcLevel = 0, dstLevel = 0 ) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you mind updating all copyTextureToTexture() signatures in WebGPURenderer? For that, you have to update Renderer.copyTextureToTexture(), Backend.copyTextureToTexture() (the interface definition) and both backends.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool I've updated the signatures too, hopefully it's looking alright

@zonkypop zonkypop force-pushed the WebGLBackend-copyTextureToTexture-3D branch from 3cb654b to b72a191 Compare February 27, 2025 22:15
*/
copyTextureToTexture( srcTexture, dstTexture, srcRegion = null, dstPosition = null, level = 0 ) {
copyTextureToTexture( srcTexture, dstTexture, srcRegion = null, dstPosition = null, level = 0, dstLevel = 0 ) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please rename level to srcLevel?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed, I've set dstLevel = null which is the same as the original WebGLRenderer as well.

// gather the necessary dimensions to copy
let width, height, depth, minX, minY, minZ;
let dstX, dstY, dstZ;
const image = srcTexture.isCompressedTexture ? srcTexture.mipmaps[ dstLevel ] : srcTexture.image;
Copy link
Collaborator

@Mugen87 Mugen87 Mar 3, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This bit isn't correct. The default value of dstLevel must be 0 otherwise you end up with srcTexture.mipmaps[ null ].

Please change the default value of dstLevel to 0 in all signatures as well in #30618.

Copy link
Collaborator

@Mugen87 Mugen87 Mar 3, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Regarding your comment in #30584 (comment): The signature in WebGLRenderer can't be used as a template since the value is null for backwards compatibility reason, AFAICS. Besides, it is set to 0 in the first if statement.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah yes that makes sense, I have updated them to use dstLevel = 0 by default now.

@zonkypop zonkypop force-pushed the WebGLBackend-copyTextureToTexture-3D branch from 93a1072 to 38be18a Compare March 4, 2025 03:58
@Mugen87 Mugen87 added this to the r175 milestone Mar 4, 2025
@Mugen87 Mugen87 merged commit a42a8cf into mrdoob:dev Mar 4, 2025
12 checks passed
Mugen87 added a commit that referenced this pull request Mar 4, 2025
Fix interface method, see #30584.
@Mugen87 Mugen87 mentioned this pull request Mar 4, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants