Пример #1
0
func GetShaderInfoLog(shader uint32) string {
	var logSize int32 = 0
	gl.GetShaderiv(shader, gl.INFO_LOG_LENGTH, &logSize)
	var infoLog []uint8 = make([]uint8, logSize)
	gl.GetShaderInfoLog(shader, logSize, &logSize, &infoLog[0])
	return gl.GoStr(&infoLog[0])
}
Пример #2
0
func (self *ShaderInfo) CompileShader() (uint32, error) {
	content, err := ioutil.ReadFile(self.Path)
	if err != nil {
		return 0, err
	}
	contentString := bytes.NewBuffer(content).String()
	glContentString := gl.Str(contentString + "\x00")

	shader := gl.CreateShader(self.ShaderType)
	gl.ShaderSource(shader, 1, &glContentString, nil)
	gl.CompileShader(shader)

	var status int32
	gl.GetShaderiv(shader, gl.COMPILE_STATUS, &status)
	if status == gl.FALSE {
		var logLength int32
		gl.GetShaderiv(shader, gl.INFO_LOG_LENGTH, &logLength)
		log := strings.Repeat("\x00", int(logLength+1))
		gl.GetShaderInfoLog(shader, logLength, nil, gl.Str(log))

		return 0, fmt.Errorf("failed to compile %v: %v", contentString, log)
	}

	return shader, nil
}
Пример #3
0
func compileShader(source string, shaderType uint32) (uint32, error) {
	shader := gl.CreateShader(shaderType)

	csource := gl.Str(source)
	gl.ShaderSource(shader, 1, &csource, nil)
	gl.CompileShader(shader)

	var status int32
	gl.GetShaderiv(shader, gl.COMPILE_STATUS, &status)
	if status == gl.FALSE {
		var logLength int32
		gl.GetShaderiv(shader, gl.INFO_LOG_LENGTH, &logLength)

		log := strings.Repeat("\x00", int(logLength+1))
		gl.GetShaderInfoLog(shader, logLength, nil, gl.Str(log))

		return 0, fmt.Errorf("failed to compile %v: %v", source, log)
	}
	return shader, nil
}