VBL syncing and threads behavior

Posts: 72
Joined: 2006.10
Post: #1
I've always used VBL syncing, but since it's so simple to just activate it and forget it, I never took the time to have a proper look at it.

I can't seem to find this in the documentation, so...

When CGLFlushBuffer() is called with VBL syncing enabled. What exactly happens?

a. The function returns immediately and the flushing happens in parallel?
b. The function blocks the thread that called it and unblocks it when it's time to flush?
c. The thread runs wild in a while loop while waiting? Sneaky
d. Something else?

I'm guessing ( hoping? ) that the answer is b...


- Sohta
Quote this message in a reply
Posts: 5,143
Joined: 2002.04
Post: #2
the answer is a combination of a) and b). You have a certain number of frame buffers (2-3) available to you for flushing into; if one is available flush will return immediately and the swap will happen later. If none are available, flush will block until one becomes available.
Quote this message in a reply
Posts: 1,234
Joined: 2002.10
Post: #3
Yes. So, because it can block, if you need to squeeze out as much performance as possible, you should spawn another thread for your physics/AI/whatever that can run independent of the graphics thread.

You can also (as shown at WWDC 2003) have two GL threads running in parallel, for example one calculating and updating texture maps, and one submitting terrain geometry using those textures. In this case you have to use locks if you are sharing one context between the threads (or risk a kernel panic!) Or, you could use a separate context per thread; one could be a render-to-texture context.
Quote this message in a reply
Posts: 72
Joined: 2006.10
Post: #4
Thanks guys, This is along the lines of what I had in mind.

- Sohta
Quote this message in a reply
Post Reply 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  GLUT and VBL syncing in Mac OSX supersonic 1 4,982 Jul 21, 2011 06:09 AM
Last Post: Skorche
  Strange CGCaptureAllDisplays() Behavior Justin Brimm 4 3,704 Apr 20, 2006 09:06 PM
Last Post: Justin Brimm
  SDL and threads basic questions... WhatMeWorry 1 3,276 Sep 19, 2005 04:35 AM
Last Post: IBethune
  CoreAudio and threads Dan Potter 1 3,742 Mar 27, 2005 08:55 PM
Last Post: Dan Potter