Jump to content
  • Advertisement
Sign in to follow this  
GuyPerfect

OpenGL Today's Facepalm: glFlush()

This topic is 3715 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

I recently developed a need for an off-screen buffer so I could render images via a command line tool that would not be able to produce a window for rendering. I looked up the needed code changes (PFD_DRAW_TO_BITMAP in Windows, for example), but it didn't seem to be working right. I eventually tripped over glFlush() and looked up why that made things work. I had no idea that OpenGL commands are actually buffered and processed via means unknown at appropriate times like when the system's SwapBuffers or equivalent are called. I simply assumed that if I send a command, it gets executed and I have my pixels in my memory buffer. Well, that's not the case. So to prevent someone else from losing a portion of their hair when working with single-buffered, non-windowed OpenGL contexts: remember to use glFlush() to make sure everything's taken care of and all pixels are rendered!

Share this post


Link to post
Share on other sites
Advertisement
Quote:
Original post by GuyPerfect
So to prevent someone else from losing a portion of their hair when working with single-buffered, non-windowed OpenGL contexts: remember to use glFlush() to make sure everything's taken care of and all pixels are rendered!

Be careful, glFlush doesn't do what you think it is doing ! glFlush will only initiate a flush of the command buffer to the GPU, but it will not wait for it to complete. So you are still not guaranteed that all pixels are in fact rendered after issuing this command. That it is working for you right now could just be a timing coincidence.

What you are looking for is glFinish(). It does basically the same as glFlush, but it will wait until all rendering operations are really completed.

Share this post


Link to post
Share on other sites
If you're planning on doing some fairly CPU intensive work while rendering stuff, you can make all of the rendering calls, then call glFlush() to start the rendering, and then begin the other work, and once that's done, you can then swap the buffers, or call glFinish() (depending on what you're doing...). That's the way I do things anyway... It works in theory, and I haven't had any problems with it, so I assume it'd be the best way to go about things...

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!