LWJGL Forum

Programming => OpenGL => Topic started by: CodeBunny on March 17, 2012, 16:53:53

Title: Can I read from a framebuffer while drawing to it?
Post by: CodeBunny on March 17, 2012, 16:53:53
Yes, I know I cannot read and write to a target from within a shader. This is slightly different. Can I have a single framebuffer, render different passes to different sections of it, and then render the final version to
another section?

A simple graphic illustrating what I'm trying to do:
(http://i.imgur.com/kJkeC.png)
Title: Re: Can I read from a framebuffer while drawing to it?
Post by: spasi on March 17, 2012, 18:06:41
Two options:

- NV_texture_barrier (http://www.opengl.org/registry/specs/NV/texture_barrier.txt): Widely supported on NV/AMD, has limitations.
- ARB_shader_image_load_store (http://www.opengl.org/registry/specs/ARB/shader_image_load_store.txt): More advanced, but supported on DX11+ GPUs only.
Title: Re: Can I read from a framebuffer while drawing to it?
Post by: CodeBunny on March 17, 2012, 21:30:44
So, in a generally-supported sense, no?
Title: Re: Can I read from a framebuffer while drawing to it?
Post by: spasi on March 17, 2012, 22:00:39
Why do you want to render this way anyway? Why not have a texture that holds the 3 render passes (like [1][2][3]) and then perform the combined render pass on the backbuffer directly?
Title: Re: Can I read from a framebuffer while drawing to it?
Post by: CodeBunny on March 18, 2012, 14:04:27
Efficiency experiments. That's actually what I'm doing currently, and I'm trying to improve my render process.

For one thing, I'm using pixel scaling, so the actual scene I'm rendering is 2-4x smaller than the view. The shader I use to combine the render passes is expensive, so it occurred to me that rendering to a smaller texture first, and then just using a straight replace blend function would probably be the fastest method.

Additionally, it seemed like I could be most efficient memory-wise if I combined my framebuffers onto a single texture. I try to minimize PoT overflow as much as I can.