Why the TextureCanvas is rendered two times?

Hello everyone,

i noticed that when a TextureCanvas is created it is added two times to the scene. If i set a name to generated TextureCanvas it is possible see that there are two textures (“no name” and “textureCanvas”) in the section “Scene Explorer > Scene > Textures” of the inspector.

The problem is reproducible in the official playground adding the property name and activating the inspector:

https://playground.babylonjs.com/#9S5YZY#53

Why is created the “no name” texture?

Thanks,
SimoneDev

Welcome aboard!

Pinging @Gijs who created this extension.

3 Likes

Hi @SimoneDev, when something is drawn onto the TextureCanvas, it actually gets drawn on the back buffer (“no name”), which then gets copied to “textureCanvas”. It was made this way to have the texture shader use itself as a texture sampler for the background, because sampling and rendering itself at the same time doesn’t work.

This is the shader that draws something onto “no name”, where “backgroundSampler” is “textureCanvas”:

1 Like

Hi @Gijs, thank you. My problem is that, when i dispose the TextureCanvas, the back buffer is not disposed. So i created a pull request in which i dispose the back buffer before to dispose the TextureCanvas; i also provide a property name for the TextureCanvas and his back buffer to easily identify them in the inspector.

This is the pull request:
Add the name property and dispose the back buffer by simonedevit · Pull Request #1 · Poolminer/BabylonTextureCanvas · GitHub

What do you think about it?

Thanks,
SimoneDev

1 Like

Thanks for the help @SimoneDev, it looks like the best solution, so I’ve accepted it! It’s too bad we can’t use a setter for the name though for changing the name later on, to also change the backbuffer name.

1 Like