private static int LoadShader(int type, String source) { int id = GLES20.CreateShader(type); if (id == 0) { throw new Exception("Could not create shader."); } GLES20.ShaderSource(id, source); GLES20.CompileShader(id); int status; GLES20.GetShaderiv(id, GLES20.GL_COMPILE_STATUS, out status); if (status == 0) { String log = GLES20.GetShaderInfoLog(id); GLES20.DeleteShader(id); throw new Exception("Error compiling shader: " + log); } return(id); }
private static int LoadProgram(string vertexShader, string fragmentShader) { int id = GLES20.CreateProgram(); if (id == 0) { throw new Exception("Could not create new program."); } int vertexShaderId = LoadShader(GLES20.GL_VERTEX_SHADER, vertexShader); int fragmentShaderId = LoadShader(GLES20.GL_FRAGMENT_SHADER, fragmentShader); GLES20.AttachShader(id, vertexShaderId); GLES20.AttachShader(id, fragmentShaderId); GLES20.LinkProgram(id); GLES20.DeleteShader(vertexShaderId); GLES20.DeleteShader(fragmentShaderId); int status; GLES20.GetProgramiv(id, GLES20.GL_LINK_STATUS, out status); if (status == 0) { string log = GLES20.GetProgramInfoLog(id); GLES20.DeleteProgram(id); throw new Exception("Error linking program: " + log); } GLES20.ValidateProgram(id); GLES20.GetProgramiv(id, GLES20.GL_VALIDATE_STATUS, out status); if (status == 0) { string log = GLES20.GetProgramInfoLog(id); throw new Exception("Results of validating program: " + status + ". Log: " + log); } CheckError("Program load"); return(id); }