// drawScene renders the scene consisting of one VAO. func (tb *tbtag) drawScene() { gl.Clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT) gl.UseProgram(tb.shaders) gl.Uniform1i(tb.sampler, 0) gl.ActiveTexture(gl.TEXTURE0 + 0) gl.BindTexture(gl.TEXTURE_2D, tb.texture.Tid) gl.BindVertexArray(tb.vao) tb.mvp32 = renderMatrix(tb.ortho, tb.mvp32) gl.UniformMatrix4fv(tb.mvpref, 1, false, tb.mvp32.Pointer()) gl.DrawElements(gl.TRIANGLES, int32(len(tb.faces)), gl.UNSIGNED_BYTE, gl.Pointer(nil)) // cleanup gl.ActiveTexture(0) gl.UseProgram(0) gl.BindVertexArray(0) }
// bindUniforms wraps all the various glUniform calls as a single method. // It expects the variable parameter list to match the given type. func (gc *opengl) bindUniforms(uniform int32, utype 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 vf1: count := udata[0].(int32) vptr := udata[1].(*float32) gl.Uniform1fv(uniform, count, vptr) case vf2: count := udata[0].(int32) vptr := udata[1].(*float32) gl.Uniform2fv(uniform, count, vptr) case vi1: count := udata[0].(int32) vptr := udata[1].(*int32) gl.Uniform1iv(uniform, count, vptr) case m3: mptr := udata[0].(*float32) gl.UniformMatrix3fv(uniform, 1, false, mptr) case m4: mptr := udata[0].(*float32) gl.UniformMatrix4fv(uniform, 1, false, mptr) } }