Avoid using struct key

This commit is contained in:
Hajime Hoshi 2015-01-03 16:16:43 +09:00
parent 3ad8d8ea2c
commit 52e610845b
2 changed files with 14 additions and 22 deletions

View File

@ -198,22 +198,20 @@ func (c *Context) UseProgram(p Program) {
func (c *Context) UniformInt(p Program, location string, v int) {
gl := c.gl
key := locationCacheKey{p, location}
l, ok := uniformLocationCache[key]
l, ok := uniformLocationCache[location]
if !ok {
l = gl.GetUniformLocation(p, location)
uniformLocationCache[key] = l
uniformLocationCache[location] = l
}
gl.Uniform1i(l, v)
}
func (c *Context) UniformFloats(p Program, location string, v []float32) {
gl := c.gl
key := locationCacheKey{p, location}
l, ok := uniformLocationCache[key]
l, ok := uniformLocationCache[location]
if !ok {
l = gl.GetUniformLocation(p, location)
uniformLocationCache[key] = l
uniformLocationCache[location] = l
}
switch len(v) {
case 4:
@ -227,33 +225,30 @@ func (c *Context) UniformFloats(p Program, location string, v []float32) {
func (c *Context) VertexAttribPointer(p Program, location string, stride int, v uintptr) {
gl := c.gl
key := locationCacheKey{p, location}
l, ok := attribLocationCache[key]
l, ok := attribLocationCache[location]
if !ok {
l = AttribLocation(gl.GetAttribLocation(p, location))
attribLocationCache[key] = l
attribLocationCache[location] = l
}
gl.VertexAttribPointer(int(l), 2, gl.FLOAT, false, stride, int(v))
}
func (c *Context) EnableVertexAttribArray(p Program, location string) {
gl := c.gl
key := locationCacheKey{p, location}
l, ok := attribLocationCache[key]
l, ok := attribLocationCache[location]
if !ok {
l = AttribLocation(gl.GetAttribLocation(p, location))
attribLocationCache[key] = l
attribLocationCache[location] = l
}
gl.EnableVertexAttribArray(int(l))
}
func (c *Context) DisableVertexAttribArray(p Program, location string) {
gl := c.gl
key := locationCacheKey{p, location}
l, ok := attribLocationCache[key]
l, ok := attribLocationCache[location]
if !ok {
l = AttribLocation(gl.GetAttribLocation(p, location))
attribLocationCache[key] = l
attribLocationCache[location] = l
}
gl.DisableVertexAttribArray(int(l))
}

View File

@ -14,10 +14,7 @@
package opengl
type locationCacheKey struct {
program Program
name string
}
var uniformLocationCache = map[locationCacheKey]UniformLocation{}
var attribLocationCache = map[locationCacheKey]AttribLocation{}
// Note: This cache is created only for one program.
// If we use two or more programs, the key of the map should be changed.
var uniformLocationCache = map[string]UniformLocation{}
var attribLocationCache = map[string]AttribLocation{}