three.jsclonerender-to-texturerendertarget

Cloning a texture created with THREE.WebGLRenderTarget


I'm using three.js and I need to create a few clones of a texture made with THREE.WebGLRenderTarget().

I can use the original texture, e.g.:

scene.background = renderTarget.texture;

But if I try to use a clone of it:

const tex = renderTarget.texture.clone(); scene.background = tex;

I get the following error:

THREE.WebGLState: TypeError: Failed to execute 'texSubImage2D' on 'WebGL2RenderingContext': Overload resolution failed.

If I add the line:

tex.isRenderTargetTexture = true;

Now I don't get any error, but the texture is all black.

I have also tried to clone the render target (instead of its texture) but it didn't work either. Can you please help me?

Thank you in advance.


Solution

  • Problem solved: I created a framebuffer texture, and I copied the texture by using method renderer.copyFramebufferToTexture() of class THREE.WebGLRenderer.