module /**
 * Function used to load a shader.
 */ function loadShader ( type , gl , source ) { const glType = type === "VERTEX" ? gl . VERTEX_SHADER : gl . FRAGMENT_SHADER ; const shader = gl . createShader ( glType ) ; if ( shader === null ) { throw new Error ( `loadShader: error while creating the shader` ) ; } gl . shaderSource ( shader , source ) ; gl . compileShader ( shader ) ; const successfullyCompiled = gl . getShaderParameter ( shader , gl . COMPILE_STATUS ) ; if ( ! successfullyCompiled ) { const infoLog = gl . getShaderInfoLog ( shader ) ; gl . deleteShader ( shader ) ; throw new Error ( `loadShader: error while compiling the shader:\n${ infoLog }\n${ source }` ) ; } return shader ; } export function loadVertexShader ( gl , source ) { return loadShader ( "VERTEX" , gl , source ) ; } export function loadFragmentShader ( gl , source ) { return loadShader ( "FRAGMENT" , gl , source ) ; } /**
 * Function used to load a program.
 */ export function loadProgram ( gl , shaders ) { const program = gl . createProgram ( ) ; if ( program === null ) { throw new Error ( "loadProgram: error while creating the program." ) ; } let i , l ; for ( i = 0 , l = shaders . length ; i < l ; i ++ ) gl . attachShader ( program , shaders [ i ] ) ; gl . linkProgram ( program ) ; const successfullyLinked = gl . getProgramParameter ( program , gl . LINK_STATUS ) ; if ( ! successfullyLinked ) { gl . deleteProgram ( program ) ; throw new Error ( "loadProgram: error while linking the program." ) ; } return program ; }