JOGL swapBuffer / flush

I did have a question though regarding JOGL. I know that in LWJGL that the flush takes a long time. So basically you can send all the commands to the card but when you call flush there is this long pause while it actually finishes rendering. It seems like the request to draw the Drawable and the resulting callback to the event listener does not return until the flush is complete.

Is there anyway I can have the flush operate on another thread so that I can be building the next frame? I would need to have some way to detect that the frame was actually done before I start to render the next one, but I think this would be a valuable peice of parallalism.

I have not confirmed the time delta between exiting the draw callback and returning from the call to Drawable draw, but I suspect it is a significant period of time.

I am bumping this to the top.

Any ideas?

You might be confusing a glFlush, which simply makes the OGL driver dump it’s outstanding OGL commands to the card, witha buffer swap that flips the back buffer to the front.

The buffer swap will wait for all outstanding OGL commands to complete before flipping the buffers, making sure that a complete buffer is shown on the monitor.

So ,waht does this mean to you? Simple, you can’t render the next frame without the previous being finished. However, you can do the non-rendering work if you like. You’d simply order your render loop work like this:

Render frame x
update world state according to physics, network etc for frame x + 1
swap buffers
render frame x + 1

Now, I may have completely missed your question, because I’m writing this out of LWJGL knowledge. Maybe you really wanted some way to work around a jogl limitation?

  • elias

I will just point out that it is interesting that you make an assumption that its a limitation in JOGL that David is seeking to resolve.

Sorry about that. It stems from me hearing about jogl’s implicit buffer swap, which could very well be a limitation to the loop order I proposed.

  • elias

[quote]I know that in LWJGL that the flush takes a long time. So basically you can send all the commands to the card but when you call flush there is this long pause while it actually finishes rendering. It seems like the request to draw the Drawable and the resulting callback to the event listener does not return until the flush is complete.
[/quote]
As another person mentioned, there is a difference between and explicit glFlush(), an explicit glFinish(), and an implicit finish caused by a buffer swap.

In general, glFlush() is a bad thing because it forces the driver to finish executing all glCommands before returning control to the caller. When using glFinish() or doing a buffer swap (which JOGL does internally at the end of each frame), it merely tells the graphics driver to begin processing commands and then returns control back to the user. This facilitates parallelism by allowing your app to continue processing while the card is busy flushing queued events.

So, in general, if you’re using JOGL you neither have to nor need to do make calls to glFlush(), glFinish(), or SwapBuffers(HDC). Calling glFlush() explicity shouldn’t cause any harm, but it will certainly kill your performance.

-chris