func glGetInfoLog(shaderOrProgram gl.Uint, isShader bool) string { var l = gl.Sizei(256) var s = gl.GLStringAlloc(l) defer gl.GLStringFree(s) if isShader { gl.GetShaderInfoLog(shaderOrProgram, l, nil, s) } else { gl.GetProgramInfoLog(shaderOrProgram, l, nil, s) } return gl.GoString(s) }
func ShaderInfoLog(shaderOrProgram gl.Uint, isShader bool) string { var l = gl.Sizei(256) var s = gl.GLStringAlloc(l) defer gl.GLStringFree(s) if isShader { gl.GetShaderInfoLog(shaderOrProgram, l, nil, s) } else { gl.GetProgramInfoLog(shaderOrProgram, l, nil, s) } PanicIfErrors("ShaderInfoLog(s=%v)", isShader) return gl.GoString(s) }
func glGetLocation(glProg gl.Uint, name string, isAtt bool) gl.Uint { var a gl.Int var s = gl.GLString(name) defer gl.GLStringFree(s) if isAtt { a = gl.GetAttribLocation(glProg, s) } else { a = gl.GetUniformLocation(glProg, s) } if a < 0 { panic("Shader attribute or uniform bind error") } return gl.Uint(a) }
func ShaderLocation(glProg gl.Uint, name string, isAtt bool) gl.Int { var loc gl.Int var s = gl.GLString(name) defer gl.GLStringFree(s) if isAtt { loc = gl.GetAttribLocation(glProg, s) } else { loc = gl.GetUniformLocation(glProg, s) } // if loc < 0 { log.Panicf("sprog att/uni %s: bind error %d", name, loc) } // PanicIfErrors("ShaderLocation(n=%v a=%v)", name, isAtt) LastErrors() return loc }
// Loads a shader from a string func LoadShader(typ g.Enum, s string) g.Uint { shader := g.CreateShader(typ) cst := g.GLString(s) defer g.GLStringFree(cst) g.ShaderSource(shader, 1, &cst, nil) g.CompileShader(shader) var status g.Int g.GetShaderiv(shader, g.COMPILE_STATUS, &status) if status == g.FALSE { var length g.Int g.GetShaderiv(shader, g.INFO_LOG_LENGTH, &length) log.Println(int(length)) logStr := g.GLStringAlloc(g.Sizei(length + 1)) // TODO: defer g.GetShaderInfoLog(shader, g.Sizei(length), nil, logStr) log.Println(g.GoString(logStr)) } return shader }
func GetUniformLocation(p g.Uint, s string) g.Int { cstr := g.GLString(s) defer g.GLStringFree(cstr) return g.GetUniformLocation(p, cstr) }