15

With all my SDL/OpenGL programs, the framerate is stuck at 60fps, so looks like the vsync is enable, but not by me, nor in my code or my settings. so i would like to now if there is a way to disable it, maybe in some deep macOS settings?

3 Answers 3

9

This enabled me to get around ~700 frames per second on my MacBook Pro.

It is not permanent either, perfect for testing/benchmarking.

Source

5
  • 1
    Oh my gad, after all that time!! Thanks so much mate!
    – Nox
    Oct 2, 2014 at 1:50
  • i tried this and nothing happened. What am i doing wrong? Jun 4, 2016 at 9:18
  • 1. Double check that the app you are testing can actually go over 60fps; 2. This solution was for Mavericks 10.9, untested for Yosemite or El Capitan
    – cevaris
    Jun 4, 2016 at 16:09
  • 1
    Would you mind to state in your answer that this solution is actually not working on 10.11 with xCode 7.3 (that the only one I've tried) anymore please?
    – Nox
    Jul 13, 2016 at 22:56
  • Your first link is broken: it says Your session has expired. Please log in..
    – Ruslan
    Aug 12, 2016 at 9:58
5

Welcome to SO. I outlined an approach here for a similar question. You should consider that most Mac LCDs are locked to 60Hz, and more recent hardware is limited to 120Hz. Disabling vsync may simply result in wasted CPU/GPU cycles, and possibly introduce tearing artifacts.

1
  • Yeah, i've stop looking around to find a solution... Thanks anyway!
    – Nox
    Jan 31, 2014 at 7:58
5

After YEARS looking for a workaround (and with the help of Brett Hale) this is what worked for me - I've added that piece of code at the start of my render loop (and not only in the init, as Apple seems to reset the SwapInterval settings every time...) and was finally able to have unsynchronize framerate:

#ifdef __APPLE__
GLint                       sync = 0;
CGLContextObj               ctx = CGLGetCurrentContext();

CGLSetParameter(ctx, kCGLCPSwapInterval, &sync);
#endif

Don't forget to include <OpenGL/gl.h>

It's not the nicest solution but it's actually the only one I found that work like a charm.

8
  • Apparently this is broken in Mac OS 10.14 (Mojave), with vsync always disabled, (but vsync in Metal still works). SDL2.0.10+ (not yet released) will work around this bug by using CVDisplayLink instead. You can see the commit here and discussion here Mar 24, 2019 at 0:42
  • Also, the code SDL2 were previously using only seems to set this once, not every frame. Maybe because they instead called [NSOpenGLContext setValues:&value forParameter:NSOpenGLCPSwapInterval] Mar 24, 2019 at 0:46
  • News just in, apparently OpenGL vsync is fixed in the next release, Mac OS 10.14.4 Mar 24, 2019 at 0:49
  • Confirmed working on macOS 10.14, but seems this is not working on macOS 10.15 and 11 anymore, I've tried kCGLCPSwapInterval / NSOpenGLCPSwapInterval / CVDisplayLink Jul 24, 2021 at 12:54
  • Found out on macOS 10.15 and 11, the actual drawing code including flushBuffer() must not be put in func draw(_ dirtyRect: NSRect) Jul 26, 2021 at 14:16

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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