Esempio n. 1
0
func compileShaders() (err error) {
	var glStatus gl.Int

	makeShader := func(stage gl.Enum, src string) (shader gl.Uint) {
		shader = gl.CreateShader(stage)
		logLastGlError("gl.CreateShader()")
		glStr := gl.Util.CStringArray(src)
		defer gl.Util.CStringArrayFree(glStr)
		gl.ShaderSource(shader, gl.Sizei(len(glStr)), &glStr[0], nil)
		logLastGlError("gl.ShaderSource()")
		gl.CompileShader(shader)
		if gl.GetShaderiv(shader, gl.COMPILE_STATUS, &glStatus); glStatus == 0 {
			panic("Shader compilation failed: " + src)
		}
		return
	}

	glVertShader := makeShader(gl.VERTEX_SHADER, srcVertShader)
	defer gl.DeleteShader(glVertShader)
	glFragShader := makeShader(gl.FRAGMENT_SHADER, srcFragShader)
	defer gl.DeleteShader(glFragShader)

	shaderProg = gl.CreateProgram()
	for stageName, shader := range map[string]gl.Uint{"vert": glVertShader, "frag": glFragShader} {
		gl.AttachShader(shaderProg, shader)
		logLastGlError("gl.AttachShader " + stageName)
		defer gl.DetachShader(shaderProg, shader)
	}

	gl.LinkProgram(shaderProg)
	if gl.GetProgramiv(shaderProg, gl.LINK_STATUS, &glStatus); glStatus == 0 {
		panic("Program linking failed...")
	}

	glAttName := gl.Util.CString("aPos")
	defer gl.Util.CStringFree(glAttName)
	progPosAttrLoc = gl.Uint(gl.GetAttribLocation(shaderProg, glAttName))
	logLastGlError("gl.GetAttribLocation()")

	return
}
Esempio n. 2
0
//	Links this program object. This is a convenience short-hand for calling gl.LinkProgram(),
//	checking gl.LINK_STATUS and obtaining gl.GetProgramInfoLog().
func (me *Program) Link() (err error) {
	if gl.LinkProgram(me.GlHandle); me.ParamInt(gl.LINK_STATUS) == gl.FALSE {
		err = errf("Program'%s'.Link() error: %s\n", me.Name, me.InfoLog())
	}
	return
}