Esempio n. 1
0
func (s *Shader) getProgramInfoLog(context string) error {
	var logLength int32
	gl.GetProgramiv(s.program, gl.INFO_LOG_LENGTH, &logLength)

	log := strings.Repeat("\x00", int(logLength+1))
	gl.GetProgramInfoLog(s.program, logLength, nil, gl.Str(log))

	return fmt.Errorf("%s: %s", context, log)
}
Esempio n. 2
0
func (s *Shader) getProgramInfoLog(context string) error {
	var logLength int32
	gl.GetProgramiv(s.program, gl.INFO_LOG_LENGTH, &logLength)

	cLog, free := gl.Strs(strings.Repeat("\x00", int(logLength+1)))
	defer free()
	gl.GetProgramInfoLog(s.program, logLength, nil, *cLog)

	return fmt.Errorf("%s: %s", context, cLog)
}
Esempio n. 3
0
// GetProgramInfoLog returns the information log for a program.
//
// http://www.khronos.org/opengles/sdk/docs/man3/html/glGetProgramInfoLog.xhtml
func GetProgramInfoLog(p Program) string {
	var logLength int32
	gl.GetProgramiv(p.Value, gl.INFO_LOG_LENGTH, &logLength)
	if logLength == 0 {
		return ""
	}

	logBuffer := make([]uint8, logLength)
	gl.GetProgramInfoLog(p.Value, logLength, nil, &logBuffer[0])
	return gl.GoStr(&logBuffer[0])
}
Esempio n. 4
0
File: gg.go Progetto: dmac/gg
func (*backend) LinkProgram(p *gg.Program) error {
	pv := p.Value.(uint32)
	gl.LinkProgram(pv)
	var status int32
	gl.GetProgramiv(pv, gl.LINK_STATUS, &status)
	if status == gl.TRUE {
		return nil
	}
	var logLength int32
	gl.GetProgramiv(pv, gl.INFO_LOG_LENGTH, &logLength)
	log := strings.Repeat("\x00", int(logLength+1))
	gl.GetProgramInfoLog(pv, logLength, nil, gl.Str(log))
	return fmt.Errorf("link program: %s", log)
}
Esempio n. 5
0
// PrintLog prints the error log for an object
func PrintLog(object uint32) {
	var logLength int32
	if gl.IsShader(object) {
		gl.GetShaderiv(object, gl.INFO_LOG_LENGTH, &logLength)
	} else if gl.IsProgram(object) {
		gl.GetProgramiv(object, gl.INFO_LOG_LENGTH, &logLength)
	} else {
		log.Fatal("PrintLog: not a shader or program")
	}

	infoLog := strings.Repeat("\x00", int(logLength+1))
	if gl.IsShader(object) {
		gl.GetShaderInfoLog(object, logLength, nil, gl.Str(infoLog))
	} else if gl.IsProgram(object) {
		gl.GetProgramInfoLog(object, logLength, nil, gl.Str(infoLog))
	}
	log.Fatal(infoLog)
}
Esempio n. 6
0
func NewProgram(vertexSource, fragmentSource string) (*Program, error) {
	vertexId, err := newShader(vertexSource, gl.VERTEX_SHADER)
	if err != nil {
		return nil, err
	}
	fragmentId, err := newShader(fragmentSource, gl.FRAGMENT_SHADER)
	if err != nil {
		gl.DeleteShader(vertexId)
		return nil, err
	}
	id := gl.CreateProgram()
	if id == 0 {
		gl.DeleteShader(vertexId)
		gl.DeleteShader(fragmentId)
		return nil, fmt.Errorf("Unable to allocate program")
	}
	gl.AttachShader(id, vertexId)
	gl.AttachShader(id, fragmentId)
	gl.LinkProgram(id)
	var result int32
	gl.GetProgramiv(id, gl.LINK_STATUS, &result)
	if result == int32(gl.FALSE) {
		var loglength int32
		gl.GetProgramiv(id, gl.INFO_LOG_LENGTH, &loglength)
		log := make([]byte, loglength)
		var length int32
		gl.GetProgramInfoLog(id, loglength, &length, &log[0])
		gl.DeleteShader(vertexId)
		gl.DeleteShader(fragmentId)
		gl.DeleteProgram(id)
		return nil, fmt.Errorf("Unable to link program: %s", log[:length])
	}

	return &Program{
		id:       id,
		vertId:   vertexId,
		fragId:   fragmentId,
		uniforms: uniforms(id),
	}, nil
}