コード例 #1
0
ファイル: tools.go プロジェクト: YagoCarballo/Go-OpenGL-Lab-3
//
// Build Shader
// Creates and compiles a shader
//
// @param source (string) the path to the shader file
// @param shaderType (uint32) the shader type
//
// @return shader (uint32) the pointer to the shader
// @return error (error) the error (if any)
//
func BuildShader(source string, shaderType uint32) (uint32, error) {
	// Creates the Shader Object
	shader := gl.CreateShader(shaderType)

	// Reads the File
	fileContents := FileToString(source)

	// Converts the file contents into a valid C String
	csource := gl.Str(fileContents)

	// Loads the Shader's Source
	gl.ShaderSource(shader, 1, &csource, nil)

	// Compiles the Shader
	gl.CompileShader(shader)

	// Gets any errors that happened when building the Shader
	var status int32
	gl.GetShaderiv(shader, gl.COMPILE_STATUS, &status)

	// If there was an error, parse the C Error into a Go Error and return it
	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)
	}

	// Returns the shader if everything is OK
	return shader, nil
}
コード例 #2
0
ファイル: gl.go プロジェクト: gmacd/rt
func compileShader(source string, shaderType uint32) (uint32, error) {
	shader := gl.CreateShader(shaderType)

	csource := gl.Str(source)
	gl.ShaderSource(shader, 1, &csource, nil)
	if e := gl.GetError(); e != gl.NO_ERROR {
		panic(fmt.Sprintf("before resizing: %d", e))
	}
	gl.CompileShader(shader)

	if e := gl.GetError(); e != gl.NO_ERROR {
		panic(fmt.Sprintf("before resizing: %d", e))
	}
	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
}
コード例 #3
0
ファイル: hello.go プロジェクト: rdterner/gl
func makeShader(shaderType uint32, source string) uint32 {
	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))

		x(fmt.Errorf("failed to compile %v: %v", source, log))
	}

	return shader
}