Archived

This topic is now archived and is closed to further replies.

glFlush and glFinish

This topic is 5333 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

From MSDN:

quote:

The glFlush function forces execution of OpenGL functions in finite time.

The glFinish function blocks until all OpenGL execution is complete.


Share this post


Link to post
Share on other sites
On the language different than the MSDN trash that means:

call glFlush instead of SwapBuffers if you are using single-buffered mode and call glFinish at the end of your rendering function to finish all OpenGL pipeline ops.

The PAIN is coming...this summer!!!In cinemas everywhere.

Share this post


Link to post
Share on other sites
No, you can''t call glFlush instead of SwapBuffers. glFlush doesn''t swap front/back buffers and SwapBuffers doesn''t execute the OpenGL command pipeline.

Share this post


Link to post
Share on other sites
I''ve got another question related to glFinish. In what kind of way does it block? Does it "suspend" the current thread/process until it gets a signal to continue, or does it poll the pipeline until its execution is complete? I mean in the first way the os could give some cpu time to another thread/process or make the cpu sleep for some time if none is waiting.

eloso

Share this post


Link to post
Share on other sites
quote:
Original post by eloso
I''ve got another question related to glFinish. In what kind of way does it block? Does it "suspend" the current thread/process until it gets a signal to continue, or does it poll the pipeline until its execution is complete? I mean in the first way the os could give some cpu time to another thread/process or make the cpu sleep for some time if none is waiting.

eloso


Nope.The only thing that glFinish do is not to return from the function exucusion while all of the pipeline commands aren''t finished.When they are,the function returns.

The PAIN is coming...this summer!!!In cinemas everywhere.

Share this post


Link to post
Share on other sites
But when it does not return it must do something. Either go to sleep and wait for a signal/interrupt/whatever or go into a loop that polls the pipeline state and breaks when the pipeline has finished. And that''s my question.

eloso

Share this post


Link to post
Share on other sites
The second is right.I explain it so(ofcourse this is my opinion).glFinish posts some command to the pipeline and blocks it.When it the posted message is resieved the pipeline is clear.

The PAIN is coming...this summer!!!In cinemas everywhere.

Share this post


Link to post
Share on other sites
If i understood you right it is not a good idea to call glFinish directly after all gl calls if maybe some AI could be computed for the next frame even if they are in another thread. So it is better to first do all the rendering stuff and then compute ai/physics/sound/... as long as you guess the pipeline would need to finish, right?

Btw. is it possible to just check whether the pipeline has finished?

sorry for my obtrusive asking, but i think this is a very important aspect which is not covered by any OpenGL book i''ve read.

eloso

Share this post


Link to post
Share on other sites
You would not want to call glFinish after every rendering operation. The time that is wasted wating for the glFinish operation to return could be spent executing other sections of code in your program. Only use glFinish in a situation where it is absolutely essential that the previous rendering operations have completed. If you order your operations right you shouldn''t have to use this command anyway. Just stick anything that relies on the rendering operations being complete at the end of your idle loop.

As for what glFlush does, it forces any pending rendering operations to begin, but doesn''t block waiting for them to finish. It''d probably be good form to stick a glFlush at the end of your rendering loop, but not a glFinish.

glFlush and glFinish mostly have applications where you''re distributing an application over a network, and you want to control the timing of when rendering commands are issued to the other computers. They can be used to help keep them all in sync, and ensure that all the rendering operations are issued when you want them to be issued.

Share this post


Link to post
Share on other sites
Allright, i think i understood that. Thanks to you all. But was sphinx23 really right when he said SwapBuffers doesn''t execute the pipeline? I think if SwapBuffers swapped immediately instead of waiting for the pipeline you would get half rendered frames, right? So i guess SwapBuffers calls glFinish (or does something similar). And if so i think it would be advisable to 1st do all the rendering stuff, then do all cpu intensive calculations for the next frame and last call SwapBuffers. Or in other words call SwapBuffers BEFORE rendering, not AFTER like in many OpenGL examples. Am i right with my assumptions?

eloso

Share this post


Link to post
Share on other sites