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 }
// Convenience short-hand for gl.GetShaderiv. func (me *Shader) ParamInt(pname gl.Enum) (iv gl.Int) { gl.GetShaderiv(me.GlHandle, pname, &iv) return }