Use attrib location cache

This commit is contained in:
Hajime Hoshi 2015-01-03 15:56:54 +09:00
parent 13a94d3446
commit 3ad8d8ea2c
2 changed files with 23 additions and 7 deletions

View File

@ -28,7 +28,7 @@ type Framebuffer js.Object
type Shader js.Object
type Program js.Object
type UniformLocation js.Object
type AttribLocation js.Object
type AttribLocation int
type context struct {
gl *webgl.Context
@ -227,20 +227,35 @@ 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
l := gl.GetAttribLocation(p, location)
gl.VertexAttribPointer(l, 2, gl.FLOAT, false, stride, int(v))
key := locationCacheKey{p, location}
l, ok := attribLocationCache[key]
if !ok {
l = AttribLocation(gl.GetAttribLocation(p, location))
attribLocationCache[key] = l
}
gl.VertexAttribPointer(int(l), 2, gl.FLOAT, false, stride, int(v))
}
func (c *Context) EnableVertexAttribArray(p Program, location string) {
gl := c.gl
l := gl.GetAttribLocation(p, location)
gl.EnableVertexAttribArray(l)
key := locationCacheKey{p, location}
l, ok := attribLocationCache[key]
if !ok {
l = AttribLocation(gl.GetAttribLocation(p, location))
attribLocationCache[key] = l
}
gl.EnableVertexAttribArray(int(l))
}
func (c *Context) DisableVertexAttribArray(p Program, location string) {
gl := c.gl
l := gl.GetAttribLocation(p, location)
gl.DisableVertexAttribArray(l)
key := locationCacheKey{p, location}
l, ok := attribLocationCache[key]
if !ok {
l = AttribLocation(gl.GetAttribLocation(p, location))
attribLocationCache[key] = l
}
gl.DisableVertexAttribArray(int(l))
}
func (c *Context) NewBuffer(bufferType BufferType, v interface{}, bufferUsageType BufferUsageType) {

View File

@ -20,3 +20,4 @@ type locationCacheKey struct {
}
var uniformLocationCache = map[locationCacheKey]UniformLocation{}
var attribLocationCache = map[locationCacheKey]AttribLocation{}