From 25fb0a9e312701736cfe9ced263c9491d9ac6a8e Mon Sep 17 00:00:00 2001 From: Hajime Hoshi Date: Wed, 31 Dec 2014 20:07:27 +0900 Subject: [PATCH] Unify Uniform* methods --- internal/graphics/internal/shader/program.go | 10 +++++----- internal/opengl/context.go | 21 ++++++++++---------- 2 files changed, 15 insertions(+), 16 deletions(-) diff --git a/internal/graphics/internal/shader/program.go b/internal/graphics/internal/shader/program.go index f791d9b0d..cd394fa0a 100644 --- a/internal/graphics/internal/shader/program.go +++ b/internal/graphics/internal/shader/program.go @@ -74,7 +74,7 @@ func useProgramColorMatrix(c *opengl.Context, projectionMatrix [16]float32, geo // TODO: Check the performance. program := programColorMatrix - c.UniformMatrix4fv(program, "projection_matrix", projectionMatrix) + c.Uniform(program, "projection_matrix", projectionMatrix) ma := float32(geo.Element(0, 0)) mb := float32(geo.Element(0, 1)) @@ -88,8 +88,8 @@ func useProgramColorMatrix(c *opengl.Context, projectionMatrix [16]float32, geo 0, 0, 1, 0, tx, ty, 0, 1, } - c.UniformMatrix4fv(program, "modelview_matrix", glModelviewMatrix) - c.Uniform1i(program, "texture", 0) + c.Uniform(program, "modelview_matrix", glModelviewMatrix) + c.Uniform(program, "texture", 0) e := [4][5]float32{} 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][3], e[1][3], e[2][3], e[3][3], } - c.UniformMatrix4fv(program, "color_matrix", glColorMatrix) + c.Uniform(program, "color_matrix", glColorMatrix) glColorMatrixTranslation := [...]float32{ 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 } diff --git a/internal/opengl/context.go b/internal/opengl/context.go index 669404aa0..e10eadef3 100644 --- a/internal/opengl/context.go +++ b/internal/opengl/context.go @@ -178,17 +178,16 @@ func (c *Context) UseProgram(p Program) { gl.Program(p).Use() } -func (c *Context) Uniform1i(p Program, location string, v int) { - // TODO: Cache the location names. - gl.Program(p).GetUniformLocation(location).Uniform1i(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) Uniform(p Program, location string, v interface{}) { + l := gl.Program(p).GetUniformLocation(location) + 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) VertexAttribPointer(p Program, location string, stride int, v uintptr) {