native/macos: Add frame pacing for smooth motion#623
Open
Pewnack wants to merge 4 commits intonot-fl3:masterfrom
Open
native/macos: Add frame pacing for smooth motion#623Pewnack wants to merge 4 commits intonot-fl3:masterfrom
Pewnack wants to merge 4 commits intonot-fl3:masterfrom
Conversation
… wait twice. Added timeouts to the frame pacer to prevent waiting forever for a next frame.
…he timeout expired. Waiting for the timeout already gave time to other process/threads/
…anics let's just panic here as well.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Fixes #559
On macOS, if you are using OpenGL, motion stutters. Motion is not smooth/fluent. You can see it immediately when you run
The problem is that there isn't any real frame pacing in the current main loop. The main loop pushes out a new frame each iteration with flushBuffer and relies on VSYNC (swap_interval = 1) for pacing. But that's not enough on macOS. flushBuffer gives us the new frame, but it's up to the display server (Quartz Compositor) to decide when to use it.
This change adds a frame pacer using macOS's CVDisplayLink callback. Basically what this change does is this:
There might be other ways to do it. But I wanted to keep the main loop intact as much as possible.
With this frame pacer motion is now super smooth 😄
Before version v0.4.6 it was still reasonably smooth. That's because rendering was done differently. In v.0.4.5 each iteration of the main loop called setNeedsDisaply:YES on the view to trigger a redraw. This marks the view as 'dirty' signaling the display server to update it. The redraw performed a flushBuffer with VSYNC.