Skip to content

Conversation

@gkjohnson
Copy link
Collaborator

Related issue: #21734

Depends on #29769

Description

This PR adjusts copyTextureToTexture so it can take null as the first "srcTexture" argument so data can be copied from the "canvas" frame buffer, removing the need for a separate "copyFramebufferToTexture" function since this was the only remaining use case after #29662 was merged. Since this function was the only documented reason for FrameBufferTexture, that has been removed, as well.

The LensFlare addon is the last thing that needs to be changed before this PR is ready but I'll wait for feedback before making further changes.

@github-actions
Copy link

github-actions bot commented Oct 30, 2024

📦 Bundle size

Full ESM build, minified and gzipped.

Before After Diff
WebGL 692.66
171.56
693.05
171.77
+394 B
+212 B
WebGPU 822.12
221.9
822.25
221.97
+136 B
+65 B
WebGPU Nodes 821.63
221.78
821.76
221.84
+136 B
+60 B

🌳 Bundle size after tree-shaking

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

Before After Diff
WebGL 465.01
112.35
467.12
112.93
+2.1 kB
+579 B
WebGPU 542.65
146.78
542.79
146.84
+136 B
+55 B
WebGPU Nodes 498.65
136.58
498.79
136.65
+136 B
+70 B

Comment on lines -106 to +107
texture = new THREE.FramebufferTexture( textureSize, textureSize );
texture = new THREE.DataTexture( new Uint8Array( textureSize * textureSize * 4 ), textureSize, textureSize );
texture.needsUpdate = true;
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Creating an "empty" texture that is only useful for copying data into, as FramebufferTexture was, is a bit more awkward, now. In the past I've used RenderTargets to serve as "empty" texture vessels for copying data around into but there's still some extra memory overhead in that case (depth buffers, etc).

Comment on lines +2712 to +2718
const currentTarget = this.getRenderTarget();

this.setRenderTarget( null );
textures.setTexture2D( dstTexture, 0 );
_gl.copyTexSubImage2D( _gl.TEXTURE_2D, dstLevel, dstX, dstY, minX, minY, width, height );
state.unbindTexture();
this.setRenderTarget( currentTarget );
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I'm not sure if there's a better way to do this without calling "setRenderTarget"

@gkjohnson gkjohnson added this to the r170 milestone Oct 31, 2024
@mrdoob mrdoob modified the milestones: r170, r171 Oct 31, 2024
# Conflicts:
#	docs/api/en/renderers/WebGLRenderer.html
#	src/renderers/WebGLRenderer.js
@gkjohnson
Copy link
Collaborator Author

gkjohnson commented Nov 7, 2024

cc @Mugen87 what are your thoughts on this? I'm hoping it cuts down on some API redundancy with copyTextureToTexture. Happy to adjust it however and remove the last couple uses of copyFramebufferToTexture in examples.

@Mugen87
Copy link
Collaborator

Mugen87 commented Nov 7, 2024

FYI: I've noticed the PR but I'm currently focusing on bug fixing/support in WebGPURenderer so it will take a bit until I can revisit this topic.

@mrdoob mrdoob modified the milestones: r171, r172 Nov 29, 2024
@mrdoob mrdoob modified the milestones: r172, r173 Dec 31, 2024
@mrdoob mrdoob modified the milestones: r173, r174 Jan 31, 2025
@mrdoob mrdoob modified the milestones: r174, r175 Feb 27, 2025
@mrdoob mrdoob modified the milestones: r175, r176 Mar 28, 2025
@mrdoob mrdoob modified the milestones: r176, r177 Apr 24, 2025
@mrdoob mrdoob modified the milestones: r177, r178 May 30, 2025
@mrdoob mrdoob modified the milestones: r178, r179 Jun 30, 2025
@mrdoob mrdoob modified the milestones: r179, r180 Aug 1, 2025
@mrdoob mrdoob modified the milestones: r180, r181 Sep 3, 2025
@mrdoob mrdoob modified the milestones: r181, r182 Oct 31, 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.

3 participants