How much more complex is it to draw simple curves, lines and circles in OpenGL ES rather than in Quartz 2D?

前端 未结 4 769
陌清茗
陌清茗 2021-01-06 23:45

Is OpenGL ES really so much faster? Why? And is it really so horrible complicated to draw such simple things in OpenGL ES compared to drawing these in Quartz 2D?

For

4条回答
  •  一生所求
    2021-01-07 00:03

    Based on your earlier question, I assume the reason you want to switch to OpenGL is to accelerate the animation of your drawn elements. In that question, you were attempting to animate by redrawing your UIView's contents with Quartz every frame. That will be incredibly slow, because of the way that the iPhone's drawing system works. Every frame, your view's backing layer would need to be converted to a texture and re-uploaded to the GPU, a very slow set of operations.

    As has been pointed out, going the way of pure OpenGL ES for this will take a tremendous amount of time and effort, unless you are willing to use a third-party framework like Cocos2D. Even then, I bet that you'll find drawing complex 2-D elements to be as hard or harder than with Quartz.

    Instead, my recommendation is to not try animating your content by redrawing it each frame in Quartz, but by layering your drawing and using Core Animation to move these layers around. Even on the original iPhone OS devices, I've found that I can animate 50 translucent layers around using Core Animation at 60 frames per second. Core Animation, using Quartz for drawing, is far easier to work with than OpenGL ES, and can let you achieve close to the same level of performance if done properly. Trust me, I've used both.

    Even if you need to animate a vector element as it changes shape, you can use something like CAShapeLayer to handle that animation for you.

    See also my answer to this question. For resources on getting started with Core Animation, see my answer here.

提交回复
热议问题