diff --git a/docs/api/en/renderers/WebGLRenderTarget.html b/docs/api/en/renderers/WebGLRenderTarget.html index 6f4c43dc55bd6b..407f4ccaa7c944 100644 --- a/docs/api/en/renderers/WebGLRenderTarget.html +++ b/docs/api/en/renderers/WebGLRenderTarget.html @@ -133,7 +133,11 @@

[method:WebGLRenderTarget clone]()

Creates a copy of this render target.

[method:this copy]( [param:WebGLRenderTarget source] )

-

Adopts the settings of the given render target.

+

+ Adopts the settings of the given render target. This is a structural copy so + no resources are shared between render targets after the copy. That includes + all MRT textures and the depth texture. +

[method:undefined dispose]()

diff --git a/src/core/RenderTarget.js b/src/core/RenderTarget.js index 30ce82d62558b0..4ee5be6c634308 100644 --- a/src/core/RenderTarget.js +++ b/src/core/RenderTarget.js @@ -148,12 +148,12 @@ class RenderTarget extends EventDispatcher { this.textures[ i ].isRenderTargetTexture = true; this.textures[ i ].renderTarget = this; - } + // ensure image object is not shared, see #20328 - // ensure image object is not shared, see #20328 + const image = Object.assign( {}, source.textures[ i ].image ); + this.textures[ i ].source = new Source( image ); - const image = Object.assign( {}, source.texture.image ); - this.texture.source = new Source( image ); + } this.depthBuffer = source.depthBuffer; this.stencilBuffer = source.stencilBuffer; diff --git a/src/textures/DepthTexture.js b/src/textures/DepthTexture.js index ddbb3fb9b5603b..ff91d0f876e320 100644 --- a/src/textures/DepthTexture.js +++ b/src/textures/DepthTexture.js @@ -1,3 +1,4 @@ +import { Source } from './Source.js'; import { Texture } from './Texture.js'; import { NearestFilter, UnsignedIntType, UnsignedInt248Type, DepthFormat, DepthStencilFormat } from '../constants.js'; @@ -35,6 +36,7 @@ class DepthTexture extends Texture { super.copy( source ); + this.source = new Source( Object.assign( {}, source.image ) ); // see #30540 this.compareFunction = source.compareFunction; return this;