Exemple #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))
		}
	}
}
Exemple #2
0
func (lib *ShaderLibrary) LoadProgram(tag, vsfilename, fsfilename string) {
	vtag := tag + "_vs"
	ftag := tag + "_fs"
	lib.LoadVertexShader(vtag, vsfilename)
	lib.LoadFragmentShader(ftag, fsfilename)
	program := gl.CreateProgram()
	err := LoadProgram(program, lib.VertexShaders[vtag], lib.FragmentShaders[ftag])
	if err != nil {
		panic(err)
	}
	_, ok := lib.Programs[tag]
	if !ok {
		lib.Programs[tag] = program
	} else {
		panic("program: '" + tag + "' already defined")
	}
}