Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Capping FPS rate on iPhone?

How do I limit my FPS rate on my OpenGL app (I'm using CADisplayLink) so I can leave the CPU for other things?

like image 884
user642252 Avatar asked Dec 09 '22 03:12

user642252


2 Answers

Although this has been answered I would like to expand a bit.

The recommended method is indeed to use CADisplayLink and frameInterval to limit your base frame rate, the display itself in hardware has a fixed refresh rate and CADisplayLink method synchronizes the hardware refresh with the calling of our drawing methods so the drawing methods have the most time to work.

Since CADisplayLink is hardware generated the only thing you can do with it is divide the time, that's what the frameInterval is there to do.

frameInterval = 1 gets you 60 fps

frameInterval = 2 gets you 30 fps

frameInterval = 3 gets you 20 fps

I use a lot frameInterval = 5 for menus for example, it still gives me 12fps (about the minimum for reasonable simple animation) and the battery consumption reduces drastically.

I've also used dynamic frame rate change, by measuring the average frame rate and choosing a frameInterval bellow that, helps to keep a game fluid.

FPS's outside of these values aren't very stable and usually result in jittery animation, the time slice we have to work with is 1/60 s, so only multiples of that will produce a fluid animation. Even if you don't use CADisplayLink and make a perfect timing routing to deliver something else, the hardware will still draw with that time slice.

like image 144
led42 Avatar answered Dec 21 '22 04:12

led42


In general, you're not really in control over the refresh rate if you are using the Apple-recommended CADisplayLink method to draw your app. However, you can set the frameInterval property to something greater than one to skip drawing frames, bringing your frame rate down. For example, frameInterval = 2 should give you roughly 30 fps instead of 60 fps.

It may be more useful to look at putting some application work on another thread or optimizing your drawing tasks than chopping the frame rate.

like image 37
Adrian Avatar answered Dec 21 '22 04:12

Adrian