Change macOS OpenGL timing to use CVDisplayLink #488
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
When building with
SOKOL_GLCORE33
on Mac, this commit adds the CoreVideo to the list of required frameworks:-framework CoreVideo
This replaces the
NSTimer
withCVDisplayLink
for driving the timing of rendering frames with OpenGL on macOS.CVDisplayLink
can be used to receive a callback on a separate high-priority thread synchronized with the timing of a display device.Because sokol_app.h expects the rendering code to run on the main thread, we use:
NSObject performSelectorOnMainThread:
to trigger our code on the main thread.Without vertical sync enabled, this will cause tearing. Maybe because both the rendering time of a frame can't be guaranteed to meet the deadline, and maybe also because of the time spent going from one thread to another.
However, it does give a consistent timer, and seems to be an improvement over
NSTimer
. In my measurements, CPU time waste from the high-frequencyNSTimer
was reduced.I believe @floooh has found some issue with resizing the window with this patch. I haven't been able to reproduce that in 10.12, but I also haven't tried very hard.