Situation
I am writing an image compositor, and I am using FBOs.
As gl can not read a texture that it is currently writing to, currently I am using a pseudo "Fbo Flip Chain" logic. I create a list of about 10 FBO and each time I render I move to the next FBO which can happily read from one of the previous FBO textures.
However this is deeply flawed because of the way I am currently doing my composting an fbo can be overwritten when it is still needed in its current state. I tied a "locking/unlocking" logic but it is flakey.
An image currently goes through the following stages:
- Draw The Image to a texture (using fbo)
- fbo flip
- Composite all of the Images "children" onto image
- fbo flip for each child this is the issue
- convert the image to the destination type
- fbo flip
- Blend the image with its destination
- fbo flip
- pass texture along for composting with siblings
I have decided to re-factor this flip chain-compositing idea. The way I see it, it would be better to do one of the following:
Possible Solutions
- Each image would contain its own multiple fbos, each with its own render target, switching to a designated fbo at each stage*
- Each Image would contain one fbo and mutiple texture targets, changing the attachment for each stage*
- Each image would have 2 render targets ("front", "back"), there would be 1 master fbo and the master fbo would overwrite the "front" texture, while reading from the "back" texture (thinking more like a back buffer and a front buffer). At the end of each stage* swap them over.
*(each stage = where a flip is currently performed)
I am currently leaning towards number 2, each image would end up with 4/5 textures, that would be designated to each stage. And when the image is "drawn" it can test if it can start its draw from a different stage.
e.g. the image has been drawn and is already converted to the correct type, so take the "post_convert" texture and just blend.
Issues:
- I am unsure which is quicker, attaching and detaching render targets. or binding FBOs...
- There is an awful lot of textures and fbos being thrown around at the moment. And I am very wary of the fact that I am programming with GL in C# so I need to nail down a system of managing the gl memory alongside C#s GC.