From a2f0682268790cbd5ed09e29c640b13b9d5afafa Mon Sep 17 00:00:00 2001 From: Renaud Rohlinger Date: Fri, 10 May 2024 17:56:31 +0900 Subject: [PATCH] WebGLRenderer: Update `copyFramebufferToTexture` function signature (#28329) * update signature * add defualt x,y --- docs/api/ar/renderers/WebGLRenderer.html | 2 +- docs/api/en/renderers/WebGLRenderer.html | 2 +- docs/api/en/textures/FramebufferTexture.html | 2 +- docs/api/it/renderers/WebGLRenderer.html | 2 +- docs/api/zh/renderers/WebGLRenderer.html | 2 +- docs/api/zh/textures/FramebufferTexture.html | 2 +- examples/jsm/objects/Lensflare.js | 4 ++-- examples/webgl_framebuffer_texture.html | 2 +- src/renderers/WebGLRenderer.js | 18 ++++++++++++++++-- 9 files changed, 25 insertions(+), 11 deletions(-) diff --git a/docs/api/ar/renderers/WebGLRenderer.html b/docs/api/ar/renderers/WebGLRenderer.html index f657790afac7b..12891aefa8336 100644 --- a/docs/api/ar/renderers/WebGLRenderer.html +++ b/docs/api/ar/renderers/WebGLRenderer.html @@ -369,7 +369,7 @@

- [method:undefined copyFramebufferToTexture]( [param:Vector2 position], [param:FramebufferTexture texture], [param:Number level] ) + [method:undefined copyFramebufferToTexture]( [param:FramebufferTexture texture], [param:Vector2 position], [param:Number level] )

ينسخ بكسلات من WebGLFramebuffer الحالي إلى قوام ثنائي الأبعاد. يتيح diff --git a/docs/api/en/renderers/WebGLRenderer.html b/docs/api/en/renderers/WebGLRenderer.html index e72270f4e17fa..e2fed603791b2 100644 --- a/docs/api/en/renderers/WebGLRenderer.html +++ b/docs/api/en/renderers/WebGLRenderer.html @@ -367,7 +367,7 @@

- [method:undefined copyFramebufferToTexture]( [param:Vector2 position], [param:FramebufferTexture texture], [param:Number level] ) + [method:undefined copyFramebufferToTexture]( [param:FramebufferTexture texture], [param:Vector2 position], [param:Number level] )

Copies pixels from the current WebGLFramebuffer into a 2D texture. Enables diff --git a/docs/api/en/textures/FramebufferTexture.html b/docs/api/en/textures/FramebufferTexture.html index 3ab666b592a99..7864770d75624 100644 --- a/docs/api/en/textures/FramebufferTexture.html +++ b/docs/api/en/textures/FramebufferTexture.html @@ -33,7 +33,7 @@

[name]

renderer.render( scene, camera ); // copy part of the rendered frame into the framebuffer texture -renderer.copyFramebufferToTexture( vector, frameTexture ); +renderer.copyFramebufferToTexture( frameTexture, vector );

Examples

diff --git a/docs/api/it/renderers/WebGLRenderer.html b/docs/api/it/renderers/WebGLRenderer.html index f4073d6001078..c6b84a5e86e36 100644 --- a/docs/api/it/renderers/WebGLRenderer.html +++ b/docs/api/it/renderers/WebGLRenderer.html @@ -321,7 +321,7 @@

[method:Promise compileAsync]( [param:Object3D scene], [param:Camera camera] Questo metodo utilizza *KHR_parallel_shader_compile*.

-

[method:undefined copyFramebufferToTexture]( [param:Vector2 position], [param:FramebufferTexture texture], [param:Number level] )

+

[method:undefined copyFramebufferToTexture]( [param:FramebufferTexture texture], [param:Vector2 position], [param:Number level] )

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]. diff --git a/docs/api/zh/renderers/WebGLRenderer.html b/docs/api/zh/renderers/WebGLRenderer.html index 1f2660c433ccc..118d1341dbd8b 100644 --- a/docs/api/zh/renderers/WebGLRenderer.html +++ b/docs/api/zh/renderers/WebGLRenderer.html @@ -281,7 +281,7 @@

[method:Promise compileAsync]( [param:Object3D scene], [param:Camera camera] 此方法利用 *KHR_parallel_shader_compile*。

-

[method:undefined copyFramebufferToTexture]( [param:Vector2 position], [param:FramebufferTexture texture], [param:Number level] )

+

[method:undefined copyFramebufferToTexture]( [param:FramebufferTexture texture], [param:Vector2 position], [param:Number level] )

将当前WebGLFramebuffer中的像素复制到2D纹理中。可访问[link:https://developer.mozilla.org/en-US/docs/Web/API/WebGLRenderingContext/copyTexImage2D WebGLRenderingContext.copyTexImage2D].

[method:undefined copyTextureToTexture]( [param:Texture srcTexture], [param:Texture dstTexture], [param:Box2 srcRegion], [param:Vector2 dstPosition], [param:Number level] )

diff --git a/docs/api/zh/textures/FramebufferTexture.html b/docs/api/zh/textures/FramebufferTexture.html index a68d0e8f8c4ea..af0ed51068b86 100644 --- a/docs/api/zh/textures/FramebufferTexture.html +++ b/docs/api/zh/textures/FramebufferTexture.html @@ -32,7 +32,7 @@

帧缓冲纹理([name])

renderer.render( scene, camera ); // copy part of the rendered frame into the framebuffer texture - renderer.copyFramebufferToTexture( vector, frameTexture ); + renderer.copyFramebufferToTexture( frameTexture, vector );

例子

diff --git a/examples/jsm/objects/Lensflare.js b/examples/jsm/objects/Lensflare.js index 6bbec633618f0..58e7d2771721d 100644 --- a/examples/jsm/objects/Lensflare.js +++ b/examples/jsm/objects/Lensflare.js @@ -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 @@ -222,7 +222,7 @@ class Lensflare extends Mesh { // copy result to occlusionMap - renderer.copyFramebufferToTexture( screenPositionPixels, occlusionMap ); + renderer.copyFramebufferToTexture( occlusionMap, screenPositionPixels ); // restore graphics diff --git a/examples/webgl_framebuffer_texture.html b/examples/webgl_framebuffer_texture.html index 59528712b5dae..e7f97e98e33cc 100644 --- a/examples/webgl_framebuffer_texture.html +++ b/examples/webgl_framebuffer_texture.html @@ -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 ); diff --git a/src/renderers/WebGLRenderer.js b/src/renderers/WebGLRenderer.js index 38c6facf3718c..d12b90e5b94e8 100644 --- a/src/renderers/WebGLRenderer.js +++ b/src/renderers/WebGLRenderer.js @@ -2436,15 +2436,29 @@ class WebGLRenderer { }; - this.copyFramebufferToTexture = function ( position, texture, level = 0 ) { + this.copyFramebufferToTexture = function ( texture, position = null, level = 0 ) { + + // 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();