Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: OpenGL FBO rendering - when to call glFlush()  (Read 5054 times)

0 Members and 1 Guest are viewing this topic.

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6286
  • Thor Developer
    • View Profile
    • Bromeon
OpenGL FBO rendering - when to call glFlush()
« on: June 05, 2013, 09:38:53 am »
This question is not directly related to SFML, more to OpenGL.

If I have two FBOs and switch them alternately to render with a shader multiple times, do I need to call glFlush() before each switching to be sure that everything is rendered before the texture is read again? Because when I omit it, it seems like the data is not ready yet. I also noticed that sf::RenderTexture::display() calls glFlush().

The problem is, flushing the whole OpenGL pipeline is terribly slow. Can't multipass shaders be applied without flushing?
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Re: OpenGL FBO rendering - when to call glFlush()
« Reply #1 on: June 05, 2013, 09:46:23 am »
As long as everything happens in the same OpenGL context, you shouldn't have to call glFlush. sf::RenderTarget calls it because the target has its own separate context, so it is required so that all other contexts have an updated view of the texture.

I'm afraid I can't help more, I'm not a FBO expert :-\
Laurent Gomila - SFML developer

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6286
  • Thor Developer
    • View Profile
    • Bromeon
Re: OpenGL FBO rendering - when to call glFlush()
« Reply #2 on: June 05, 2013, 10:07:07 am »
Okay. First I had glClear() and then I rendered with the shader. glClear() was very slow, and it did not change much when i used glScissor().

Replacing glClear() with manual rendering is faster, but the pixels are not ready in time -- it only works when I add a synchronization point like glReadPixels() (to debug) or glFlush().

Does glClear() also introduce synchronization, or do you (anybody) have an idea why it could be so slow, even if I'm clearing only a few pixels of a texture?
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6286
  • Thor Developer
    • View Profile
    • Bromeon
Re: OpenGL FBO rendering - when to call glFlush()
« Reply #3 on: June 07, 2013, 09:40:12 am »
Is it different if I have a single FBO and just attach a different texture after each shader pass? What would I have to do to make sure everything is drawn before the texture is read again?
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Re: OpenGL FBO rendering - when to call glFlush()
« Reply #4 on: June 07, 2013, 10:01:19 am »
I have no idea, sorry.

Have you tried to use an OpenGL debugger? There are pretty good ones available for free.
Laurent Gomila - SFML developer

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6286
  • Thor Developer
    • View Profile
    • Bromeon
Re: OpenGL FBO rendering - when to call glFlush()
« Reply #5 on: June 07, 2013, 10:39:31 am »
I have experimented with glIntercept a bit, but not found anything obvious. Also, I use a macro to check the OpenGL calls.

And of course the good old way of debugging a texture by reading it to the RAM with glReadPixels(). Interestingly, this call makes the behavior correct (i.e. the texture data is ready before each shader pass), which makes me think texture attachment switches in a single FBO require some kind of explicit synchronization. The problem is, I just can't afford any glFlush() calls.

If somebody else has an idea, just speculate please :D
Meanwhile, I'm searching further on the Internet...

Thanks!
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

 

anything