Coolant
Coolant

Reputation: 448

Variable Name Efficiency in Shader (OpenGL ES 2)

Out of curiosity, will it be more efficient to write shader variables like this :

     lowp vec4 tC = texture2D(uTexture, vTexCoord); // texture color

or

     lowp vec4 textureColor = texture2D(uTexture, vTexCoord); // texture color

Note that I wrote variable tC because it has less characters than variable textureColor

I understand in programming language like C/ObjC, it doesn't matter, but what about shader, since you can query the attributes / uniform names.

Upvotes: 2

Views: 676

Answers (1)

Jesse Hall
Jesse Hall

Reputation: 6797

It shouldn't make a measurable difference. After linking your program during initialization, query the locations of attributes/uniforms, and keep the result around with the program handle. From then on, neither your app nor the driver will be touching the name strings, just the integer locations.

Even if you re-query locations every time you need to change an attrib binding or uniform value, the difference between a short and "moderate" name length likely won't make much difference compared to the other costs of doing the lookup and binding/value change.

Upvotes: 1

Related Questions