private GLShaderProgram _compileProgram(string vertexSource, string fragmentSource, string name = null) { GLShader vertexShader = null; GLShader fragmentShader = null; try { try { vertexShader = new GLShader(this, ShaderType.VertexShader, vertexSource, name == null ? $"{name}-vertex" : null); } catch (ShaderCompilationException e) { throw new ShaderCompilationException( "Failed to compile vertex shader, see inner for details.", e); } try { fragmentShader = new GLShader(this, ShaderType.FragmentShader, fragmentSource, name == null ? $"{name}-fragment" : null); } catch (ShaderCompilationException e) { throw new ShaderCompilationException( "Failed to compile fragment shader, see inner for details.", e); } var program = new GLShaderProgram(this, name); program.Add(vertexShader); program.Add(fragmentShader); try { program.Link(); } catch (ShaderCompilationException e) { program.Delete(); throw new ShaderCompilationException("Failed to link shaders. See inner for details.", e); } return(program); } finally { vertexShader?.Delete(); fragmentShader?.Delete(); } }