Async behaviour of SwapBuffers

Hi,

I found out that SwapBuffers() returns control BEFORE it actually does the job.

Is there any way to wait until it really finishes?

Any good reason why you’d want that?

try swapControl EXT…
just a question, your rendering time will be stable and within the refreshPeriod?
if not ask Humus. ^^

Call glFinish immediately afterwards?

  • Matt

Originally posted by Alexey:
[b]Hi,

I found out that SwapBuffers() returns control BEFORE it actually does the job.

Is there any way to wait until it really finishes?[/b]

From glFinish:

The glFinish function does not return until the effects of all previously called OpenGL functions are complete. Such effects include all changes to the OpenGL state, all changes to the connection state, and all changes to the framebuffer contents.

Strictly speaking, SwapBuffers is not an OpenGL command, but I wonder if doing a glFinish after calling SwapBuffers will work for you, as it’s a change to the framebuffer contents (I would say it’s driver dependent, though).

Thank you very much!

glFinish() worked fine!

I am still very curious as to why you would want to wait for SwapBuffers. SwapBuffers just schedules a buffer swap at the next vsync (if you have that enabled). I do not see why you need to wait for it to actually happen, why not go on and start rendering the next frame? If you have vsync enabled it will not cause any tearing.

Originally posted by Nakoruru:
I am still very curious as to why you would want to wait for SwapBuffers.

You may need to wait for swapbuffers to finish if you want to mix GDI with opengl rendering (not something I would recommend, though).