在 OpenGL ES 中而不是在 Quartz 2D 中绘制简单的曲线、直线和圆要复杂多少? [英] How much more complex is it to draw simple curves, lines and circles in OpenGL ES rather than in Quartz 2D?

查看:12
本文介绍了在 OpenGL ES 中而不是在 Quartz 2D 中绘制简单的曲线、直线和圆要复杂多少?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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 example, I have a UIView subclass with -drawRect: implemented, where I draw some lines, curves and circles. Just simple paths, with some shadow.

What would I do in OpenGL ES? Isn't there this nice EAGLView layer thing? One thing that comes to mind is how do touch events go into OpenGL ES? Maybe that's the complex thing about it? Are there tutorials on basic drawing operations in OpenGL ES?

解决方案

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.

这篇关于在 OpenGL ES 中而不是在 Quartz 2D 中绘制简单的曲线、直线和圆要复杂多少?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆