Skip to main content
GameDev.net gamedev.net
🔒 Locked

GLSL Question....

Started by staticVoid2 Mar 27, 2011 at 8:54 PM 1 replies 900+ views
Original Post
staticVoid2
staticVoid2
In GLSL, is it guaranteed that the index location of vertex attributes is a one-to-one matching with the order you declared them in?

for e.g. if I have:


attribute vec3 pos;
attribute vec2 texcoord;


getGetAttribLocation("pos") will always return 0 and glGetAttribLocation("texcoord") will always return 1 ?
Danny02
Danny02
no there is no [color="#1C2837"]guarantee and also in my experience a little change in the code can give very different attribute ids.

[color="#1C2837"]Implementations will also differ greatly(drivers etc)

[color="#1C2837"]On the other hand you are free to force specified attributs to specific ids.

[color="#1C2837"]Normaly you will do this with the following function

[color="#1C2837"]e.g.
[color="#1C2837"]glBindAttribLocation(shader_prog,3,"myAttr")
[color="#1C2837"](after programm compiling but before linking)

[color="#1C2837"]Starting with OpenGL 3.3 I think
[color="#1C2837"]you can use directly in your shader the location qualifier

[color="#1C2837"]layout(location = 3) in vec4 myAttr;
staticVoid2
staticVoid2

no there is no [color="#1C2837"]guarantee and also in my experience a little change in the code can give very different attribute ids.

[color="#1C2837"]Implementations will also differ greatly(drivers etc)

[color="#1C2837"]On the other hand you are free to force specified attributs to specific ids.

[color="#1C2837"]Normaly you will do this with the following function

[color="#1C2837"]e.g.
[color="#1C2837"]glBindAttribLocation(shader_prog,3,"myAttr")
[color="#1C2837"](after programm compiling but before linking)

[color="#1C2837"]Starting with OpenGL 3.3 I think
[color="#1C2837"]you can use directly in your shader the location qualifier

[color="#1C2837"]layout(location = 3) in vec4 myAttr;



Thanks.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.