1
\$\begingroup\$

I have a single mesh, and I give the vertex-shader a matrix which holds the objects position, scale and rotation. It seems to work.

in vec3 position;
uniform mat4 object;
uniform mat4 view;
uniform mat4 proj;

void main() {
   gl_Position = proj * view * object * vec4(position, 1.0);
}

What if I have multiple meshes? What is the standard way to approach this? Feed in a different mat4 for every mesh rendered, or have separate vertex shaders for each mesh?

\$\endgroup\$

1 Answer 1

4
\$\begingroup\$

Each mesh gets a different object matrix (world transformation matrix).

A common sequence of rendering multiple meshes is :

  • Use shader program
  • Set the uniforms for Mesh1
  • Bind VAO/VBO's for Mesh1
  • Draw

  • Set uniform for world matrix for Mesh2

  • Bind VBO/VAO for Mesh2
  • Draw

    ....

\$\endgroup\$
1
  • \$\begingroup\$ thanks mate, being a newb I still don't fully get VBO/VAO stuff, but I'll go do some more reading :) \$\endgroup\$ Commented Nov 3, 2015 at 11:02

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .