var canvas = document.createElement("canvas"); var gl = canvas.getContext("webgl"); var ext = gl.getExtension('KHR_parallel_shader_compile'); if (ext) { // Just for demo of API usage. Generally it's not needed unless you really // want to override the implementation-specific maximum. var threads = gl.getParameter(ext.MAX_SHADER_COMPILER_THREADS_KHR); ext.maxShaderCompilerThreadsKHR(Math.max(2, threads)); } var vSource = "attribute vec2 position; void main() { gl_Position = vec4(position, 0, 1); }"; var fSource = "precision mediump float; void main() { gl_FragColor = vec4(1,0,0,1); }"; var vShader = gl.createShader(gl.VERTEX_SHADER); gl.shaderSource(vShader, vSource); gl.compileShader(vShader); var fShader = gl.createShader(gl.FRAGMENT_SHADER); gl.shaderSource(fShader, fSource); gl.compileShader(fShader); var program = gl.createProgram(); gl.attachShader(program, vShader); gl.attachShader(program, fShader); gl.linkProgram(program); function checkToUseProgram() { if (gl.getProgramParameter(program, gl.LINK_STATUS) == true) { gl.useProgram(program); } else { // error check. } } if (ext) { function checkCompletion() { if (gl.getProgramParameter(program, ext.COMPLETION_STATUS_KHR) == true) { checkToUseProgram(); } else { requestAnimationFrame(checkCompletion); } } requestAnimationFrame(checkCompletion); } else { checkToUseProgram(); }