tksuoran's picture

Expose SwapInterval to GameWindow

Project:The Open Toolkit library
Category:feature request
Status:in progress (review)

Exposing SwapInterval to GameWindow would allow applications to target lower frame rates while maintaining some smoothness.


Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
the Fiddler's picture


Status:open» in progress

I'm added an experimental SwapInterval property to my working copy. The real question is how should this interact with the VSync property (VSync = true is currently equivalent to SwapInterval = 1).

There are several possible approaches:

  • Keep VSync and SwapInterval independent. The former enables vsync, using the interval specified by the latter (default = 1).
  • Deprecate VSync and keep only SwapInterval. (In this case, SwapInterval = 0 is equivalent to VSync = false, SwapInterval = 1 is equivalent to VSync = true).

The former approach maintains backwards-compatibility (existing applications won't have to change anything). The downside is that (a) you now need two steps to use higher interval values (i.e. set interval value first, then enable vsync) and (b) that it's not obvious what should happen if you change SwapInterval while vsync is enabled (should it take place immediately or should you call VSync = true again?)

The latter is much cleaner to implement and closer to how WGL/GLX/AGL/EGL actually work. The downside is a new deprecation warning (to avoid having two APIs do the exact same thing).

Anyone has any other ideas? I'm siding with the second approach for now, as it's cleaner in the long term.

tksuoran's picture


Thanks, looks good. I'm siding with second approach.

Does the Run() method internals in GameWindow() interact with this? Can I set target render rate to half of display device refresh rate when using SwapInterval = 2?

the Fiddler's picture


Status:in progress» in progress (review)

Initial implementation trunk r3081. Use with:

Context.SwapInterval = [0, n)

Invalid values are currently ignored (a message is printed to the debug log).

Still need to decide whether to expose SwapInterval directly to GameWindow and GLControl (right now it's available through their Context property), how to handle invalid values (throw exception?) and how to handle the case where swap control is not supported (throw NotSupportedException or ignore?)

invisghost's picture


Maybe when the application is being debugged throw exceptions but when it isn't just silently ignore it?

My 2 cents on the vsync/swapinterval thing:

Vsync should be deprecated and then add a way to set the SwapInterval value to the correct number for vsync.