All files / core/domain/utils/webgl loadProgram.js

0% Statements 0/14
0% Branches 0/8
0% Functions 0/1
0% Lines 0/13

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35                                                                     
/**
 * Creates a program, attaches shaders, binds attrib locations, links the
 * program and calls useProgram.
 *
 * @param  {Array.<WebGLShader>}    shaders   The shaders to attach.
 * @param  {Array.<string>}         attribs   The attribs names.
 * @param  {Array.<number>}         locations The locations for the attribs.
 * @param  {function(string): void} error     Callback for errors.
 * @return {WebGLProgram}                     The created program.
 */
export default function loadProgram(gl, shaders, attribs, locations, error) {
  let i;
  const program = gl.createProgram();
 
  for (i = 0; i < shaders.length; ++i) gl.attachShader(program, shaders[i]);
 
  if (attribs)
    for (i = 0; i < attribs.length; ++i)
      gl.bindAttribLocation(program, locations ? locations[i] : i, attribs[i]);
 
  gl.linkProgram(program);
 
  // Check the link status
  const linked = gl.getProgramParameter(program, gl.LINK_STATUS);
  if (!linked) {
    if (error)
      error(`Error in program linking: ${gl.getProgramInfoLog(program)}`);
 
    gl.deleteProgram(program);
    return null;
  }
 
  return program;
}