开发者

OpenGL constant color

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 d开发者_开发百科raw 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?


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜