func shinit() gl.Int { vs := loadShader(gl.VERTEX_SHADER, vss) var sfs string if *blend { sfs = bfss } else { sfs = fss } fs := loadShader(gl.FRAGMENT_SHADER, sfs) prg := gl.CreateProgram() gl.AttachShader(prg, vs) gl.AttachShader(prg, fs) gl.LinkProgram(prg) var l int if *blend { l = 6 } else { l = 3 } gl.UseProgram(prg) names := []string{"yt1", "cbt1", "crt1", "yt0", "cbt0", "crt0"} for i := 0; i < l; i++ { loc := gl.GetUniformLocation(prg, gl.GLString(names[i])) gl.Uniform1i(loc, gl.Int(i)) } return gl.GetUniformLocation(prg, gl.GLString("factor")) }
func (s *Shader) initUniform(name string, uni *gl.Int) { uni_name := gl.GLString(name) defer gl.GLStringFree(uni_name) *uni = gl.GetUniformLocation(s.program, uni_name) if *uni == -1 { fmt.Println("Error in getting uniform", gl.GoString(uni_name)) } }
func SetUniform4F(shader, variable string, vs []float32) error { prog, ok := shader_progs[shader] if !ok { return shaderError(fmt.Sprintf("Tried to set a uniform in an unknown shader '%s'", shader)) } bvariable := []byte(fmt.Sprintf("%s\x00", variable)) loc := gl.GetUniformLocation(prog, (*gl.Char)(unsafe.Pointer(&bvariable[0]))) gl.Uniform4f(loc, gl.Float(vs[0]), gl.Float(vs[1]), gl.Float(vs[2]), gl.Float(vs[3])) return nil }
func SetUniformI(shader, variable string, n int) error { prog, ok := shader_progs[shader] if !ok { return shaderError(fmt.Sprintf("Tried to set a uniform in an unknown shader '%s'", shader)) } bvariable := []byte(fmt.Sprintf("%s\x00", variable)) loc := gl.GetUniformLocation(prog, (*gl.Char)(unsafe.Pointer(&bvariable[0]))) gl.Uniform1i(loc, gl.Int(n)) return nil }
func SetUniformF(shader, variable string, f float32) { prog, ok := shader_progs[shader] if !ok { if !warned_names[shader] { Warn().Printf("Tried to set a uniform in an unknown shader '%s'", shader) warned_names[shader] = true } return } bvariable := []byte(fmt.Sprintf("%s\x00", variable)) loc := gl.GetUniformLocation(prog, (*gl.Char)(unsafe.Pointer(&bvariable[0]))) gl.Uniform1f(loc, f) }
func SetUniformV2Array(shader, variable string, vs []linear.Vec2) { prog, ok := shader_progs[shader] if !ok { if !warned_names[shader] { Warn().Printf("Tried to set a uniform in an unknown shader '%s'", shader) warned_names[shader] = true } return } bvariable := []byte(fmt.Sprintf("%s\x00", variable)) loc := gl.GetUniformLocation(prog, (*gl.Char)(unsafe.Pointer(&bvariable[0]))) var fs []gl.Float for i := range vs { fs = append(fs, gl.Float(vs[i].X)) fs = append(fs, gl.Float(vs[i].Y)) } gl.Uniform2fv(loc, gl.Sizei(len(vs)), (*gl.Float)(unsafe.Pointer(&fs[0]))) }
func (effect *Effect) checkUniformVariable(variable string) { if _, ok := effect.uniforms[variable]; !ok { effect.uniforms[variable] = gl.GetUniformLocation(effect.program, gl.GLString(variable)) } }