예제 #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))
		}
	}
}
예제 #2
0
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
	}
}
예제 #3
0
	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))
		case textureType: