Question

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

Was it helpful?

Solution

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.

OTHER TIPS

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.

I did not get the term "limit my FPS rate " from the function. but to make your openGL app runs smoothly it should have an FPS upto 60 (in iOS 5) and you should maintain(i think limit in your case) that FPS for better performance.

Xcode provides many tools to help you analyze and tune your OpenGL ES applications, as described in the OpenGL ES Programming Guide for iOS:

OpenGL ES Performance Detective — First introduced in Xcode 4, OpenGL ES Performance Detective quickly helps you to determine if OpenGL ES is the main bottleneck in your application; it should be the first tool you run to test your OpenGL ES code. A key advantage of OpenGL ES Performance Detective is that it can automatically direct you immediately to the critical location in your application that slows OpenGL ES performance the most. To use the OpenGL ES Performance Detective, launch the tool and use it to select your application on the iOS-based device connected to your development machine. When your application reaches a location in your application that is of interest to you, click the Collect Evidence button. OpenGL ES Performance Detective records OpenGL ES commands your application generates over a series of frames, analyzes the commands to discover the key bottlenecks and delivers specific performance recommendations. The OpenGL ES Performance Detective can be found inside the /Developer/Applications/Graphics Tools/ directory.

Instruments (OpenGL ES Analysis) — Also introduced in Xcode 4, the OpenGL ES Analysis tool provides a number of features to help you study your application’s usage of OpenGL ES. The OpenGL ES Analysis tool records the OpenGL ES commands generated by your application and warns you when your application does not follow the best practices described in this programming guide; it recommends specific changes you can make to follow the best practices. The OpenGL ES Analysis tool allows you to see all the commands used to generate each frame of animation. Finally, the OpenGL ES Analysis tool allows you to selectively disable portions of the graphics pipeline to determine if that part of the pipeline is a significant bottleneck in your application. The OpenGL ES Analysis tool provides you a great set of tools to manually analyze your application and understand its inner workings. It does not, however, automatically point you at the location where your application is currently bottlenecked. For example, even when it offers a suggestion on how to improve your OpenGL ES coding practices, that suggestion does not mean that changing your code is automatically going to improve the performance of your application.

Instruments (OpenGL ES Driver) — The OpenGL ES Driver tool is provided on Xcode 3 and later. It does not directly analyze the OpenGL ES commands submitted by your application. Instead, it allows you to monitor key statistics about how the graphics hardware is utilized by your application. For example, you can use it to track the number of bytes used to hold texture data and how those numbers change from frame to frame.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top