stackgl/webgl-workshop

Should uniforms be set after useProgram?

reverland opened this issue · 1 comments

According to shader-uniform exercise, I see something like this:

 for (var i = 0; i < 4; i ++) {
      gl.uniform1f(scaleLocation, scales[i])
      gl.uniform2fv(offsetLocation, offsets[i])
      gl.uniform3fv(colorLocation, colors[i])
      gl.useProgram(program)

It looks I should call useProgram after uniform2fv.

However, when I encounter with challenge-0, I find I must write something like this

 // uniform
    colorLocation = gl.getUniformLocation(program, 'color')
    console.log(colorLocation)
    // use program !IMPORTANT set uniform after useProgram!
    gl.useProgram(program)
    // set uniforms
    gl.uniform4fv(colorLocation, fragColor)

Or colorLocation will be nothing and I can't set uniform successfully.

It makes me confused......

anyone have time to teach me?

Yes, the program should be in use before you start setting uniforms.