diff --git a/docs/api/en/renderers/WebGLRenderer.html b/docs/api/en/renderers/WebGLRenderer.html index 11af5a9b892bcd..cef67b7dbd6241 100644 --- a/docs/api/en/renderers/WebGLRenderer.html +++ b/docs/api/en/renderers/WebGLRenderer.html @@ -370,22 +370,13 @@

This method makes use of the *KHR_parallel_shader_compile* WebGL extension.

-

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

-

- 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]. -

-

[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] )

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.
- The `depthTexture` and `texture` property of render targets are supported as well.
+ 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.
When using render target textures as `srcTexture` and `dstTexture`, you must make sure both render targets are initialized e.g. via [page:.initRenderTarget]().

diff --git a/docs/api/en/textures/FramebufferTexture.html b/docs/api/en/textures/FramebufferTexture.html deleted file mode 100644 index 7864770d756241..00000000000000 --- a/docs/api/en/textures/FramebufferTexture.html +++ /dev/null @@ -1,98 +0,0 @@ - - - - - - - - - - [page:Texture] → - -

[name]

- -

- This class can only be used in combination with - [page:WebGLRenderer.copyFramebufferToTexture](). -

- - -const pixelRatio = window.devicePixelRatio; -const textureSize = 128 * pixelRatio; - -// instantiate a framebuffer texture -const frameTexture = new FramebufferTexture( textureSize, textureSize ); - -// calculate start position for copying part of the frame data -const vector = new Vector2(); -vector.x = ( window.innerWidth * pixelRatio / 2 ) - ( textureSize / 2 ); -vector.y = ( window.innerHeight * pixelRatio / 2 ) - ( textureSize / 2 ); - -// render the scene -renderer.clear(); -renderer.render( scene, camera ); - -// copy part of the rendered frame into the framebuffer texture -renderer.copyFramebufferToTexture( frameTexture, vector ); - - -

Examples

- -

[example:webgl_framebuffer_texture]

- -

Constructor

- -

- [name]( [param:Number width], [param:Number height] ) -

-

- [page:Number width] -- The width of the texture.
- - [page:Number height] -- The height of the texture. -

- -

Properties

- -

See the base [page:Texture Texture] class for common properties.

- -

[property:Boolean generateMipmaps]

-

Whether to generate mipmaps for the [name]. Default value is `false`.

- -

[property:Boolean isFramebufferTexture]

-

Read-only flag to check if a given object is of type [name].

- -

[property:number magFilter]

-

- How the texture is sampled when a texel covers more than one pixel. The - default is [page:Textures THREE.NearestFilter], which uses the value of - the closest texel. -

- - See [page:Textures texture constants] for details. -

- -

[property:number minFilter]

-

- How the texture is sampled when a texel covers less than one pixel. The - default is [page:Textures THREE.NearestFilter], which uses the value of - the closest texel. -

- - See [page:Textures texture constants] for details. -

- -

[property:Boolean needsUpdate]

- -

True by default. This is required so that the canvas data is loaded.

- -

Methods

- -

See the base [page:Texture Texture] class for common methods.

- -

Source

- -

- [link:https://github.com/mrdoob/three.js/blob/master/src/[path].js src/[path].js] -

- - diff --git a/docs/api/it/textures/FramebufferTexture.html b/docs/api/it/textures/FramebufferTexture.html deleted file mode 100644 index 390bb5a6df839b..00000000000000 --- a/docs/api/it/textures/FramebufferTexture.html +++ /dev/null @@ -1,56 +0,0 @@ - - - - - - - - - - [page:Texture] → - -

[name]

- -

- Questa classe può solo essere utilizzata in combinazione con [page:WebGLRenderer.copyFramebufferToTexture](). -

- -

Costruttore

-

[name]( [param:Number width], [param:Number height] )

-

- [page:Number width] -- La larghezza della texture.
- - [page:Number height] -- L'altezza della texture. -

- -

Proprietà

- -

- Vedi la classe base [page:Texture Texture] per le proprietà comuni. -

- -

[property:Boolean isFramebufferTexture]

-

- Flag di sola lettura per verificare se l'oggetto dato è di tipo [name]. -

- -

[property:Boolean needsUpdate]

- -

- True da impostazione predefinita. Ciò è necessario affinché i dati del canvas vengano caricati. -

- -

Metodi

- -

- Vedi la classe base [page:Texture Texture] per i metodi comuni. -

- - -

Source

- -

- [link:https://github.com/mrdoob/three.js/blob/master/src/[path].js src/[path].js] -

- - diff --git a/docs/api/zh/textures/FramebufferTexture.html b/docs/api/zh/textures/FramebufferTexture.html deleted file mode 100644 index af0ed51068b867..00000000000000 --- a/docs/api/zh/textures/FramebufferTexture.html +++ /dev/null @@ -1,93 +0,0 @@ - - - - - - - - - - [page:Texture] → - -

帧缓冲纹理([name])

- -

- 这个类只能与 [page:WebGLRenderer.copyFramebufferToTexture]() 结合使用。 -

- - - const pixelRatio = window.devicePixelRatio; - const textureSize = 128 * pixelRatio; - - // instantiate a framebuffer texture - const frameTexture = new FramebufferTexture( textureSize, textureSize ); - - // calculate start position for copying part of the frame data - const vector = new Vector2(); - vector.x = ( window.innerWidth * pixelRatio / 2 ) - ( textureSize / 2 ); - vector.y = ( window.innerHeight * pixelRatio / 2 ) - ( textureSize / 2 ); - - // render the scene - renderer.clear(); - renderer.render( scene, camera ); - - // copy part of the rendered frame into the framebuffer texture - renderer.copyFramebufferToTexture( frameTexture, vector ); - - -

例子

- -

[example:webgl_framebuffer_texture]

- -

构造函数

-

[name]( [param:Number width], [param:Number height] )

-

- [page:Number width] -- 纹理的宽度
- - [page:Number height] -- 纹理的高度

- -

- - -

属性

- -

共有属性请参见其基类 [page:Texture Texture]

- -

[property:Boolean generateMipmaps]

-

是否为 [name] 生成 mipmaps ,默认为`false`

- -

[property:Boolean isFramebufferTexture]

-

只读,检查给定对象是否为 [name] 类型

- -

[property:number magFilter]

-

- 纹理元素覆盖多个像素时如何对纹理进行采样。默认值为 [page:Textures THREE.NearestFilter] ,它使用最接近的纹理元素。 -

- - 更多细节详见 [page:Textures texture constants] -

- -

[property:number minFilter]

-

- 纹理元素覆盖少于一个像素时如何对纹理进行采样。默认值为 [page:Textures THREE.NearestFilter] ,它使用最近的纹理元素。 -

- - 更多细节详见 [page:Textures texture constants] -

- -

[property:Boolean needsUpdate]

- -

默认为 `true` ,这是加载 canvas 数据所必需的

- -

方法

- -

共有方法请参见其基类 [page:Texture Texture]

- - -

源代码

- -

- [link:https://github.com/mrdoob/three.js/blob/master/src/[path].js src/[path].js] -

- - diff --git a/examples/webgl_framebuffer_texture.html b/examples/webgl_framebuffer_texture.html index e7f97e98e33cc7..cb40a29b9a5a32 100644 --- a/examples/webgl_framebuffer_texture.html +++ b/examples/webgl_framebuffer_texture.html @@ -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(); @@ -103,7 +103,8 @@ // - texture = new THREE.FramebufferTexture( textureSize, textureSize ); + texture = new THREE.DataTexture( new Uint8Array( textureSize * textureSize * 4 ), textureSize, textureSize ); + texture.needsUpdate = true; // @@ -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 ); diff --git a/src/renderers/WebGLRenderer.js b/src/renderers/WebGLRenderer.js index 5c25de2cde1fb5..8680d4c7b7d631 100644 --- a/src/renderers/WebGLRenderer.js +++ b/src/renderers/WebGLRenderer.js @@ -54,6 +54,7 @@ import { WebGLMaterials } from './webgl/WebGLMaterials.js'; import { WebGLUniformsGroups } from './webgl/WebGLUniformsGroups.js'; import { createCanvasElement, probeAsync, toNormalizedProjectionMatrix, toReversedProjectionMatrix, warnOnce } from '../utils.js'; import { ColorManagement } from '../math/ColorManagement.js'; +import { Box2 } from '../math/Box2.js'; class WebGLRenderer { @@ -2548,18 +2549,16 @@ class WebGLRenderer { } - 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 ); + // @deprecated, r170 + warnOnce( 'WebGLRenderer: copyFramebufferToTexture function has been deprecated. Use copyTextureToTexture instead.' ); - _gl.copyTexSubImage2D( _gl.TEXTURE_2D, level, 0, 0, x, y, width, height ); + const box = new Box2(); + box.min.copy( position ); + box.max.copy( position ); + box.max.x += texture.image.width; + box.max.y += texture.image.height; - state.unbindTexture(); + this.copyTextureToTexture( null, texture, box, undefined, 0, level ); }; @@ -2568,7 +2567,7 @@ class WebGLRenderer { this.copyTextureToTexture = function ( srcTexture, dstTexture, srcRegion = null, dstPosition = null, srcLevel = 0, dstLevel = null ) { // support previous signature with dstPosition first - if ( srcTexture.isTexture !== true ) { + if ( srcTexture && srcTexture.isTexture !== true ) { // @deprecated, r165 warnOnce( 'WebGLRenderer: copyTextureToTexture function signature has changed.' ); @@ -2599,10 +2598,29 @@ class WebGLRenderer { } + // set up the src texture + let isSrc3D = false; + const isDst3D = dstTexture.isDataArrayTexture || dstTexture.isData3DTexture; + // 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; + let image, imageWidth, imageHeight; + if ( srcTexture !== null ) { + + image = srcTexture.isCompressedTexture ? srcTexture.mipmaps[ dstLevel ] : srcTexture.image; + imageWidth = image.width; + imageHeight = image.height; + isSrc3D = srcTexture.isDataArrayTexture || srcTexture.isData3DTexture; + + } else { + + image = null; + imageWidth = _width; + imageHeight = _height; + + } + if ( srcRegion !== null ) { width = srcRegion.max.x - srcRegion.min.x; @@ -2615,13 +2633,13 @@ class WebGLRenderer { } else { const levelScale = Math.pow( 2, - srcLevel ); - width = Math.floor( image.width * levelScale ); - height = Math.floor( image.height * levelScale ); - if ( srcTexture.isDataArrayTexture ) { + width = Math.floor( imageWidth * levelScale ); + height = Math.floor( imageHeight * levelScale ); + if ( srcTexture && srcTexture.isDataArrayTexture ) { depth = image.depth; - } else if ( srcTexture.isData3DTexture ) { + } else if ( srcTexture && srcTexture.isData3DTexture ) { depth = Math.floor( image.depth * levelScale ); @@ -2683,17 +2701,23 @@ class WebGLRenderer { const currentUnpackSkipPixels = _gl.getParameter( _gl.UNPACK_SKIP_PIXELS ); const currentUnpackSkipRows = _gl.getParameter( _gl.UNPACK_SKIP_ROWS ); const currentUnpackSkipImages = _gl.getParameter( _gl.UNPACK_SKIP_IMAGES ); - - _gl.pixelStorei( _gl.UNPACK_ROW_LENGTH, image.width ); - _gl.pixelStorei( _gl.UNPACK_IMAGE_HEIGHT, image.height ); + _gl.pixelStorei( _gl.UNPACK_ROW_LENGTH, imageWidth ); + _gl.pixelStorei( _gl.UNPACK_IMAGE_HEIGHT, imageHeight ); _gl.pixelStorei( _gl.UNPACK_SKIP_PIXELS, minX ); _gl.pixelStorei( _gl.UNPACK_SKIP_ROWS, minY ); _gl.pixelStorei( _gl.UNPACK_SKIP_IMAGES, minZ ); - // set up the src texture - const isSrc3D = srcTexture.isDataArrayTexture || srcTexture.isData3DTexture; - const isDst3D = dstTexture.isDataArrayTexture || dstTexture.isData3DTexture; - if ( srcTexture.isDepthTexture ) { + if ( srcTexture === null ) { + + 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 ); + + } else if ( srcTexture.isDepthTexture ) { const srcTextureProperties = properties.get( srcTexture ); const dstTextureProperties = properties.get( dstTexture ); diff --git a/src/textures/FramebufferTexture.js b/src/textures/FramebufferTexture.js index db87092f614e41..2785928adb724b 100644 --- a/src/textures/FramebufferTexture.js +++ b/src/textures/FramebufferTexture.js @@ -1,5 +1,6 @@ import { Texture } from './Texture.js'; import { NearestFilter } from '../constants.js'; +import { warnOnce } from '../utils.js'; class FramebufferTexture extends Texture { @@ -16,6 +17,9 @@ class FramebufferTexture extends Texture { this.needsUpdate = true; + // @deprecated r170 + warnOnce( 'FramebufferTexture: FramebufferTexture has been deprecated. Use any other texture with copyTextureToTexture, instead.' ); + } }