Exemplo n.º 1
0
func ShaderSource(shader uint32, src string) {
	//var srcArray []uint8 = StringToArray(src)
	//var ptr *uint8 = &srcArray[0]
	src += "\x00"
	csources, free := gl.Strs(src)
	gl.ShaderSource(shader, 1, csources, nil)
	free()
}
Exemplo n.º 2
0
func NewShader(src string, sType uint32) (*Shader, error) {

	handle := gl.CreateShader(sType)
	glSrcs, freeFn := gl.Strs(src + "\x00")
	gl.ShaderSource(handle, 1, glSrcs, nil)
	freeFn()
	gl.CompileShader(handle)
	err := getGlError(handle, gl.COMPILE_STATUS, gl.GetShaderiv, gl.GetShaderInfoLog,
		"SHADER::COMPILE_FAILURE::")
	if err != nil {
		return nil, err
	}
	return &Shader{handle: handle}, nil
}
Exemplo n.º 3
0
func compileShader(source string, shaderType uint32) (uint32, error) {
	shader := gl.CreateShader(shaderType)

	csources, free := gl.Strs(source)
	gl.ShaderSource(shader, 1, csources, nil)
	free()
	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
}
Exemplo n.º 4
0
// Converts a Go string to a uint8 array for use with OpenGL.
// Returns a pointer to the char array and a function to free the memory associated with the array
func GLString(str string) (**uint8, func()) {
	if !strings.HasSuffix(str, "\x00") {
		str += "\x00"
	}
	return gl.Strs(str)
}