Exemplo n.º 1
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
}
Exemplo n.º 2
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()
}
func compileShader(shaderCode string, shaderType uint32) uint32 {
	shader := gl.CreateShader(shaderType)
	shaderChars := gl.Str(shaderCode + "\x00")
	gl.ShaderSource(shader, 1, &shaderChars, nil)
	gl.CompileShader(shader)
	checkShaderCompileErrors(shader)
	return shader
}
func compileShaders() []uint32 {

	// create the vertex shader
	vertexShader := gl.CreateShader(gl.VERTEX_SHADER)
	shaderSourceChars := gl.Str(vertexShaderSource + "\x00")
	gl.ShaderSource(vertexShader, 1, &shaderSourceChars, nil)
	gl.CompileShader(vertexShader)
	checkShaderCompileErrors(vertexShader)

	// create the fragment shader
	fragmentShader := gl.CreateShader(gl.FRAGMENT_SHADER)
	shaderSourceChars = gl.Str(fragmentShaderSource + "\x00")
	gl.ShaderSource(fragmentShader, 1, &shaderSourceChars, nil)
	gl.CompileShader(fragmentShader)
	checkShaderCompileErrors(fragmentShader)

	return []uint32{vertexShader, fragmentShader}
}
Exemplo n.º 5
0
func createProgram() uint32 {
	vs := gl.CreateShader(gl.VERTEX_SHADER)
	cvertexShader := gl.Str(vertexShader)
	gl.ShaderSource(vs, 1, &cvertexShader, nil)
	gl.CompileShader(vs)

	fs := gl.CreateShader(gl.FRAGMENT_SHADER)
	cfragmentShader := gl.Str(fragmentShader)
	gl.ShaderSource(fs, 1, &cfragmentShader, nil)
	gl.CompileShader(fs)

	shaderProgram := gl.CreateProgram()
	gl.AttachShader(shaderProgram, fs)
	gl.AttachShader(shaderProgram, vs)

	gl.LinkProgram(shaderProgram)

	return shaderProgram
}
Exemplo n.º 6
0
func (me *Core) AddProgram(vertFile, fragFile string) int {
	vertexShader := gl.Str(readWholeFile(vertFile) + "\x00")
	fragmentShader := gl.Str(readWholeFile(fragFile) + "\x00")

	n := me.nbProg
	vs := gl.CreateShader(gl.VERTEX_SHADER)
	gl.ShaderSource(vs, 1, &vertexShader, nil)
	gl.CompileShader(vs)
	fs := gl.CreateShader(gl.FRAGMENT_SHADER)
	gl.ShaderSource(fs, 1, &fragmentShader, nil)
	gl.CompileShader(fs)

	me.Progs[n] = gl.CreateProgram()
	gl.AttachShader(me.Progs[n], fs)
	gl.AttachShader(me.Progs[n], vs)
	gl.LinkProgram(me.Progs[n])
	me.nbProg++
	return n
}
Exemplo n.º 7
0
func NewShader(src string, sType uint32) (*Shader, error) {

	handle := gl.CreateShader(sType)
	glSrc := gl.Str(src + "\x00")
	gl.ShaderSource(handle, 1, &glSrc, nil)
	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.º 8
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
}