Example #1
0
func (c *Context) GetUniformLocation(p Program, location string) UniformLocation {
	u := UniformLocation(gl.GetUniformLocation(uint32(p), gl.Str(location+"\x00")))
	if u == -1 {
		panic("invalid uniform location: " + location)
	}
	return u
}
Example #2
0
File: gg.go Project: dmac/gg
func (*backend) GetUniformLocation(p *gg.Program, name string) (*gg.Uniform, error) {
	u := gl.GetUniformLocation(p.Value.(uint32), gl.Str(name+"\x00"))
	if u < 0 {
		return nil, fmt.Errorf("gg: no uniform named " + name)
	}
	return &gg.Uniform{Value: u}, nil
}
Example #3
0
func (c *Context) getUniformLocationImpl(p Program, location string) uniformLocation {
	uniform := uniformLocation(gl.GetUniformLocation(uint32(p), gl.Str(location+"\x00")))
	if uniform == -1 {
		panic("opengl: invalid uniform location: " + location)
	}
	return uniform
}
Example #4
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
}
Example #5
0
func (s *Shader) addUniform(uniformName string) error {
	uniformLocation := gl.GetUniformLocation(s.program, gl.Str(uniformName+"\000"))

	if uniformLocation == -1 {
		return fmt.Errorf("could not find uniform: %s", uniformName)
	}

	s.uniforms[uniformName] = uniformLocation
	return nil
}
Example #6
0
func (s *Shader) addUniform(uniformName string) error {
	csource, free := gl.Strs(uniformName + "\000")
	defer free()
	uniformLocation := gl.GetUniformLocation(s.program, *csource)

	if uniformLocation == -1 {
		return fmt.Errorf("could not find uniform: %s", uniformName)
	}

	s.uniforms[uniformName] = uniformLocation
	return nil
}
Example #7
0
func uniforms(id uint32) map[string]Uniform {
	var maxlength int32
	gl.GetProgramiv(id, gl.ACTIVE_UNIFORM_MAX_LENGTH, &maxlength)
	var numuniforms int32
	gl.GetProgramiv(id, gl.ACTIVE_UNIFORMS, &numuniforms)
	buf := make([]byte, maxlength)
	m := make(map[string]Uniform)
	for index := uint32(0); index < uint32(numuniforms); index++ {
		name, dt, siz := uniform(id, index, buf)
		loc := gl.GetUniformLocation(id, &buf[0])
		if loc == -1 {
			panic(fmt.Errorf("Expected location for indexed uniform '%s'", name))
		}
		m[name] = Uniform{
			name:     name,
			location: loc,
			typ:      dt,
			siz:      siz,
		}
	}
	return m
}
Example #8
0
// GetUniformLocation returns the location of a uniform variable.
//
// http://www.khronos.org/opengles/sdk/docs/man3/html/glGetUniformLocation.xhtml
func GetUniformLocation(p Program, name string) Uniform {
	return Uniform{Value: gl.GetUniformLocation(p.Value, gl.Str(name+"\x00"))}
}
Example #9
0
func (c *Context) GetUniformLocation(program *Program, name string) *UniformLocation {
	return &UniformLocation{gl.GetUniformLocation(program.uint32, gl.Str(name+"\x00"))}
}
Example #10
0
func (c *Context) GetUniformLocation(program *Program, name string) *UniformLocation {
	strptr, free := gl.Strs(name + "\x00")
	defer free()
	return &UniformLocation{gl.GetUniformLocation(program.uint32, *strptr)}
}