Resizing Render Texture

Hello Community!

I’ve been trying to make a paint-like environment using Phaser and Render Textures.
It seems that everytime I resize or setSize to the RenderTexture, my drawings are destroyed.

According to Phaser’s RenderTexture resize method source code:

this.renderer.deleteTexture(this.frame.source.glTexture);
this.renderer.deleteFramebuffer(this.framebuffer);

this.frame.source.glTexture = this.renderer.createTexture2D(0, gl.NEAREST, gl.NEAREST, gl.CLAMP_TO_EDGE, gl.CLAMP_TO_EDGE, gl.RGBA, null, width, height, false);
this.framebuffer = this.renderer.createFramebuffer(width, height, this.frame.source.glTexture, false);

this.frame.glTexture = this.frame.source.glTexture;

The example in Phaser 3 Examples page is broken and outdated.
Is there a way I could get a hold to what’s been drawn, resize and then redraw it?

Hi @falc,
Before resize, you could draw the render texture in another.
Something like:

// rt1: render texture to resize
// rt2: helper render texture
function resizeRt(rt1, rt2, width, height) {
  rt2.clear();
  rt2.draw(rt1, 0, 0);
  rt1.resize(width, height);
  rt1.draw(rt2, 0, 0);
}

Regards.