示例#1
0
func initResources() (uint32, int32) {
	vs := CreateShader("triangle.v.glsl", gl.VERTEX_SHADER)
	fs := CreateShader("triangle.f.glsl", gl.FRAGMENT_SHADER)

	var linkOk int32
	program := gl.CreateProgram()
	gl.AttachShader(program, vs)
	gl.AttachShader(program, fs)
	gl.LinkProgram(program)
	gl.GetProgramiv(program, gl.LINK_STATUS, &linkOk)
	if linkOk == 0 {
		log.Fatal("gl.LinkProgram")
	}

	gl.GenBuffers(1, &vboTriangle)
	gl.BindBuffer(gl.ARRAY_BUFFER, vboTriangle)
	gl.BufferData(gl.ARRAY_BUFFER, 4*len(triangleVertices), gl.Ptr(triangleVertices), gl.STATIC_DRAW)

	attribName := "coord2d\x00"
	attribCoord2d := gl.GetAttribLocation(program, gl.Str(attribName))
	if attribCoord2d == -1 {
		log.Fatal("failed to bind attribute")
	}
	return program, attribCoord2d
}
示例#2
0
func initResources() uint32 {
	vs := CreateShader("triangle.v.glsl", gl.VERTEX_SHADER)
	fs := CreateShader("triangle.f.glsl", gl.FRAGMENT_SHADER)

	var linkOk int32
	program := gl.CreateProgram()
	gl.AttachShader(program, vs)
	gl.AttachShader(program, fs)
	gl.LinkProgram(program)
	gl.GetProgramiv(program, gl.LINK_STATUS, &linkOk)
	if linkOk == 0 {
		log.Fatal("gl.LinkProgram")
	}

	gl.GenBuffers(1, &vboTriangle)
	gl.BindBuffer(gl.ARRAY_BUFFER, vboTriangle)
	gl.BufferData(gl.ARRAY_BUFFER, floatSize*len(triangleAttributes), gl.Ptr(triangleAttributes), gl.STATIC_DRAW)

	attributeCoord2d = gl.GetAttribLocation(program, gl.Str("coord2d\x00"))
	if attributeCoord2d == -1 {
		log.Fatal("failed to bind attribute")
	}

	attributeVColor = gl.GetAttribLocation(program, gl.Str("v_color\x00"))
	if attributeVColor == -1 {
		log.Fatal("could not bind attribute v_color")
	}

	uniformFade = gl.GetUniformLocation(program, gl.Str("fade\x00"))
	if uniformFade == -1 {
		log.Fatal("could not bind uniform fade")
	}

	return program
}
示例#3
0
文件: gg.go 项目: dmac/gg
func (*backend) LinkProgram(p *gg.Program) error {
	pv := p.Value.(uint32)
	gl.LinkProgram(pv)
	var status int32
	gl.GetProgramiv(pv, gl.LINK_STATUS, &status)
	if status == gl.TRUE {
		return nil
	}
	var logLength int32
	gl.GetProgramiv(pv, gl.INFO_LOG_LENGTH, &logLength)
	log := strings.Repeat("\x00", int(logLength+1))
	gl.GetProgramInfoLog(pv, logLength, nil, gl.Str(log))
	return fmt.Errorf("link program: %s", log)
}
示例#4
0
func (s *Shader) compile() error {
	gl.LinkProgram(s.program)
	var result int32
	gl.GetProgramiv(s.program, gl.LINK_STATUS, &result)
	if result == 0 {
		return s.getProgramInfoLog("shader compilation error")
	}
	gl.ValidateProgram(s.program)
	gl.GetProgramiv(s.program, gl.VALIDATE_STATUS, &result)
	if result == 0 {
		return s.getProgramInfoLog("shader compilation error: %s")
	}

	return nil
}
示例#5
0
func (c *Context) NewProgram(shaders []Shader) (Program, error) {
	p := gl.CreateProgram()
	if p == 0 {
		return 0, errors.New("glCreateProgram failed")
	}

	for _, shader := range shaders {
		gl.AttachShader(p, uint32(shader))
	}
	gl.LinkProgram(p)
	var v int32
	gl.GetProgramiv(p, gl.LINK_STATUS, &v)
	if v == gl.FALSE {
		return 0, errors.New("program error")
	}
	return Program(p), nil
}
示例#6
0
func createProgram(vertShaderSrc string, fragShaderSrc string) uint32 {
	vertShader := loadShader(gl.VERTEX_SHADER, vertShaderSrc)
	fragShader := loadShader(gl.FRAGMENT_SHADER, fragShaderSrc)

	prog := gl.CreateProgram()

	gl.AttachShader(prog, vertShader)
	gl.AttachShader(prog, fragShader)
	gl.LinkProgram(prog)

	var status int32
	gl.GetProgramiv(prog, gl.LINK_STATUS, &status)
	if status != gl.TRUE {
		//log := gl.GetInfoLogARB(prog)
		panic(fmt.Errorf("Failed to link program: , "))
	}

	return prog
}
示例#7
0
func initResources() (uint32, int32) {
	vSrc0 := fixupSrc(vShaderSrc)
	vSrc := gl.Str(vSrc0)
	vs := gl.CreateShader(gl.VERTEX_SHADER)
	gl.ShaderSource(vs, 1, &vSrc, nil)
	gl.CompileShader(vs)
	var vok int32
	gl.GetShaderiv(vs, gl.COMPILE_STATUS, &vok)
	if vok == 0 {
		log.Fatal("error in vertex shader")

	}

	fSrc := gl.Str(fShaderSrc)
	fs := gl.CreateShader(gl.FRAGMENT_SHADER)
	gl.ShaderSource(fs, 1, &fSrc, nil)
	gl.CompileShader(fs)
	var fok int32
	gl.GetShaderiv(vs, gl.COMPILE_STATUS, &fok)
	if fok == 0 {
		log.Fatal("error in fragment shader")

	}

	var linkOk int32
	program := gl.CreateProgram()
	gl.AttachShader(program, vs)
	gl.AttachShader(program, fs)
	gl.LinkProgram(program)
	gl.GetProgramiv(program, gl.LINK_STATUS, &linkOk)
	if linkOk == 0 {
		log.Fatal("gl.LinkProgram")
	}

	attribName := fixupSrc("coord2d")
	attribCoord2d := gl.GetAttribLocation(program, gl.Str(attribName))
	if attribCoord2d == -1 {
		log.Fatal("failed to bind attribute")
	}
	return program, attribCoord2d
}
示例#8
0
文件: program.go 项目: PieterD/crap
func NewProgram(vertexSource, fragmentSource string) (*Program, error) {
	vertexId, err := newShader(vertexSource, gl.VERTEX_SHADER)
	if err != nil {
		return nil, err
	}
	fragmentId, err := newShader(fragmentSource, gl.FRAGMENT_SHADER)
	if err != nil {
		gl.DeleteShader(vertexId)
		return nil, err
	}
	id := gl.CreateProgram()
	if id == 0 {
		gl.DeleteShader(vertexId)
		gl.DeleteShader(fragmentId)
		return nil, fmt.Errorf("Unable to allocate program")
	}
	gl.AttachShader(id, vertexId)
	gl.AttachShader(id, fragmentId)
	gl.LinkProgram(id)
	var result int32
	gl.GetProgramiv(id, gl.LINK_STATUS, &result)
	if result == int32(gl.FALSE) {
		var loglength int32
		gl.GetProgramiv(id, gl.INFO_LOG_LENGTH, &loglength)
		log := make([]byte, loglength)
		var length int32
		gl.GetProgramInfoLog(id, loglength, &length, &log[0])
		gl.DeleteShader(vertexId)
		gl.DeleteShader(fragmentId)
		gl.DeleteProgram(id)
		return nil, fmt.Errorf("Unable to link program: %s", log[:length])
	}

	return &Program{
		id:       id,
		vertId:   vertexId,
		fragId:   fragmentId,
		uniforms: uniforms(id),
	}, nil
}
示例#9
0
func (c *Context) NewProgram(shaders []Shader) (Program, error) {
	var program Program
	if err := c.runOnContextThread(func() error {
		p := gl.CreateProgram()
		if p == 0 {
			return errors.New("opengl: glCreateProgram failed")
		}

		for _, shader := range shaders {
			gl.AttachShader(p, uint32(shader))
		}
		gl.LinkProgram(p)
		var v int32
		gl.GetProgramiv(p, gl.LINK_STATUS, &v)
		if v == gl.FALSE {
			return errors.New("opengl: program error")
		}
		program = Program(p)
		return nil
	}); err != nil {
		return 0, err
	}
	return program, nil
}
示例#10
0
文件: gl_opengl.go 项目: tanema/amore
// LinkProgram links the specified program.
//
// http://www.khronos.org/opengles/sdk/docs/man3/html/glLinkProgram.xhtml
func LinkProgram(p Program) {
	gl.LinkProgram(p.Value)
}
示例#11
0
文件: gl_gl2.go 项目: EngoEngine/gl
func (c *Context) LinkProgram(program *Program) {
	gl.LinkProgram(program.uint32)
}