index.js
function compile(gl, vertSource, fragSource, attribs, verbose) {
    var log = "";

    var vert = loadShader(gl, gl.VERTEX_SHADER, vertSource, verbose);
    var frag = loadShader(gl, gl.FRAGMENT_SHADER, fragSource, verbose);

    var vertShader = vert.shader;
    var fragShader = frag.shader;

    log += vert.log + "\n" + frag.log;

    var program = gl.createProgram();

    gl.attachShader(program, vertShader);
    gl.attachShader(program, fragShader);

    //TODO: Chrome seems a bit buggy with attribute bindings...
    if (attribs) {
        for (var key in attribs) {
            if (attribs.hasOwnProperty(key)) {
                gl.bindAttribLocation(program, Math.floor(attribs[key]), key);
            }
        }
    }

    gl.linkProgram(program); 

    log += gl.getProgramInfoLog(program) || "";

    if (!gl.getProgramParameter(program, gl.LINK_STATUS)) {
        if (verbose) {
            console.error("Shader error:\n"+log);
            console.error("Problematic shaders:\nVERTEX_SHADER:\n"+addLineNumbers(vertSource)
                    +"\n\nFRAGMENT_SHADER:\n"+addLineNumbers(fragSource));
        }
        //delete before throwing error    
        gl.detachShader(program, vertShader);
        gl.detachShader(program, fragShader);
        gl.deleteShader(vertShader);
        gl.deleteShader(fragShader);
        
        throw new Error("Error linking the shader program:\n" + log);

    }
    return {
        program: program,
        vertex: vertShader,
        fragment: fragShader,
        log: log.trim()
    };
}
function compile(gl, vertSource, fragSource, attribs, verbose) {
    var log = "";

    var vert = loadShader(gl, gl.VERTEX_SHADER, vertSource, verbose);
    var frag = loadShader(gl, gl.FRAGMENT_SHADER, fragSource, verbose);

    var vertShader = vert.shader;
    var fragShader = frag.shader;

    log += vert.log + "\n" + frag.log;

    var program = gl.createProgram();

    gl.attachShader(program, vertShader);
    gl.attachShader(program, fragShader);

    //TODO: Chrome seems a bit buggy with attribute bindings...
    if (attribs) {
        for (var key in attribs) {
            if (attribs.hasOwnProperty(key)) {
                gl.bindAttribLocation(program, Math.floor(attribs[key]), key);
            }
        }
    }

    gl.linkProgram(program); 

    log += gl.getProgramInfoLog(program) || "";

    if (!gl.getProgramParameter(program, gl.LINK_STATUS)) {
        if (verbose) {
            console.error("Shader error:\n"+log);
            console.error("Problematic shaders:\nVERTEX_SHADER:\n"+addLineNumbers(vertSource)
                    +"\n\nFRAGMENT_SHADER:\n"+addLineNumbers(fragSource));
        }
        //delete before throwing error    
        gl.detachShader(program, vertShader);
        gl.detachShader(program, fragShader);
        gl.deleteShader(vertShader);
        gl.deleteShader(fragShader);
        
        throw new Error("Error linking the shader program:\n" + log);

    }
    return {
        program: program,
        vertex: vertShader,
        fragment: fragShader,
        log: log.trim()
    };
}
function compile ( gl , vertSource , fragSource , attribs , verbose ) { var log = "" ; var vert = loadShader ( gl , gl . VERTEX_SHADER , vertSource , verbose ) ; var frag = loadShader ( gl , gl . FRAGMENT_SHADER , fragSource , verbose ) ; var vertShader = vert . shader ; var fragShader = frag . shader ; log += vert . log + "\n" + frag . log ; var program = gl . createProgram ( ) ; gl . attachShader ( program , vertShader ) ; gl . attachShader ( program , fragShader ) ; //TODO: Chrome seems a bit buggy with attribute bindings... if ( attribs ) { for ( var key in attribs ) { if ( attribs . hasOwnProperty ( key ) ) { gl . bindAttribLocation ( program , Math . floor ( attribs [ key ] ) , key ) ; } } } gl . linkProgram ( program ) ; log += gl . getProgramInfoLog ( program ) || "" ; if ( ! gl . getProgramParameter ( program , gl . LINK_STATUS ) ) { if ( verbose ) { console . error ( "Shader error:\n" + log ) ; console . error ( "Problematic shaders:\nVERTEX_SHADER:\n" + addLineNumbers ( vertSource ) + "\n\nFRAGMENT_SHADER:\n" + addLineNumbers ( fragSource ) ) ; } //delete before throwing error     gl . detachShader ( program , vertShader ) ; gl . detachShader ( program , fragShader ) ; gl . deleteShader ( vertShader ) ; gl . deleteShader ( fragShader ) ; throw new Error ( "Error linking the shader program:\n" + log ) ; } return { program : program , vertex : vertShader , fragment : fragShader , log : log . trim ( ) } ; }
Compiles the shaders, throwing an error if the program was invalid.
Compiles the shaders throwing an error if the program was invalid .