glClear() 如何提高性能? [英] How does glClear() improve performance?

查看:29
本文介绍了glClear() 如何提高性能?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Apple 解决闪烁问题的技术问答 (QA1650) 包括以下段落.(强调我的.)

Apple's Technical Q&A on addressing flickering (QA1650) includes the following paragraph. (Emphasis mine.)

您必须为屏幕上的每个像素提供一种颜色.在绘图代码的开头,最好使用 glClear() 来初始化颜色缓冲区.在帧开始时全屏清除每个颜色、深度和模板缓冲区(如果您正在使用它们)通常也可以提高您的应用程序的性能.

You must provide a color to every pixel on the screen. At the beginning of your drawing code, it is a good idea to use glClear() to initialize the color buffer. A full-screen clear of each of your color, depth, and stencil buffers (if you're using them) at the start of a frame can also generally improve your application's performance.

在其他平台上,我一直发现它是一种优化,如果您要绘制到每个像素,清除颜色缓冲区.(如果您只是要覆盖清晰的颜色,为什么要浪费时间填充颜色缓冲区?)

On other platforms, I've always found it to be an optimization to not clear the color buffer if you're going to draw to every pixel. (Why waste time filling the color buffer if you're just going to overwrite that clear color?)

调用 glClear() 如何提高性能?

How can a call to glClear() improve performance?

推荐答案

这很可能与基于图块的渲染有关,它将整个视口划分为图块(较小的窗口,通常大小可以为 32x32),这些图块是保存在更快的记忆中.这个较小的内存和实际帧缓冲区之间的复制操作可能需要一些时间(内存操作比算术操作慢很多).通过发出 glClear 命令,您是在告诉硬件您不需要以前的缓冲区内容,因此它不需要将颜色/深度/任何内容从帧缓冲区复制到较小的图块内存.

It is most likely related to tile-based rendering, which divides the whole viewport to tiles (smaller windows, can be typically of size 32x32) and these tiles are kept in faster memories. The copy operations between this smaller memory and the real framebuffer can take some time (memory operations are a lot slower than arithmetic operations). By issuing a glClear command, you are telling the hardware that you do not need previous buffer content, thus it does not need to copy the color/depth/whatever from the framebuffer to the smaller tile memory.

这篇关于glClear() 如何提高性能?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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