Esempio n. 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
}
Esempio n. 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
}
Esempio n. 3
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
}
Esempio n. 4
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
}
Esempio n. 5
0
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
}
Esempio n. 6
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
}
Esempio n. 7
0
func (s *Shader) addProgram(text string, typ uint32) error {
	shader := gl.CreateShader(typ)
	if shader == 0 {
		return errors.New("could not find valid memory location when adding shader")
	}
	cStr := gl.Str(text + "\000")
	gl.ShaderSource(shader, 1, &cStr, nil)
	gl.CompileShader(shader)

	var result int32
	gl.GetShaderiv(shader, gl.COMPILE_STATUS, &result)
	if result == 0 {
		return s.getShaderInfoLog(shader, "get shader error")
	}

	gl.AttachShader(s.program, shader)
	return nil
}
Esempio n. 8
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
}
Esempio n. 9
0
// AttachShader attaches a shader to a program.
//
// http://www.khronos.org/opengles/sdk/docs/man3/html/glAttachShader.xhtml
func AttachShader(p Program, s Shader) {
	gl.AttachShader(p.Value, s.Value)
}
Esempio n. 10
0
func (c *Context) AttachShader(program *Program, shader *Shader) {
	gl.AttachShader(program.uint32, shader.uint32)
}
Esempio n. 11
0
File: gg.go Progetto: dmac/gg
func (*backend) AttachShader(p *gg.Program, s *gg.Shader) {
	gl.AttachShader(p.Value.(uint32), s.Value.(uint32))
}