Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Performance: Quartz2D vs OpenGL ES (GLKit)

I'm working on a project where you can draw on the screen using touch. I thought of using OpenGL for it, however I came across two examples; one using OpenGL and the other using Quartz2D.

Example project from Apple, GLPaint, using OpenGL

Example project from EffectiveUI using Quartz2D

What strikes me, is that the Quartz implementation is considerably faster then the OpenGL implementation. I always presumed that OpenGL would be faster, because it is lower level, it can almost speak to the hardware itself. I know that Quartz2D is also using OpenGL for drawing, so my question is; why is the drawing in the GLPaint example so slow?

Could you make any optimizations to the GLPaint project that would benefit performance?

like image 871
Jeroen de Leeuw Avatar asked Aug 30 '12 12:08

Jeroen de Leeuw


2 Answers

It is a well known fact that on the simulator, Quartz 2D can be about 5x faster than OpenGLES, because OpenGLES isn't hardware accelerated there (different chipsets, ARM vs i386).

I would encourage you strongly to test using OpenGLES on the device and compare that to Quartz 2D, and then you should experience about a 2x performance enhancement for OpenGLES.

Another thing to consider when using OpenGL is image manipulation. OpenGL wasn't made for that, and as such has only one image buffer, meaning only one image can actually be in the GPU at once. To compensate, try using a program like TexturePacker to make a texture atlas (as a PVRTC) to load into OpenGL, and you should have some huge performance increases.

With the above taken into consideration, remember that GLPaint isn't actually drawing lines in it's implementation, but trying to draw a semi-transparent PNG over the framebuffer, and then coloring it accordingly. That is very costly, and I would recommend comparing apples to apples (OpenGL line drawing vs Quartz line drawing)

Let's face it - OpenGL is old, and as such must be treated as it is - an old dog. You can't teach this old dog new tricks, but it's damn good at the tricks it knows.

Quartz on the other hand is a new dog - while it can do lots of tricks, it cannot do one thing particularly well - performing them. It's OK for moderately complex projects, but for anything major, I will always recommend OpenGL, or a thin C++ wrapper over it.

like image 112
Richard J. Ross III Avatar answered Nov 14 '22 23:11

Richard J. Ross III


OpenGL can definitely reach a level beyond what Quartz can but being such a low level it often takes an expert to reach that level. Quartz was already written by experts and as long as you can live inside its limitations it should be a perfect API for your drawing app.

In my own experience I've often turned to customizing UIKit using Quartz because I've rarely needed to tap into OpenGL for performance sake. When I build custom OpenGL implementations it is normally because Quartz can't do the complex animations I need not because it isn't performing well on the simple ones.

like image 1
Ryan Poolos Avatar answered Nov 14 '22 22:11

Ryan Poolos