Search code examples
cocoa-touchopengl-escocos2d-iphonecore-animationquartz-graphics

Why are OpenGL ES and cocos2D faster than Cocoa Touch / iOS frameworks itself?


I wonder if cocos2D is built on top of iOS's frameworks, won't cocos2D be slightly slower than using the Cocoa framework directly? (is cocos2D on top of OpenGL ES, which in turn is on top of Cocoa Touch / iOS frameworks including Core Animation and Quartz?).

However, I heard that OpenGL ES is actually faster than using Core Graphics, Core Animation, and Quartz?

So is OpenGL ES the fastest, cocos2D the second, and Core Animation the slowest? Does someone know why using OpenGL ES is faster than using Cocoa framework directly?


Solution

  • cocos2D is built on top of OpenGL. When creating a sprite in cocos2D, you are actually creating a 3D model and applying a texture to it. The 3D model is just a flat square and the camera is always looking straight at it which is why it all appears flat and 2D. But this is why you can do things like scaling and rotating sprites easily - all you are really doing is rotating the 2D square (well, two triangles really) or moving them closer or further away from the camera. But Cocos2D handles all that for you.

    OpenGL is designed from the start to pump out 3D graphics very very quickly. So it is designed to handle shoving points and triangles around. This is then enhanced by a 3D rendering hardware which it can use specifically for this. As this is all it does, it can be very optimised for doing all the maths on the points that build up the objects and mapping textures onto those object. It doesn't have to worry about handling touches or other system things that Cocoa does.

    Cocoa Touch doesn't use openGl. It may use some hardware acceleration, but it isn't designed for that - it's designed for creating 2D buttons, etc. What it does, it does well, but it has lots of layers to pass through to do what it needs to do which doesn't make it as efficient as something designed just for graphics (openGL).

    OpenGL is the fastest cocos2D is slightly slower, but only because there are some wrappers to make your life easier. If you were to do the same thing, then you may get it faster, but with the cost of flexibility. Core Animation is the slowest.

    But they all have their uses and are excellent in their individual niche areas.