/** Create and initialize the WebGL context. */ public final boolean initWebGLContext() { if (gl == null) { gl = GL2ContextHelper.getGL2( getWidget(), new WebGLContextAttributes() { { setStencilEnable(true); } }); if (gl == null) { return false; } } float[] cc = getState().clearColor; gl.clearColor(cc[0], cc[1], cc[2], cc[3]); gl.clearDepth(1); gl.enable(EnableCap.DEPTH_TEST); gl.depthFunc(DepthFunction.LEQUAL); gl.clear(ClearBufferMask.COLOR_BUFFER_BIT, ClearBufferMask.DEPTH_BUFFER_BIT); try { shader = new AbstractShader() { @Override protected void initImpl() throws ShaderException { initProgram(getState().vertexShaderSource, getState().fragmentShaderSource); } }; shader.init(gl); shader.bind(); } catch (ShaderException e) { Window.alert(e.getMessage()); return false; } vertexPositionAttribute = shader.getAttributeLocation("aVertexPosition"); gl.enableVertexAttribArray(vertexPositionAttribute); vertexColorAttribute = shader.getAttributeLocation("aVertexColor"); gl.enableVertexAttribArray(vertexColorAttribute); PROJECTION.pushIdentity(); PROJECTION.perspective(getState().fov, 1, getState().minDist, getState().maxDist); gl.uniformMatrix(shader.getUniformLocation("uPMatrix"), PROJECTION.get()); PROJECTION.pop(); buildBuffers(getState().shapes); return true; }
private void setMatrixUniforms() { gl.uniformMatrix(shader.getUniformLocation("uMVMatrix"), MODELVIEW.get()); }