3
\$\begingroup\$

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...

\$\endgroup\$
  • \$\begingroup\$ 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. \$\endgroup\$ – Josh Nov 14 '13 at 18:43
  • \$\begingroup\$ (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.) \$\endgroup\$ – Josh Nov 14 '13 at 18:44
3
\$\begingroup\$

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);
\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.