private static GLShader GetShader(WebGLContext gl, string id) { var shaderScript = Element.GetById(id); var str = shaderScript.TextContent; if (str == "" || str == null) { var k = shaderScript.FirstChild; while (k != null) { if (k.NodeType == 3) { str += k.TextContent; } k = k.NextSibling; } } GLShader shader; if (shaderScript.GetAttributeValue("type") == "x-shader/x-fragment") { shader = gl.CreateShader(gl.FragmentShader); } else if (shaderScript.GetAttributeValue("type") == "x-shader/x-vertex") { shader = gl.CreateShader(gl.VertexShader); } else { return(null); } gl.ShaderSource(shader, str); gl.CompileShader(shader); if (!gl.GetShaderParameter(shader, gl.CompileStatus)) { throw new Exception("Shader compilation failed"); } return(shader); }
private WebGLShader LoadShader(WebGLContext gl, ShaderType type, string source) { var shader = gl.CreateShader(type); gl.ShaderSource(shader, source); gl.CompileShader(shader); if (!gl.GetShaderParameter <bool>(shader, ShaderParameter.COMPILE_STATUS)) { string info = gl.GetShaderInfoLog(shader); gl.DeleteShader(shader); throw new Exception("An error occured while compiling the shader: " + info); } return(shader); }