My game needs to behave differently to get the best performance if the user disables vsync globally (basically, I need to change the scheduling on my housekeeping operations).

Is there a graphics card independent way (SDK call, C/C++) for me to find out if vsync is disabled?

I'm using opengl/glfw 3.2.1, and I can use glfwSwapInterval(0) to force vsync disabling, but that's not the same as reading the player's current default preferences.

I can always use application settings, but it'd be good if the game could default to the most suitable approach for the default video settings.

  • \$\begingroup\$ What operating system are you targeting? \$\endgroup\$ – Pikalek Dec 3 '18 at 14:50
  • \$\begingroup\$ win32, UWP, OSX and maybe Linux for kicks. \$\endgroup\$ – Andy Krouwel Dec 6 '18 at 17:59

I couldn't locate anything directly in GLFW that for checking the status of vsync.

According to the official OpenGL spec on swap intervals, swap interval access is provided via platform-specific extensions. You can query the swap interval as follows:

  • On Windows, use wglGetSwapIntervalEXT()
  • On Linux, use glXSwapIntervalEXT()

Note in the Linux case, no parameter is passed; if a value is passed, the call will attempt to set the swap interval rather than read it.

Also note, some GL drivers support adaptive vsync - I'm not sure how (if at all) this may factor into your problem, but it's something to be aware of.

  • 1
    \$\begingroup\$ The necessary call (On Windows) is to wglGetSwapIntervalEXT(). Couldn't find it because GLFW (which I was using) doesn't reference it in any way or include it in their headers. And it works! If I force vsync off in the driver, I get back an initial value of 0 and even if I try to set it to 1 then it's still 0 when I ask again. Similarly, if I force it to be on then even if I request a swap interval of 0 wglGetSwapIntervalEXT still returns 1. Reference extension headers are available from khronos.org/registry/OpenGL/index_gl.php and you're looking for <GL/wglext.h> \$\endgroup\$ – Andy Krouwel Dec 14 '18 at 14:45
  • \$\begingroup\$ Nice work! In my somewhat limited experience, sometimes these APIs drift over time from their documentation such that these sorts of things are harder to figure out than they really should be. Thanks for going through the trouble of editing my answer to reflect you findings. \$\endgroup\$ – Pikalek Dec 14 '18 at 15:22
  • \$\begingroup\$ egl has eglSwapInterval() but appears to have no equivalent function for getting the swap interval (according to headers on khronos.org/registry/EGL), which is a pain because that's what I use on some platforms. They're mostly mobile, so I guess the idea of swapInterval barely makes sense, except yes I AM looking at you Windows UWP. \$\endgroup\$ – Andy Krouwel Dec 14 '18 at 20:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.