From 52e610845b0241c527e5c33de17dde4142d013e5 Mon Sep 17 00:00:00 2001 From: Hajime Hoshi Date: Sat, 3 Jan 2015 16:16:43 +0900 Subject: [PATCH] Avoid using struct key --- internal/opengl/context_js.go | 25 ++++++++++--------------- internal/opengl/locationcache.go | 11 ++++------- 2 files changed, 14 insertions(+), 22 deletions(-) diff --git a/internal/opengl/context_js.go b/internal/opengl/context_js.go index 38c963f98..56dd131b1 100644 --- a/internal/opengl/context_js.go +++ b/internal/opengl/context_js.go @@ -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)) } diff --git a/internal/opengl/locationcache.go b/internal/opengl/locationcache.go index c3dfee9a8..a01e7d9ca 100644 --- a/internal/opengl/locationcache.go +++ b/internal/opengl/locationcache.go @@ -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{}