func Bind(bindings interface{}) { value := reflect.ValueOf(bindings).Elem() n := value.NumField() for i := 0; i < n; i++ { field := value.Field(i) switch field.Type() { case bufferType: buffer := gl.GenBuffer() field.Set(reflect.ValueOf(buffer)) case textureType: texture := gl.GenTexture() field.Set(reflect.ValueOf(texture)) case vaoType: vao := gl.GenVertexArray() field.Set(reflect.ValueOf(vao)) case vertexShaderType: shader := gl.VertexShader(gl.CreateShader(gl.VERTEX_SHADER)) field.Set(reflect.ValueOf(shader)) case fragmentShaderType: shader := gl.FragmentShader(gl.CreateShader(gl.FRAGMENT_SHADER)) field.Set(reflect.ValueOf(shader)) case programType: program := gl.CreateProgram() field.Set(reflect.ValueOf(program)) } } }
func (lib *ShaderLibrary) LoadVertexShader(tag, filename string) { _, ok := lib.VertexShaders[tag] if !ok { shader := gl.VertexShader(gl.CreateShader(gl.VERTEX_SHADER)) err := LoadVertexShaderSource(shader, filename) if err != nil { panic(err) } lib.VertexShaders[tag] = shader } }
func (lib *ShaderLibrary) LoadFragmentShader(tag, filename string) { _, ok := lib.FragmentShaders[tag] if !ok { shader := gl.FragmentShader(gl.CreateShader(gl.FRAGMENT_SHADER)) err := LoadFragmentShaderSource(shader, filename) if err != nil { panic(err) } lib.FragmentShaders[tag] = shader } }