当前位置: 动力学知识库 > 问答 > 编程问答 >

What are the implications of a constant vertex attribute vs. a uniform in OpenGL ES 2

问题描述:

When specifying a value that does not vary over each vertex to my vertex shader, I have the option of either specifying it as a uniform or as a constant vertex attribute (using glVertexAttrib1f and friends).

What are the reasons for which I should choose one over the other? Simply that there are a limited number of available vertex attributes and uniforms on any given implementation and thus I need to choose wisely, or are there also performance implications?

I've done some looking around and found a few discussions, but nothing that answers my concerns concretely:

- http://www.khronos.org/message_boards/showthread.php/7134-Difference-between-uniform-and-constant-vertex-attribute

http://gamedev.stackexchange.com/questions/44024/what-is-the-difference-between-constant-vertex-attributes-and-uniforms

I'm by no means an OpenGL guru, so my apologies if I'm simply missing something fundamental.

网友答案:

Well, vertex attributes can be setup to vary per-vertex if you pass a vertex attribute pointer; you can swap between a constant value and varying per-vertex on the fly simply by changing how you give data to a particular generic attribute location.

Uniforms can never vary per-vertex, they are more constant by far. Generally GLSL ES guarantees you far fewer vertex attribute slots (8, with up to 4 components each) to work with than uniform components (128 vectors, 4 components each) - most implementations exceed these requirements, but the trend is the same (more uniforms than attributes).

Furthermore, uniforms are a per-program state. These are constants that can be accessed from any stage of your GLSL program. In OpenGL ES 2.0 this means Vertex / Fragment shader, but in desktop GL this means Vertex, Fragment, Geometry, Tessellation Control, Tessellation Evaluation.

分享给朋友:
您可能感兴趣的文章:
随机阅读: