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: Update copyFramebufferToTexture function signature #28329

Merged
merged 2 commits into from
May 10, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion docs/api/ar/renderers/WebGLRenderer.html
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,7 @@ <h3>
</p>

<h3>
[method:undefined copyFramebufferToTexture]( [param:Vector2 position], [param:FramebufferTexture texture], [param:Number level] )
[method:undefined copyFramebufferToTexture]( [param:FramebufferTexture texture], [param:Vector2 position], [param:Number level] )
</h3>
<p>
ينسخ بكسلات من WebGLFramebuffer الحالي إلى قوام ثنائي الأبعاد. يتيح
Expand Down
2 changes: 1 addition & 1 deletion docs/api/en/renderers/WebGLRenderer.html
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ <h3>
</p>

<h3>
[method:undefined copyFramebufferToTexture]( [param:Vector2 position], [param:FramebufferTexture texture], [param:Number level] )
[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
Expand Down
2 changes: 1 addition & 1 deletion docs/api/en/textures/FramebufferTexture.html
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ <h1>[name]</h1>
renderer.render( scene, camera );

// copy part of the rendered frame into the framebuffer texture
renderer.copyFramebufferToTexture( vector, frameTexture );
renderer.copyFramebufferToTexture( frameTexture, vector );
</code>

<h2>Examples</h2>
Expand Down
2 changes: 1 addition & 1 deletion docs/api/it/renderers/WebGLRenderer.html
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,7 @@ <h3>[method:Promise compileAsync]( [param:Object3D scene], [param:Camera camera]
Questo metodo utilizza *KHR_parallel_shader_compile*.
</p>

<h3>[method:undefined copyFramebufferToTexture]( [param:Vector2 position], [param:FramebufferTexture texture], [param:Number level] )</h3>
<h3>[method:undefined copyFramebufferToTexture]( [param:FramebufferTexture texture], [param:Vector2 position], [param:Number level] )</h3>
<p>
Copia i pixel dal WebGLFramebuffer corrente in una texture 2D. Abilita l'accesso a
[link:https://developer.mozilla.org/en-US/docs/Web/API/WebGLRenderingContext/copyTexImage2D WebGLRenderingContext.copyTexImage2D].
Expand Down
2 changes: 1 addition & 1 deletion docs/api/zh/renderers/WebGLRenderer.html
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ <h3>[method:Promise compileAsync]( [param:Object3D scene], [param:Camera camera]
此方法利用 *KHR_parallel_shader_compile*。
</p>

<h3>[method:undefined copyFramebufferToTexture]( [param:Vector2 position], [param:FramebufferTexture texture], [param:Number level] )</h3>
<h3>[method:undefined copyFramebufferToTexture]( [param:FramebufferTexture texture], [param:Vector2 position], [param:Number level] )</h3>
<p>将当前WebGLFramebuffer中的像素复制到2D纹理中。可访问[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:Vector2 dstPosition], [param:Number level] )</h3>
Expand Down
2 changes: 1 addition & 1 deletion docs/api/zh/textures/FramebufferTexture.html
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ <h1>帧缓冲纹理([name])</h1>
renderer.render( scene, camera );

// copy part of the rendered frame into the framebuffer texture
renderer.copyFramebufferToTexture( vector, frameTexture );
renderer.copyFramebufferToTexture( frameTexture, vector );
</code>

<h2>例子</h2>
Expand Down
4 changes: 2 additions & 2 deletions examples/jsm/objects/Lensflare.js
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ class Lensflare extends Mesh {

// save current RGB to temp texture

renderer.copyFramebufferToTexture( screenPositionPixels, tempMap );
renderer.copyFramebufferToTexture( tempMap, screenPositionPixels );

// render pink quad

Expand All @@ -222,7 +222,7 @@ class Lensflare extends Mesh {

// copy result to occlusionMap

renderer.copyFramebufferToTexture( screenPositionPixels, occlusionMap );
renderer.copyFramebufferToTexture( occlusionMap, screenPositionPixels );

// restore graphics

Expand Down
2 changes: 1 addition & 1 deletion examples/webgl_framebuffer_texture.html
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@
vector.x = ( window.innerWidth * dpr / 2 ) - ( textureSize / 2 );
vector.y = ( window.innerHeight * dpr / 2 ) - ( textureSize / 2 );

renderer.copyFramebufferToTexture( vector, texture );
renderer.copyFramebufferToTexture( texture, vector );

renderer.clearDepth();
renderer.render( sceneOrtho, cameraOrtho );
Expand Down
18 changes: 16 additions & 2 deletions src/renderers/WebGLRenderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -2436,15 +2436,29 @@ class WebGLRenderer {

};

this.copyFramebufferToTexture = function ( position, texture, level = 0 ) {
this.copyFramebufferToTexture = function ( texture, position = null, level = 0 ) {
Mugen87 marked this conversation as resolved.
Show resolved Hide resolved

// support previous signature with position first
if ( texture.isTexture !== true ) {

// @deprecated, r165
console.warn( 'WebGLRenderer: copyFramebufferToTexture function signature has changed.' );

position = arguments[ 0 ] || null;
texture = arguments[ 1 ];

}

const levelScale = Math.pow( 2, - level );
const width = Math.floor( texture.image.width * levelScale );
const height = Math.floor( texture.image.height * levelScale );

const x = position !== null ? position.x : 0;
const y = position !== null ? position.y : 0;

textures.setTexture2D( texture, 0 );

_gl.copyTexSubImage2D( _gl.TEXTURE_2D, level, 0, 0, position.x, position.y, width, height );
_gl.copyTexSubImage2D( _gl.TEXTURE_2D, level, 0, 0, x, y, width, height );

state.unbindTexture();

Expand Down