OpenGL 常量颜色
我阅读了 此 Apple 文档(在标题“避免在属性数组中存储常量”下)它表示如果模型的顶点都具有相同的颜色则颜色不应该是顶点属性。 “OpenGL ES 2.0 应用程序可以设置常量顶点属性……”是什么意思?
我的问题是,使用统一的颜色值,并且为每个对象调用统一的调用和绘制调用是否更好?或者无论如何都具有顶点属性,但一口气绘制所有内容。 (或者,如果更好的话,使用恒定的顶点属性)。
基本上,一次绘制所有内容的优点只是缺少多个函数调用的开销吗?
为了了解一下,假设我每帧画 1000 个圆圈,每个圆圈颜色不同,有 40 个顶点。在这种情况下哪个会更好?
I read in this Apple documentation (under the header "Avoid Storing Constants in Attribute Arrays") it says that if a model's vertices all have the same colour then colour shouldn't be a vertex attribute. What do they mean by "OpenGL ES 2.0 applications can either set a constant vertex attribute…"?
My question is, is it better to use a uniform value for colour, and call have a uniform call and draw call for every object? Or to have the vertex attribute anyway, but draw everything in one fell swoop. (Or, a constant vertex attribute if that's better).
Basically, is the advantage of drawing everything at once only the lack of overhead of multiple function calls?
Just to get a sense of it, say I were drawing 1000 circles every frame, each a different colour and having 40 vertices. Which would be better in that case?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
答案取决于您在一次绘制调用中绘制了多少内容。如果您有一个包含 30,000 个顶点的对象,其中所有顶点都具有相同的颜色,那么您就会浪费大量的每个顶点读取(假设颜色数据使您的每个顶点数据更大。但可能不会)。但是,如果您谈论的是四边形渲染,其中每个四边形都有不同的颜色,那么统一的更新开销和多次绘制调用将降低您的性能。
请注意,OpenGL 下有一些实例化方法,它允许您拥有每个实例的数据以及每个顶点的数据。但是,除非模型中有数千个实例和 100 多个顶点,否则这通常不会产生太大影响。
对于您的具体示例,无法知道哪个更快。你必须对其进行基准测试。
The answer depends on how much stuff you are drawing in a single draw call. If you have an object of 30,000 vertices, where all of them have the same color, then you're wasting a lot of per-vertex reads (assuming that the color data makes your per-vertex data bigger. It may not). However, if you're talking about quad rendering, where each quad has a different color, then the uniform update overhead and multiple draw calls is going to kill your performance.
Note that there are methods for instancing under OpenGL, which allows you to have per-instance data as well as per-vertex data. But this generally doesn't buy much until you have multiple thousands of instances, and more than 100 vertices in the model.
For your specific example, there's no way to know which would be faster. You'd have to benchmark it.