func compileShaders() (err error) { var glStatus gl.Int makeShader := func(stage gl.Enum, src string) (shader gl.Uint) { shader = gl.CreateShader(stage) logLastGlError("gl.CreateShader()") glStr := gl.Util.CStringArray(src) defer gl.Util.CStringArrayFree(glStr) gl.ShaderSource(shader, gl.Sizei(len(glStr)), &glStr[0], nil) logLastGlError("gl.ShaderSource()") gl.CompileShader(shader) if gl.GetShaderiv(shader, gl.COMPILE_STATUS, &glStatus); glStatus == 0 { panic("Shader compilation failed: " + src) } return } glVertShader := makeShader(gl.VERTEX_SHADER, srcVertShader) defer gl.DeleteShader(glVertShader) glFragShader := makeShader(gl.FRAGMENT_SHADER, srcFragShader) defer gl.DeleteShader(glFragShader) shaderProg = gl.CreateProgram() for stageName, shader := range map[string]gl.Uint{"vert": glVertShader, "frag": glFragShader} { gl.AttachShader(shaderProg, shader) logLastGlError("gl.AttachShader " + stageName) defer gl.DetachShader(shaderProg, shader) } gl.LinkProgram(shaderProg) if gl.GetProgramiv(shaderProg, gl.LINK_STATUS, &glStatus); glStatus == 0 { panic("Program linking failed...") } glAttName := gl.Util.CString("aPos") defer gl.Util.CStringFree(glAttName) progPosAttrLoc = gl.Uint(gl.GetAttribLocation(shaderProg, glAttName)) logLastGlError("gl.GetAttribLocation()") return }
// Calls gl.ShaderSource() and yields the err returned by Util.LastError(), if any. func (_ GlTry) ShaderSource(shader gl.Uint, count gl.Sizei, string_ **gl.Char, length *gl.Int) (err error) { gl.ShaderSource(shader, count, string_, length) err = Util.LastError("gl.ShaderSource()") return }