Search code examples
c++shaderopengl-4

opengl difference setting value in layout location or uniform variable


i am trying to get myself familiar with opengl programming. I cant stop wondering when should i use layout for variable input to a shader (with glVertexAttribPointer) vs just setting an uniform with glUniform. What are the advantage and when should i use one over the other? kind regards


Solution

  • It depends what you want to do with the value. If you want to pass in a single value to the shader, which won't change for each vertex, then you use a uniform. If you want to pass in multiple values so each vertex can have a different value, then you use an attribute pointer.