Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SDL2 FPS limit #7518

Closed
XITRIX opened this issue Mar 22, 2023 · 4 comments · Fixed by #11666
Closed

SDL2 FPS limit #7518

XITRIX opened this issue Mar 22, 2023 · 4 comments · Fixed by #11666
Assignees
Milestone

Comments

@XITRIX
Copy link

XITRIX commented Mar 22, 2023

/Is there any build in FPS limiter in SDL2?

I am running my app on different devices and I have very stable FPS count, so there is definitely some sort of FPS limit, but the problem that this limit is pretty random, on my MacBook it's 120fps, it's screen is also 120 hz so it's great. On my Nintendo Switch it's also 120, it's screen is only 60 hz, but I could limit it by my self, so it's not a problem, but on my iOS device it's 60 fps, while screen is 120 hz, so window looks really laggy on it. Moreover iOS app in MacOS mode works on 240 fps, while running it in iOS simulator shows ... maybe 1 fps ... (Update. Nevermind about simulator, it seems it has broken OpenGL)

I am using SDL_WINDOW_OPENGL flag to create a Window if it's matters.

@slouken
Copy link
Collaborator

slouken commented Nov 8, 2023

Not specifically, there's code to simulate vsync if necessary, but there's no other specific FPS limiter in SDL.

@slouken slouken closed this as completed Nov 8, 2023
@XITRIX
Copy link
Author

XITRIX commented Dec 8, 2023

I've finally managed this issue. In case someone will also find this problem here is my solution:

To allow iOS run app in 120 fps, you need to add <key>CADisableMinimumFrameDurationOnPhone</key><true/> into app's info.plist file

But doing ONLY that will not help, you also need to create CADisplayLink object and set it's preferredFrameRateRange to range from 80 to 120 fps. I've made it by modifying SDL's SDL_uikitappdelegate.m, in function didFinishLaunchingWithOptions I've added this right before SDL_SetMainReady();

if (@available(iOS 15.0, *)) {
        CADisplayLink* displayLink = [CADisplayLink displayLinkWithTarget:self selector:@selector(fpsUnlocker)];
        displayLink.preferredFrameRateRange = CAFrameRateRangeMake(80, 120, 120);
        [displayLink addToRunLoop:NSRunLoop.currentRunLoop forMode:NSDefaultRunLoopMode];
}

fpsUnlocker is just an empty function, you could declare it anywhere you'd like in that file

More information about this you could find in Apple's documentation here

@slouken slouken reopened this Dec 8, 2023
@slouken slouken added this to the 3.2.0 milestone Dec 8, 2023
@slouken slouken assigned slouken and unassigned icculus Dec 4, 2024
slouken added a commit to slouken/SDL that referenced this issue Dec 18, 2024
@slouken
Copy link
Collaborator

slouken commented Dec 18, 2024

Thanks for the info! This is fixed for SDL3.

slouken added a commit that referenced this issue Dec 18, 2024
Fixes #7518

(cherry picked from commit 835b6e0)
slouken added a commit that referenced this issue Dec 18, 2024
Fixes #7518

(cherry picked from commit 835b6e0)
(cherry picked from commit 9740984)
@slouken
Copy link
Collaborator

slouken commented Dec 18, 2024

.. and cherry-picked for the next SDL2 release. :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants