Error from copyTextureToTexture (Overload resolution)

I want to use copyTextureToTexture, but get this error:

TypeError: Failed to execute ‘texSubImage2D’ on ‘WebGL2RenderingContext’: Overload resolution failed."

I’m using a render target as the source, on r160.

Full example:

On line 2414 of WebGLRenderer in r160, renderer.copyTextureToTexture does:

```_gl.texSubImage2D( _gl.TEXTURE_2D, level, position.x, position.y, glFormat, glType, srcTexture.image );```

which is a WebGL1 signature removed in WebGL2:
texSubImage2D(target, level, xoffset, yoffset, format, type, pixels)
So it’s just missing the width and height parameters.

Is that a mistake?

I’ve never been in this part of Three.js, so the next two sentences might be wrong:

For your scenario, would it be possible to use .copyFramebufferToTexture instead of .copyTextureToTexture? When I try it there is no error … but also nothing is shown on the screen (maybe because the demo is not complete?)

PS. When I check the render target texture, it has no image. I don’t know whether this is OK or not. The .image property usually appears when a texture is loaded from file. For fremebuffer textures it might be different situation.

If I click the jsfiddle link, I immediately see this error. Is it different for you?

Copy framebuffer did not work for me, but I did find a workaround doing this:

renderer.readRenderTargetPixels( target, 0, 0, size, size, buffer );
new THREE.DataTexture(buffer, size, size);

I think this is a mistake in the threejs code though.

With .copyTextureToTexture I see the same error message.
With .copyFramebufferToTexture I see no error message.

It’s good that you’ve found a workaround that works for you. If you think this is a bug in Three.js, it is better to post it in the Three.js issue tracker on Github.

However, also look at WebGLRenderer: Calling "copyTextureToTexture" on an unused WebGLRenderTarget does nothing · Issue #28282 · mrdoob/three.js · GitHub

Thanks for the relevant info, but in this case it’s clear that the target is initialized since calling renderer.setTarget and then renderer.render before copyTextureToTexture. I’ll put an issue up on github.