Пример #1
0
func ShaderSource(name string, shader gl.Uint, source string, defines map[string]interface{}, logPrint bool) {
	var src []*gl.Char
	var i, l = 1, len(defines)
	var lines = make([]string, (l*5)+3)
	var joined string
	lines[0] = "#version 420 core\n"
	for dk, dv := range defines {
		lines[i+0] = "#define "
		lines[i+1] = dk
		lines[i+2] = " "
		lines[i+3] = fmt.Sprintf("%v", dv)
		lines[i+4] = "\n"
		i = i + 5
	}
	lines[i] = "#line 1\n"
	lines[i+1] = source
	joined = strings.Join(lines, "")
	src = gl.GLStringArray(lines...)
	defer gl.GLStringArrayFree(src)
	gl.ShaderSource(shader, gl.Sizei(len(src)), &src[0], nil)
	PanicIfErrors("ShaderSource(name=%v source=%v)", name, joined)
	if logPrint {
		log.Printf("\n\n------------------------------\n%s\n\n", joined)
	}
}
Пример #2
0
func glSetShaderSource(shader gl.Uint, source string) {
	var src = gl.GLStringArray(source)
	defer gl.GLStringArrayFree(src)
	gl.ShaderSource(shader, gl.Sizei(len(src)), &src[0], nil)
}