mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-12-25 19:28:57 +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 Shader js.Object
|
||||||
type Program js.Object
|
type Program js.Object
|
||||||
type UniformLocation js.Object
|
type UniformLocation js.Object
|
||||||
type AttribLocation js.Object
|
type AttribLocation int
|
||||||
|
|
||||||
type context struct {
|
type context struct {
|
||||||
gl *webgl.Context
|
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) {
|
func (c *Context) VertexAttribPointer(p Program, location string, stride int, v uintptr) {
|
||||||
gl := c.gl
|
gl := c.gl
|
||||||
l := gl.GetAttribLocation(p, location)
|
key := locationCacheKey{p, location}
|
||||||
gl.VertexAttribPointer(l, 2, gl.FLOAT, false, stride, int(v))
|
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) {
|
func (c *Context) EnableVertexAttribArray(p Program, location string) {
|
||||||
gl := c.gl
|
gl := c.gl
|
||||||
l := gl.GetAttribLocation(p, location)
|
key := locationCacheKey{p, location}
|
||||||
gl.EnableVertexAttribArray(l)
|
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) {
|
func (c *Context) DisableVertexAttribArray(p Program, location string) {
|
||||||
gl := c.gl
|
gl := c.gl
|
||||||
l := gl.GetAttribLocation(p, location)
|
key := locationCacheKey{p, location}
|
||||||
gl.DisableVertexAttribArray(l)
|
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) {
|
func (c *Context) NewBuffer(bufferType BufferType, v interface{}, bufferUsageType BufferUsageType) {
|
||||||
|
@ -20,3 +20,4 @@ type locationCacheKey struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var uniformLocationCache = map[locationCacheKey]UniformLocation{}
|
var uniformLocationCache = map[locationCacheKey]UniformLocation{}
|
||||||
|
var attribLocationCache = map[locationCacheKey]AttribLocation{}
|
||||||
|
Loading…
Reference in New Issue
Block a user