Ejemplo n.º 1
0
// bindUniform links data to uniforms expected by shaders.
// It expects the variable parameter list types to match the uniform type.
func (gc *opengl) bindUniform(uniform int32, utype, cnt int, udata ...interface{}) {
	switch utype {
	case i1:
		i1 := udata[0].(int32)
		gl.Uniform1i(uniform, i1)
	case f1:
		f1 := udata[0].(float32)
		gl.Uniform1f(uniform, f1)
	case f2:
		f1 := udata[0].(float32)
		f2 := udata[1].(float32)
		gl.Uniform2f(uniform, f1, f2)
	case f3:
		f1 := udata[0].(float32)
		f2 := udata[1].(float32)
		f3 := udata[2].(float32)
		gl.Uniform3f(uniform, f1, f2, f3)
	case f4:
		f1 := udata[0].(float32)
		f2 := udata[1].(float32)
		f3 := udata[2].(float32)
		f4 := udata[3].(float32)
		gl.Uniform4f(uniform, f1, f2, f3, f4)
	case x3:
		mptr := udata[0].(*float32)
		gl.UniformMatrix3fv(uniform, int32(cnt), false, mptr)
	case x34:
		mptr := udata[0].(*float32)
		gl.UniformMatrix3x4fv(uniform, int32(cnt), false, mptr)
	case x4:
		mptr := udata[0].(*float32)
		gl.UniformMatrix4fv(uniform, int32(cnt), false, mptr)
	}
}
Ejemplo n.º 2
0
Archivo: sf.go Proyecto: skyview059/vu
// drawScene renders the shader-only scene.
func (sf *sftag) drawScene() {
	gl.Clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT)
	gl.UseProgram(sf.shaders)
	gl.BindVertexArray(sf.vao)
	timeSinceStart := time.Since(sf.sTime).Seconds()
	gl.Uniform1f(sf.gTime, float32(timeSinceStart))
	gl.Uniform2f(sf.sizes, 500, 500)
	gl.UniformMatrix4fv(sf.mvpref, 1, false, sf.mvp.Pointer())
	gl.DrawElements(gl.TRIANGLES, int32(len(sf.faces)), gl.UNSIGNED_BYTE, 0)

	// cleanup
	gl.UseProgram(0)
	gl.BindVertexArray(0)
}