mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-12-24 18:58:54 +01:00
Use attrib location cache
This commit is contained in:
parent
13a94d3446
commit
3ad8d8ea2c
@ -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) {
|
||||
|
@ -20,3 +20,4 @@ type locationCacheKey struct {
|
||||
}
|
||||
|
||||
var uniformLocationCache = map[locationCacheKey]UniformLocation{}
|
||||
var attribLocationCache = map[locationCacheKey]AttribLocation{}
|
||||
|
Loading…
Reference in New Issue
Block a user