简体   繁体   English

性能:Quartz2D与OpenGL ES(GLKit)

[英]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; 我想过使用OpenGL,但是我遇到了两个例子; one using OpenGL and the other using Quartz2D. 一个使用OpenGL,另一个使用Quartz2D。

Example project from Apple, GLPaint, using OpenGL 来自Apple,GLPaint的示例项目,使用OpenGL

Example project from EffectiveUI using Quartz2D 使用Quartz2D从EffectiveUI的示例项目

What strikes me, is that the Quartz implementation is considerably faster then the OpenGL implementation. 让我感到震惊的是,Quartz实现比OpenGL实现要快得多。 I always presumed that OpenGL would be faster, because it is lower level, it can almost speak to the hardware itself. 我一直认为OpenGL会更快,因为它的级别较低,几乎可以与硬件本身对话。 I know that Quartz2D is also using OpenGL for drawing, so my question is; 我知道Quartz2D也在使用OpenGL绘图,所以我的问题是; why is the drawing in the GLPaint example so slow? 为什么GLPaint示例中的绘图如此之慢?

Could you make any optimizations to the GLPaint project that would benefit performance? 你能对GLPaint项目进行任何有利于性能的优化吗?

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). 众所周知,在模拟器上,Quartz 2D可以比OpenGLES快约5倍,因为OpenGLES并不是硬件加速(不同的芯片组,ARM与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. 我强烈建议您在设备上使用OpenGLES进行测试并将其与Quartz 2D进行比较,然后您应该体验OpenGLES的2倍性能增强。

Another thing to consider when using OpenGL is image manipulation. 使用OpenGL时要考虑的另一件事是图像处理。 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. OpenGL不是为此而制作的,因此只有一个图像缓冲区,这意味着一次只能有一个图像存在于GPU中。 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. 为了补偿,尝试使用像TexturePacker这样的程序来制作纹理图集(作为PVRTC)以加载到OpenGL中,并且您应该有一些巨大的性能提升。

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. 考虑到上述情况,请记住GLPaint实际上并没有在它的实现中绘制线条,而是尝试在帧缓冲区上绘制半透明的PNG,然后相应地对其进行着色。 That is very costly, and I would recommend comparing apples to apples (OpenGL line drawing vs Quartz line drawing) 这是非常昂贵的,我建议比较苹果与苹果(OpenGL线图与石英线图)

Let's face it - OpenGL is old, and as such must be treated as it is - an old dog. 让我们面对现实吧 - OpenGL很老了,因此必须按原样对待 - 一只老狗。 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. 适用于中等复杂的项目,但对于任何重要的项目,我总是会推荐OpenGL,或者是一个简单的C ++包装器。

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. OpenGL绝对可以达到Quartz所能达到的水平,但是如此低的水平通常需要专家才能达到这个水平。 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. Quartz已经由专家编写,只要您能够满足其局限性,它应该是您的绘图应用程序的完美API。

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. 根据我自己的经验,我经常转向使用Quartz定制UIKit,因为我很少需要利用OpenGL来提升性能。 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. 当我构建自定义OpenGL实现时,通常是因为Quartz无法执行我不需要的复杂动画,因为它在简单的动画上表现不佳。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM