public static WebGLShader createShader(int type, String code, WebGLRenderingContext ctx) { WebGLShader shader = ctx.createShader(type); ctx.shaderSource(shader, code); ctx.compileShader(shader); if (testShaderStatus(ctx, shader)) return shader; // else error String lastError = ctx.getShaderInfoLog(shader); Window.alert("*** Error compiling shader '" + shader + "':" + lastError); ctx.deleteShader(shader); return null; }
public static WebGLProgram createAndUseProgram( List<WebGLShader> shaders, WebGLRenderingContext ctx) { WebGLProgram program = ctx.createProgram(); for (WebGLShader s : shaders) ctx.attachShader(program, s); ctx.linkProgram(program); if (ctx.getProgramParameter(program, WebGLRenderingContext.LINK_STATUS).getBoolean()) { ctx.useProgram(program); return program; } // else error String lastError = ctx.getProgramInfoLog(program); Window.alert("*** Error compiling program '" + program + "':" + lastError); ctx.deleteProgram(program); return null; }
private static boolean testShaderStatus(WebGLRenderingContext ctx, WebGLShader shader) { Any a = ctx.getShaderParameter(shader, WebGLRenderingContext.COMPILE_STATUS); return a.getBoolean(); }