The Khronos Group - a non-profit industry consortium to develop, publish and promote open standard, royalty-free media authoring and acceleration standards for desktop and handheld devices, combined with conformance qualification programs for platform and device interoperability.

If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

Render to / and use texture

Hi,

I'm trying to create a cummulative effect in which new data is added to the framebuffer on each frame.
Ideally I would like to render the first frame to a texture and then use this texture as the background for the next, add the 2nd frame to it and so on...

Doe anybody know if this is possible using (only) vertex/fragment shaders in WebGL? I guess I can probably read back the texture and download it again, but I expect to have some performance issues doing this.

Re: Render to / and use texture

Ideally, you want to render to an FBO so you can read that into a texture on the following frame. However, because you're not allowed to read and write from the same texture at the same time, you will need to do a double-buffer arrangement. So create two texture/FBO's (let's call them A & B).

Bind A as a texture, set B as the render target.
Draw your new effect into B, merging in A as you go.
Bind B as a texture, copy it onto the screen by drawing a screen-sized quad.
Swap A and B.
Repeat.