Esempio n. 1
0
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))
		}
	}
}
Esempio n. 2
0
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
	}
}
Esempio n. 3
0
	gl.AttachShader(program, gl.Uint(fragmentShader))
	gl.LinkProgram(program)
	var ok gl.Int
	gl.GetProgramiv(program, gl.LINK_STATUS, &ok)
	if ok == 0 {
		fmt.Fprintln(os.Stderr, gl.GetProgramInfoLog(program))
		gl.DeleteProgram(program)
		return errors.New("Failed to link shader program")
	}
	return nil
}

var bufferType = reflect.TypeOf(gl.Buffer(0))
var textureType = reflect.TypeOf(gl.Texture(0))
var vaoType = reflect.TypeOf(gl.VertexArrayObject(0))
var vertexShaderType = reflect.TypeOf(gl.VertexShader(0))
var fragmentShaderType = reflect.TypeOf(gl.FragmentShader(0))
var programType = reflect.TypeOf(gl.Program(0))
var uniformLocationType = reflect.TypeOf(gl.UniformLocation(0))
var attributeLocationType = reflect.TypeOf(gl.AttributeLocation(0))

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))