openglglslshaderfbomultipass

OpenGL: Multipass Rendering using Frame Buffer Objects


While developing a small 2D engine, I stumbled across a little design problem which I'm unfortunately with my level of knowledge unable to solve without the help of you.

Let me explain: The game I'm developing the 2D engine for should contain complex effects, which likely would require multiple render passes. The problem is, I'm not sure if I understood the concept of multipass rendering right.

At this level of knowledge, I would implement it this way:

  1. Initially create, setup (attach it to a texture, ...) and bind a frame buffer object
  2. Now render the stuff onto which the effect should be applied to the FBO's attached texture
  3. Render that texture to the same FBO by using the shader for the first pass
  4. Unbind the FBO and render the attached texture to the standard FBO by using the shader for the last pass

The question is now if this is the most efficent way of solving my problem, or if there are any better ways of doing this out there.


Solution

  • Render that texture to the same FBO by using the shader for the first pass

    You cannot simultaneously read from and write to the same image in the same texture. Well, you can, but you get undefined behavior, which probably isn't helpful. So you need to either use multiple textures or perhaps use NV_texture_barrier where available.