Unify Uniform* methods

This commit is contained in:
Hajime Hoshi 2014-12-31 20:07:27 +09:00
parent e10bcb3dd8
commit 25fb0a9e31
2 changed files with 15 additions and 16 deletions

View File

@ -74,7 +74,7 @@ func useProgramColorMatrix(c *opengl.Context, projectionMatrix [16]float32, geo
// TODO: Check the performance. // TODO: Check the performance.
program := programColorMatrix program := programColorMatrix
c.UniformMatrix4fv(program, "projection_matrix", projectionMatrix) c.Uniform(program, "projection_matrix", projectionMatrix)
ma := float32(geo.Element(0, 0)) ma := float32(geo.Element(0, 0))
mb := float32(geo.Element(0, 1)) mb := float32(geo.Element(0, 1))
@ -88,8 +88,8 @@ func useProgramColorMatrix(c *opengl.Context, projectionMatrix [16]float32, geo
0, 0, 1, 0, 0, 0, 1, 0,
tx, ty, 0, 1, tx, ty, 0, 1,
} }
c.UniformMatrix4fv(program, "modelview_matrix", glModelviewMatrix) c.Uniform(program, "modelview_matrix", glModelviewMatrix)
c.Uniform1i(program, "texture", 0) c.Uniform(program, "texture", 0)
e := [4][5]float32{} e := [4][5]float32{}
for i := 0; i < 4; i++ { for i := 0; i < 4; i++ {
@ -104,11 +104,11 @@ func useProgramColorMatrix(c *opengl.Context, projectionMatrix [16]float32, geo
e[0][2], e[1][2], e[2][2], e[3][2], e[0][2], e[1][2], e[2][2], e[3][2],
e[0][3], e[1][3], e[2][3], e[3][3], e[0][3], e[1][3], e[2][3], e[3][3],
} }
c.UniformMatrix4fv(program, "color_matrix", glColorMatrix) c.Uniform(program, "color_matrix", glColorMatrix)
glColorMatrixTranslation := [...]float32{ glColorMatrixTranslation := [...]float32{
e[0][4], e[1][4], e[2][4], e[3][4], e[0][4], e[1][4], e[2][4], e[3][4],
} }
c.Uniform4fv(program, "color_matrix_translation", glColorMatrixTranslation) c.Uniform(program, "color_matrix_translation", glColorMatrixTranslation)
return program return program
} }

View File

@ -178,17 +178,16 @@ func (c *Context) UseProgram(p Program) {
gl.Program(p).Use() gl.Program(p).Use()
} }
func (c *Context) Uniform1i(p Program, location string, v int) { func (c *Context) Uniform(p Program, location string, v interface{}) {
// TODO: Cache the location names. l := gl.Program(p).GetUniformLocation(location)
gl.Program(p).GetUniformLocation(location).Uniform1i(v) switch v := v.(type) {
case int:
l.Uniform1i(v)
case [4]float32:
l.Uniform4fv(1, v[:])
case [16]float32:
l.UniformMatrix4fv(false, v)
} }
func (c *Context) Uniform4fv(p Program, location string, v [4]float32) {
gl.Program(p).GetUniformLocation(location).Uniform4fv(1, v[:])
}
func (c *Context) UniformMatrix4fv(p Program, location string, v [16]float32) {
gl.Program(p).GetUniformLocation(location).UniformMatrix4fv(false, v)
} }
func (c *Context) VertexAttribPointer(p Program, location string, stride int, v uintptr) { func (c *Context) VertexAttribPointer(p Program, location string, stride int, v uintptr) {