示例#1
0
func createShader(name string, shaderType int) (gl.Uint, error) {
	data, err := fileRead(name)
	if err != nil {
		return 0, err
	}
	if len(data) == 0 {
		return 0, errors.New("No shader code.")
	}
	var shader gl.Uint
	switch shaderType {
	case VertexShaderType:
		shader = gl.CreateShader(gl.VERTEX_SHADER)
	case FragmentShaderType:
		shader = gl.CreateShader(gl.FRAGMENT_SHADER)
	default:
		return 0, errors.New("Unknown ShaderType.")
	}
	src := gl.GLStringArray(string(data))
	defer gl.GLStringArrayFree(src)
	gl.ShaderSource(shader, gl.Sizei(1), &src[0], nil)
	gl.CompileShader(shader)

	// Similar to print_log in the C code example
	var length gl.Int
	gl.GetShaderiv(shader, gl.INFO_LOG_LENGTH, &length)
	if length > 1 {
		glString := gl.GLStringAlloc(gl.Sizei(length))
		defer gl.GLStringFree(glString)
		gl.GetShaderInfoLog(shader, gl.Sizei(length), nil, glString)
		return 0, errors.New(fmt.Sprintf("Shader log: %s", gl.GoString(glString)))
	}
	return shader, nil
}
示例#2
0
文件: shader.go 项目: klkblake/sge
func (shader *Shader) GetInfoLog() string {
	length := shader.Get(gl33.INFO_LOG_LENGTH)
	log := gl33.GLStringAlloc(gl33.Sizei(length + 1))
	defer gl33.GLStringFree(log)
	gl33.GetShaderInfoLog(shader.Id, gl33.Sizei(length), nil, log)
	return gl33.GoString(log)
}
示例#3
0
func (p *Program) getError() error {
	var logLength gl.Int
	gl.GetProgramiv(p.id, gl.INFO_LOG_LENGTH, &logLength)
	log := gl.GLStringAlloc(gl.Sizei(logLength))
	defer gl.GLStringFree(log)
	gl.GetProgramInfoLog(p.id, gl.Sizei(logLength), nil, log)
	err := gl.GoString(log)
	return errors.New(err)
}
示例#4
0
func (s *Shader) getError() error {
	var logLength gl.Int
	gl.GetShaderiv(s.id, gl.INFO_LOG_LENGTH, &logLength)
	log := gl.GLStringAlloc(gl.Sizei(logLength))
	defer gl.GLStringFree(log)
	gl.GetShaderInfoLog(s.id, gl.Sizei(logLength), nil, log)
	err := gl.GoString(log)
	return errors.New(err)
}