Exemple #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
}
Exemple #2
0
//	Calls gl.CreateProgram() and yields the err returned by Util.LastError(), if any.
func (_ GlTry) CreateProgram() (err error, tryRetVal__ gl.Uint) {
	tryRetVal__ = gl.CreateProgram()
	err = Util.LastError("gl.CreateProgram()")
	return
}