Advertisement

To glFlush() or not to glFlush()...?

Started by July 27, 2004 05:54 AM
10 comments, last by Brother Bob 20 years, 4 months ago
now THAT was the answer I was looking for. Ive been trying for hours to find something somewhere that gives better official detail about what exactly glFlush() does. To me what you just said makes the most sence.

So, by your understanding, would you say im right in assuming there is a default wait period of some kind? I mean if the GPU executed every command/function as it was passed there would be no need for glFlush(). So then it must be waiting for some reason right?

Or is 8 hours of watch getting to me head again?
C_C(Enter witty/insightful/profound remark here...)
Quote: Original post by McCLaw
Well in that case, I would use glFlush only when doing multiple render passes (Render to texture, or whatever), so that you are sure that your buffer contains the correct image...

OpenGL guarantees that commands are executed in exactly the same order as they are issued, and no commands that requires feedback is started before all previous commands have finished executing. You don't need glFLush to make sure that the buffer is in the correct state, OpenGL already guarantees that.
Quote: Original post by Cannibal_Coder
So, by your understanding, would you say im right in assuming there is a default wait period of some kind? I mean if the GPU executed every command/function as it was passed there would be no need for glFlush(). So then it must be waiting for some reason right?

As commands are issued, the specification allows them to be placed in a queue or buffer, waiting to be executed "as the driver sees fit", so to speak. There is no waiting time or so, commands are executed when the driver wants to. That means that if there's a sudden stop in commands being fed to OpenGL, the buffer may not ever be flushed, unless you tell it to, either by using glFlush or glFinish. Try it if you want and see how your driver handles it. Make a program doing single buffered rendering and draw a few triangles, and at the end, stop the rendering without performing a flush, and make sure you don't update anything (if you like, just pause the program). On my computer, nothing shows up until I call glFlush, meaning there's no time until the buffer is flushed automatically or so. If commands are not allowed to be buffered, then these commands would be useless, yes.

I see no reason to use either glFlush or glFinish, unless you're benchmarking (as lonestock said) or doing single buffered rendering.

This topic is closed to new replies.

Advertisement