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

WebGLRenderer: Allow for copying textures from the canvas, remove copyFramebufferToTexture #29772

Draft
wants to merge 17 commits into
base: dev
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 15 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 2 additions & 11 deletions docs/api/en/renderers/WebGLRenderer.html
Original file line number Diff line number Diff line change
Expand Up @@ -371,21 +371,12 @@ <h3>
</p>

<h3>
[method:undefined copyFramebufferToTexture]( [param:FramebufferTexture texture], [param:Vector2 position], [param:Number level] )
</h3>
<p>
Copies pixels from the current WebGLFramebuffer into a 2D texture. Enables
access to
[link:https://developer.mozilla.org/en-US/docs/Web/API/WebGLRenderingContext/copyTexImage2D WebGLRenderingContext.copyTexImage2D].
</p>

<h3>
[method:undefined copyTextureToTexture]( [param:Texture srcTexture], [param:Texture dstTexture], [param:Box2 srcRegion] | [param:Box3 srcRegion], [param:Vector2 dstPosition] | [param:Vector3 dstPosition], [param:Number dstLevel] )
[method:undefined copyTextureToTexture]( [param:Texture srcTexture], [param:Texture dstTexture], [param:Box2 srcRegion] | [param:Box3 srcRegion], [param:Vector2 dstPosition] | [param:Vector3 dstPosition], [param:Number srcLevel], [param:Number dstLevel] )
</h3>
<p>
Copies the pixels of a texture in the bounds '[page:Box3 srcRegion]' in the destination texture starting from the given position.
2D Texture, 3D Textures, or a mix of the two can be used as source and destination texture arguments for copying between layers of 3d textures.</br>
The `depthTexture` and `texture` property of render targets are supported as well.<br />
The `depthTexture` and `texture` property of render targets are supported as well. If `srcTexture` is `null` then data is copied from the canvas frame buffer.<br />
When using render target textures as `srcTexture` and `dstTexture`, you must make sure both render targets are initialized e.g. via [page:.initRenderTarget]().
</p>

Expand Down
98 changes: 0 additions & 98 deletions docs/api/en/textures/FramebufferTexture.html

This file was deleted.

56 changes: 0 additions & 56 deletions docs/api/it/textures/FramebufferTexture.html

This file was deleted.

93 changes: 0 additions & 93 deletions docs/api/zh/textures/FramebufferTexture.html

This file was deleted.

13 changes: 8 additions & 5 deletions examples/webgl_framebuffer_texture.html
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
const dpr = window.devicePixelRatio;

const textureSize = 128 * dpr;
const vector = new THREE.Vector2();
const box = new THREE.Box2();
const color = new THREE.Color();

init();
Expand Down Expand Up @@ -103,7 +103,8 @@

//

texture = new THREE.FramebufferTexture( textureSize, textureSize );
texture = new THREE.DataTexture( new Uint8Array( textureSize * textureSize * 4 ), textureSize, textureSize );
texture.needsUpdate = true;
Comment on lines -106 to +107
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).


//

Expand Down Expand Up @@ -178,11 +179,13 @@
renderer.render( scene, camera );

// calculate start position for copying data
const x = window.innerWidth * dpr / 2 - textureSize / 2;
const y = window.innerHeight * dpr / 2 - textureSize / 2;

vector.x = ( window.innerWidth * dpr / 2 ) - ( textureSize / 2 );
vector.y = ( window.innerHeight * dpr / 2 ) - ( textureSize / 2 );
box.min.set( x, y );
box.max.set( x + textureSize, y + textureSize );
renderer.copyTextureToTexture( null, texture, box );

renderer.copyFramebufferToTexture( texture, vector );

renderer.clearDepth();
renderer.render( sceneOrtho, cameraOrtho );
Expand Down
Loading