opengl: Bug fix: Use attrib/uniform cache

This commit is contained in:
Hajime Hoshi 2016-02-24 01:34:24 +09:00
parent 2d78d14e83
commit 888c7dadfd
2 changed files with 7 additions and 5 deletions

View File

@ -254,11 +254,11 @@ func (c *Context) GetUniformLocation(p Program, location string) UniformLocation
} }
func (c *Context) UniformInt(p Program, location string, v int) { func (c *Context) UniformInt(p Program, location string, v int) {
gl.Uniform1i(gl.GetUniformLocation(mgl.Program(p), location), v) gl.Uniform1i(mgl.Uniform(GetUniformLocation(c, p, location)), v)
} }
func (c *Context) UniformFloats(p Program, location string, v []float32) { func (c *Context) UniformFloats(p Program, location string, v []float32) {
l := gl.GetUniformLocation(mgl.Program(p), location) l := mgl.Uniform(GetUniformLocation(c, p, location))
switch len(v) { switch len(v) {
case 4: case 4:
gl.Uniform4fv(l, v) gl.Uniform4fv(l, v)
@ -278,17 +278,17 @@ func (c *Context) GetAttribLocation(p Program, location string) AttribLocation {
} }
func (c *Context) VertexAttribPointer(p Program, location string, normalize bool, stride int, size int, v int) { func (c *Context) VertexAttribPointer(p Program, location string, normalize bool, stride int, size int, v int) {
l := c.GetAttribLocation(p, location) l := GetAttribLocation(c, p, location)
gl.VertexAttribPointer(mgl.Attrib(l), size, mgl.SHORT, normalize, stride, v) gl.VertexAttribPointer(mgl.Attrib(l), size, mgl.SHORT, normalize, stride, v)
} }
func (c *Context) EnableVertexAttribArray(p Program, location string) { func (c *Context) EnableVertexAttribArray(p Program, location string) {
l := c.GetAttribLocation(p, location) l := GetAttribLocation(c, p, location)
gl.EnableVertexAttribArray(mgl.Attrib(l)) gl.EnableVertexAttribArray(mgl.Attrib(l))
} }
func (c *Context) DisableVertexAttribArray(p Program, location string) { func (c *Context) DisableVertexAttribArray(p Program, location string) {
l := c.GetAttribLocation(p, location) l := GetAttribLocation(c, p, location)
gl.DisableVertexAttribArray(mgl.Attrib(l)) gl.DisableVertexAttribArray(mgl.Attrib(l))
} }

View File

@ -23,6 +23,8 @@ type UniformLocationGetter interface {
GetUniformLocation(p Program, location string) UniformLocation GetUniformLocation(p Program, location string) UniformLocation
} }
// TODO: Rename these functions not to be confusing
func GetUniformLocation(g UniformLocationGetter, p Program, location string) UniformLocation { func GetUniformLocation(g UniformLocationGetter, p Program, location string) UniformLocation {
id := GetProgramID(p) id := GetProgramID(p)
if _, ok := uniformLocationCache[id]; !ok { if _, ok := uniformLocationCache[id]; !ok {