Example #1
0
func (p *Program) GetProgramInfoLog() string {
	var logSize int32 = 0
	gl.GetProgramiv(p.prog, gl.INFO_LOG_LENGTH, &logSize)
	var infoLog []uint8 = make([]uint8, logSize)
	gl.GetProgramInfoLog(p.prog, logSize, &logSize, &infoLog[0])
	return gl.GoStr(&infoLog[0])
}
Example #2
0
func newProgram(vertexShaderSource, fragmentShaderSource string) (uint32, error) {
	vertexShader, err := compileShader(vertexShaderSource, gl.VERTEX_SHADER)
	if err != nil {
		return 0, err
	}

	fragmentShader, err := compileShader(fragmentShaderSource, gl.FRAGMENT_SHADER)
	if err != nil {
		return 0, err
	}

	program := gl.CreateProgram()

	gl.AttachShader(program, vertexShader)
	gl.AttachShader(program, fragmentShader)
	gl.LinkProgram(program)

	var status int32
	gl.GetProgramiv(program, gl.LINK_STATUS, &status)
	if status == gl.FALSE {
		var logLength int32
		gl.GetProgramiv(program, gl.INFO_LOG_LENGTH, &logLength)

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

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

	gl.DeleteShader(vertexShader)
	gl.DeleteShader(fragmentShader)

	return program, nil
}
Example #3
0
func LoadShaders(shaders []ShaderInfo) (uint32, error) {
	program := gl.CreateProgram()

	for _, shaderInfo := range shaders {
		shader, err := shaderInfo.CompileShader()
		if err != nil {
			return 0, err
		}
		gl.AttachShader(program, shader)
		gl.DeleteShader(shader)
	}

	gl.LinkProgram(program)

	var status int32
	gl.GetProgramiv(program, gl.LINK_STATUS, &status)
	if status == gl.FALSE {
		var logLength int32
		gl.GetProgramiv(program, gl.INFO_LOG_LENGTH, &logLength)

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

		return 0, fmt.Errorf("Failed to link program: %v", log)
	}

	return program, nil
}
Example #4
0
func newProgram(shaders ...uint32) (uint32, error) {
	program := gl.CreateProgram()

	for _, shader := range shaders {
		gl.AttachShader(program, shader)
	}
	gl.LinkProgram(program)

	var status int32
	gl.GetProgramiv(program, gl.LINK_STATUS, &status)
	if status == gl.FALSE {
		var logLength int32
		gl.GetProgramiv(program, gl.INFO_LOG_LENGTH, &logLength)

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

		return 0, errors.New(fmt.Sprintf("failed to link program: %v", log))
	}

	for _, shader := range shaders {
		gl.DeleteShader(shader)
	}

	return program, nil
}
Example #5
0
func NewProgram(shaderSource map[string]string) (*GLSLProgram, error) {
	var hasVertexShader bool
	var hasFragmentShader bool

	vertexShaderSource, ok := shaderSource["vertex"]
	var vertexShader uint32
	if ok {

		vertexShader, err := compileShader(vertexShaderSource, gl.VERTEX_SHADER)
		if err != nil {
			return nil, err
		}
		hasVertexShader = true
	}

	fragmentShaderSource, ok := shaderSource["fragment"]
	var fragmentShader uint32
	if ok {

		fragmentShader, err := compileShader(fragmentShaderSource, gl.FRAGMENT_SHADER)
		if err != nil {
			return nil, err
		}
		hasFragmentShader = true
	}

	program := gl.CreateProgram()

	if !(hasVertexShader && hasFragmentShader) {
		return nil, fmt.Errorf("Need vertex shader: %v, and fragment shader: %v", hasVertexShader, hasFragmentShader)
	}

	gl.AttachShader(program, vertexShader)
	gl.AttachShader(program, fragmentShader)
	gl.LinkProgram(program)

	var status int32
	gl.GetProgramiv(program, gl.LINK_STATUS, &status)
	if status == gl.FALSE {
		var logLength int32
		gl.GetProgramiv(program, gl.INFO_LOG_LENGTH, &logLength)

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

		return nil, fmt.Errorf("Failed to link program(%v): %v", program, log)
	}

	gl.DeleteShader(vertexShader)
	gl.DeleteShader(fragmentShader)
	p := &GLSLProgram{program, vertexShaderSource, fragmentShaderSource, true}
	return p, nil
}
Example #6
0
func newProgram(vertexShaderFilename, fragmentShaderFilename string) (uint32, error) {
	program := gl.CreateProgram()

	//vertexShaderSource, err := shaders.Asset(vertexShaderFilename)
	//if err != nil {
	//	return 0, err
	//}

	vertexShader, err := shaders.Compile(vertexShaderSource, gl.VERTEX_SHADER)
	if err != nil {
		return 0, err
	}

	//fragmentShaderSource, err := shaders.Asset(fragmentShaderFilename)
	//if err != nil {
	//	return 0, err
	//}
	fragmentShader, err := shaders.Compile(fragmentShaderSource, gl.FRAGMENT_SHADER)
	if err != nil {
		return 0, err
	}

	gl.AttachShader(program, vertexShader)
	gl.AttachShader(program, fragmentShader)
	gl.LinkProgram(program)

	var status int32
	gl.GetProgramiv(program, gl.LINK_STATUS, &status)
	if status == gl.FALSE {
		var logLength int32
		gl.GetProgramiv(program, gl.INFO_LOG_LENGTH, &logLength)

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

		return 0, errors.New(fmt.Sprintf("failed to link program: %v", log))
	}

	gl.DeleteShader(vertexShader)
	gl.DeleteShader(fragmentShader)

	return program, nil
}