[GLSL] 2 beginner's questions

Hello,

I’m starting to learn more about shader programming with GLSL, but in my “studies” these 2 questions came up:

  1. Inside some Vertex Shader there’s an Uniform array of Mat4’s, which has about some 32 elements.
    Do I really need to map every single slot of that array using the “glGetUniformLocation()” and then later manually submit a matrix for every slot of this Uniform, or I can just submit a same-sized array of matrices at once?

  2. If I have different meshes with different shaders “applied” (meaning, I want to use different shaders for different meshes), how would I change which shader to use?
    Would I need to:

  • Disable the current program using glUseProgram(0) first, and then use a different program (in other words, is it really necessary to put a NULL program before changing between programs), or…
  • Simply use glUseProgram(n) and put a different program number (is that going to automatically change which type of program the renderer will use? isn’t there going to be a left over leak from the previously used program or something?).

Thanks for reading.

  1. No you can do that as a single call :
    glUniformMatrix4fv(location, 1, matrix);
    http://www.opengl.org/sdk/docs/man/xhtml/glUniform.xml

  2. Simply use glUseProgram(n). No leak to be expected, unless you keep creating new programs. Simply using programs is ok.

Thank you for the help, ZbuffeR.