Copy FBO to another texture? Or similar?

Hi

I need to use the FBO destination texture as a source texture for the next frame, how can I do this most efficiently? (Without reuploading the texture between CPU ad GpU every frame)

I’m trying to implement destroyable 2d pixel terrain.
The first frame I render the original background texture to FBO and then draw all the deformations using primitives with alpha value set to 0. It works - holes appear in the result.
The second frame, I have to use the texture generated in the FBO last frame, as the source texture for this frame. If I used the original background texture again, my changes would be lost.

Any help would be appreciated

Sounds like standard render to texture :
http://www.opengl.org/wiki/GL_EXT_framebuffer_object

I know how to render to a texture using FBO, it’s working just fine.

What I don’t understand, is how to assign the destination texture of the FBO as it’s source texture.

Steps:
First frame: Select the FBO, Draw ORIGINAL texture, Draw holes, Draw the FBO texture to screen
Second frame: Select the FBO, Draw (first frames’s)FBO texture, Draw even more holes, Draw the FBO texture to screen.
Third frame: Select the FBO, Draw (second frames’s)FBO texture, Draw some more holes, Draw the FBO texture to screen

If I try to Draw the FBO render-target texture, while the FBO is rendering to that same texture, I get white screen.

I need to buffer the texture, so that there are 2 copies, and no “access violation” while I do the FBO render-to-texture operation.

Please help

Bind texture to a sampler/texture unit, and reference the sampler in a shader.

I need to buffer the texture, so that there are 2 copies, and no “access violation” while I do the FBO render-to-texture operation.

Yes. Sounds like you’ll want two textures (or two layers of a texture array) to ping-ping with.

Consider applying your deformations (holes) to the original texture directly: by rendering them (optionally with some sort of blending) into it. This will not require 2 buffers to keep.

Yes. Sounds like you’ll want two textures (or two layers of a texture array) to ping-ping with.

Could you please specify what do mean by that? Especially the ping part =)

Yes, that would be perfect, but how can I render to an already existing texture? I can’t use FBO for that, because can’t render a texture while it’s bound to FBO, right?

Could you please specify what do mean by that? Especially the ping part =)

Have 2 textures A and B.
First frame: A->B, using B.
Second frame: B->A, using A.
and so on

Yes, that would be perfect, but how can I render to an already existing texture? I can’t use FBO for that, because can’t render a texture while it’s bound to FBO, right?

You can’t draw to the texture and use it at the same time.
But if you draw holes - you might not need original texture at all.
Just try to play with different blending functions.