src/programs.js
function createUniformSetters(gl, program) {
  let textureUnit = 0;

  /**
   * Creates a setter for a uniform of the given program with it's
   * location embedded in the setter.
   * @param {WebGLProgram} program
   * @param {WebGLUniformInfo} uniformInfo
   * @returns {function} the created setter.
   */
  function createUniformSetter(program, uniformInfo) {
    const location = gl.getUniformLocation(program, uniformInfo.name);
    const isArray = (uniformInfo.size > 1 && uniformInfo.name.substr(-3) === "[0]");
    const type = uniformInfo.type;
    const typeInfo = typeMap[type];
    if (!typeInfo) {
      throw ("unknown type: 0x" + type.toString(16)); // we should never get here.
    }
    let setter;
    if (typeInfo.bindPoint) {
      // it's a sampler
      const unit = textureUnit;
      textureUnit += uniformInfo.size;
      if (isArray) {
        setter = typeInfo.arraySetter(gl, type, unit, location, uniformInfo.size);
      } else {
        setter = typeInfo.setter(gl, type, unit, location, uniformInfo.size);
      }
    } else {
      if (typeInfo.arraySetter && isArray) {
        setter = typeInfo.arraySetter(gl, location);
      } else {
        setter = typeInfo.setter(gl, location);
      }
    }
    setter.location = location;
    return setter;
  }

  const uniformSetters = { };
  const numUniforms = gl.getProgramParameter(program, gl.ACTIVE_UNIFORMS);

  for (let ii = 0; ii < numUniforms; ++ii) {
    const uniformInfo = gl.getActiveUniform(program, ii);
    if (isBuiltIn(uniformInfo)) {
        continue;
    }
    let name = uniformInfo.name;
    // remove the array suffix.
    if (name.substr(-3) === "[0]") {
      name = name.substr(0, name.length - 3);
    }
    const setter = createUniformSetter(program, uniformInfo);
    uniformSetters[name] = setter;
  }
  return uniformSetters;
}
function createUniformSetters(gl, program) {
  let textureUnit = 0;

  /**
   * Creates a setter for a uniform of the given program with it's
   * location embedded in the setter.
   * @param {WebGLProgram} program
   * @param {WebGLUniformInfo} uniformInfo
   * @returns {function} the created setter.
   */
  function createUniformSetter(program, uniformInfo) {
    const location = gl.getUniformLocation(program, uniformInfo.name);
    const isArray = (uniformInfo.size > 1 && uniformInfo.name.substr(-3) === "[0]");
    const type = uniformInfo.type;
    const typeInfo = typeMap[type];
    if (!typeInfo) {
      throw ("unknown type: 0x" + type.toString(16)); // we should never get here.
    }
    let setter;
    if (typeInfo.bindPoint) {
      // it's a sampler
      const unit = textureUnit;
      textureUnit += uniformInfo.size;
      if (isArray) {
        setter = typeInfo.arraySetter(gl, type, unit, location, uniformInfo.size);
      } else {
        setter = typeInfo.setter(gl, type, unit, location, uniformInfo.size);
      }
    } else {
      if (typeInfo.arraySetter && isArray) {
        setter = typeInfo.arraySetter(gl, location);
      } else {
        setter = typeInfo.setter(gl, location);
      }
    }
    setter.location = location;
    return setter;
  }

  const uniformSetters = { };
  const numUniforms = gl.getProgramParameter(program, gl.ACTIVE_UNIFORMS);

  for (let ii = 0; ii < numUniforms; ++ii) {
    const uniformInfo = gl.getActiveUniform(program, ii);
    if (isBuiltIn(uniformInfo)) {
        continue;
    }
    let name = uniformInfo.name;
    // remove the array suffix.
    if (name.substr(-3) === "[0]") {
      name = name.substr(0, name.length - 3);
    }
    const setter = createUniformSetter(program, uniformInfo);
    uniformSetters[name] = setter;
  }
  return uniformSetters;
}
function createUniformSetters ( gl , program ) { let textureUnit = 0 ; /**
   * Creates a setter for a uniform of the given program with it's
   * location embedded in the setter.
   * @param {WebGLProgram} program
   * @param {WebGLUniformInfo} uniformInfo
   * @returns {function} the created setter.
   */ function createUniformSetter ( program , uniformInfo ) { const location = gl . getUniformLocation ( program , uniformInfo . name ) ; const isArray = ( uniformInfo . size > 1 && uniformInfo . name . substr ( - 3 ) === "[0]" ) ; const type = uniformInfo . type ; const typeInfo = typeMap [ type ] ; if ( ! typeInfo ) { throw ( "unknown type: 0x" + type . toString ( 16 ) ) ; // we should never get here. } let setter ; if ( typeInfo . bindPoint ) { // it's a sampler const unit = textureUnit ; textureUnit += uniformInfo . size ; if ( isArray ) { setter = typeInfo . arraySetter ( gl , type , unit , location , uniformInfo . size ) ; } else { setter = typeInfo . setter ( gl , type , unit , location , uniformInfo . size ) ; } } else { if ( typeInfo . arraySetter && isArray ) { setter = typeInfo . arraySetter ( gl , location ) ; } else { setter = typeInfo . setter ( gl , location ) ; } } setter . location = location ; return setter ; } const uniformSetters = { } ; const numUniforms = gl . getProgramParameter ( program , gl . ACTIVE_UNIFORMS ) ; for ( let ii = 0 ; ii < numUniforms ; ++ ii ) { const uniformInfo = gl . getActiveUniform ( program , ii ) ; if ( isBuiltIn ( uniformInfo ) ) { continue ; } let name = uniformInfo . name ; // remove the array suffix. if ( name . substr ( - 3 ) === "[0]" ) { name = name . substr ( 0 , name . length - 3 ) ; } const setter = createUniformSetter ( program , uniformInfo ) ; uniformSetters [ name ] = setter ; } return uniformSetters ; }
Creates setter functions for all uniforms of a shader
program.

@see {@link module:twgl.setUniforms}

@param {WebGLProgram} program the program to create setters for.
@returns {Object.<string, function>} an object with a setter by name for each uniform
@memberOf module:twgl/programs
Creates setter functions for all uniforms of a shader program .