# What is the difference between shader uniforms and attributes in OpenGL?

I don't fully understand the differences between uniforms and attributes. To be honest, I probably haven't even used attributes.

Can uniforms change for each vertex? I mean to calculate the vertex's position in screen space I just multiply the vertex's local position by the model matrix, then by the view matrix and then by the projection matrix.

Projection is constant throughout the whole scene, view is constant throughout one frame, but the model matrix changes with every object. Meaning the uniform I supply to the vertex shader as the model matrix changes a lot of times per frame. Is that good? I mean I don't see another way of transforming the object...

• Hi, welcome to the site! We are a Q&A site, not a discussion forum, so it's better to focus on a single question or topic in each post. Because your post had two vastly different questions in it, I edited out the second one. Feel free, however, to re-post that question separately. – user1430 Nov 14 '13 at 18:43
• (If you don't know, you view the old revisions of the question by clicking the edited timestamp above and that way you don't have to re-type your original query.) – user1430 Nov 14 '13 at 18:44

uniforms will remain the same for all vertices (this is why they are called uniforms)

if you want to change it you need to call gldraw* twice and set the new uniform between them:

glUniformMatrix4fv(mvpMatLoc, 1, false, mvp1);
glDrawArrays(mode, off1, count1);
glUniformMatrix4fv(mvpMatLoc, 1, false, mvp1);
glDrawArrays(mode, off2, count2);