示例#1
0
// Implements Renderer interface.
func (gc *opengl) BindShader(sh *data.Shader) (pref uint32, err error) {
	pref = gl.CreateProgram()

	// FUTURE: get rid of BindAttribLocation and use layout instead.
	//         this needs GLSL 330 instead of 150
	//         eg: layout(location=0) in vec4 in_position;
	gl.BindAttribLocation(pref, 0, "in_v") // matches vattr in bindModel
	gl.BindAttribLocation(pref, 1, "in_n") // matches nattr in bindModel
	gl.BindAttribLocation(pref, 2, "in_t") // matches tattr in bindModel

	// compile and link the shader program.
	if glerr := gl.BindProgram(pref, sh.Vsh, sh.Fsh); glerr != nil {
		err = fmt.Errorf("Failed to create shader program: %s\n", glerr)
		return
	}

	// initialize the uniform references
	var errmsg string
	for label, _ := range sh.Uniforms {
		if uid := gl.GetUniformLocation(pref, label); uid >= 0 {
			sh.Uniforms[label] = uid
		} else {
			errnum := gl.GetError()
			errmsg += fmt.Sprintf("No %s uniform in shader %X\n", label, errnum)
		}
	}
	if len(errmsg) > 0 {
		err = errors.New(errmsg)
	}
	if glerr := gl.GetError(); glerr != gl.NO_ERROR {
		log.Printf("opengl:bindShader need to find and fix error %X", glerr)
	}
	return
}
示例#2
0
文件: ld.go 项目: krattai/monoflow
// initShader compiles shaders and links them into a shader program.
func (ld *ldtag) initShader() {
	shader := &data.Shader{}
	loader := data.NewLoader()
	loader.Load("monkey", &shader)
	ld.shaders = gl.CreateProgram()
	gl.BindAttribLocation(ld.shaders, 0, "inPosition")
	gl.BindAttribLocation(ld.shaders, 1, "inNormal")
	if err := gl.BindProgram(ld.shaders, shader.Vsh, shader.Fsh); err != nil {
		fmt.Printf("Failed to create program: %s\n", err)
	}
	ld.mvpref = gl.GetUniformLocation(ld.shaders, "modelViewProjectionMatrix")
	if ld.mvpref < 0 {
		fmt.Printf("No modelViewProjectionMatrix in vertex shader\n")
	}
}
示例#3
0
文件: tb.go 项目: krattai/monoflow
// initShader compiles shaders and links them into a shader program.
func (tb *tbtag) initShader() {
	shader := &data.Shader{}
	loader := data.NewLoader()
	loader.Load("tuv", &shader)
	tb.shaders = gl.CreateProgram()
	gl.BindAttribLocation(tb.shaders, 0, "vertexPosition")
	gl.BindAttribLocation(tb.shaders, 2, "uvPoint")
	if err := gl.BindProgram(tb.shaders, shader.Vsh, shader.Fsh); err != nil {
		fmt.Printf("Failed to create program: %s\n", err)
	}
	tb.mvpref = gl.GetUniformLocation(tb.shaders, "Mvpm")
	tb.sampler = gl.GetUniformLocation(tb.shaders, "uvSampler")
	if tb.mvpref < 0 {
		fmt.Printf("No model-view-projection matrix in vertex shader\n")
	}
}