mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2025-01-11 19:48:54 +01:00
Avoid using struct key
This commit is contained in:
parent
3ad8d8ea2c
commit
52e610845b
@ -198,22 +198,20 @@ func (c *Context) UseProgram(p Program) {
|
|||||||
|
|
||||||
func (c *Context) UniformInt(p Program, location string, v int) {
|
func (c *Context) UniformInt(p Program, location string, v int) {
|
||||||
gl := c.gl
|
gl := c.gl
|
||||||
key := locationCacheKey{p, location}
|
l, ok := uniformLocationCache[location]
|
||||||
l, ok := uniformLocationCache[key]
|
|
||||||
if !ok {
|
if !ok {
|
||||||
l = gl.GetUniformLocation(p, location)
|
l = gl.GetUniformLocation(p, location)
|
||||||
uniformLocationCache[key] = l
|
uniformLocationCache[location] = l
|
||||||
}
|
}
|
||||||
gl.Uniform1i(l, v)
|
gl.Uniform1i(l, v)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Context) UniformFloats(p Program, location string, v []float32) {
|
func (c *Context) UniformFloats(p Program, location string, v []float32) {
|
||||||
gl := c.gl
|
gl := c.gl
|
||||||
key := locationCacheKey{p, location}
|
l, ok := uniformLocationCache[location]
|
||||||
l, ok := uniformLocationCache[key]
|
|
||||||
if !ok {
|
if !ok {
|
||||||
l = gl.GetUniformLocation(p, location)
|
l = gl.GetUniformLocation(p, location)
|
||||||
uniformLocationCache[key] = l
|
uniformLocationCache[location] = l
|
||||||
}
|
}
|
||||||
switch len(v) {
|
switch len(v) {
|
||||||
case 4:
|
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) {
|
func (c *Context) VertexAttribPointer(p Program, location string, stride int, v uintptr) {
|
||||||
gl := c.gl
|
gl := c.gl
|
||||||
key := locationCacheKey{p, location}
|
l, ok := attribLocationCache[location]
|
||||||
l, ok := attribLocationCache[key]
|
|
||||||
if !ok {
|
if !ok {
|
||||||
l = AttribLocation(gl.GetAttribLocation(p, location))
|
l = AttribLocation(gl.GetAttribLocation(p, location))
|
||||||
attribLocationCache[key] = l
|
attribLocationCache[location] = l
|
||||||
}
|
}
|
||||||
gl.VertexAttribPointer(int(l), 2, gl.FLOAT, false, stride, int(v))
|
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
|
||||||
key := locationCacheKey{p, location}
|
l, ok := attribLocationCache[location]
|
||||||
l, ok := attribLocationCache[key]
|
|
||||||
if !ok {
|
if !ok {
|
||||||
l = AttribLocation(gl.GetAttribLocation(p, location))
|
l = AttribLocation(gl.GetAttribLocation(p, location))
|
||||||
attribLocationCache[key] = l
|
attribLocationCache[location] = l
|
||||||
}
|
}
|
||||||
gl.EnableVertexAttribArray(int(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
|
||||||
key := locationCacheKey{p, location}
|
l, ok := attribLocationCache[location]
|
||||||
l, ok := attribLocationCache[key]
|
|
||||||
if !ok {
|
if !ok {
|
||||||
l = AttribLocation(gl.GetAttribLocation(p, location))
|
l = AttribLocation(gl.GetAttribLocation(p, location))
|
||||||
attribLocationCache[key] = l
|
attribLocationCache[location] = l
|
||||||
}
|
}
|
||||||
gl.DisableVertexAttribArray(int(l))
|
gl.DisableVertexAttribArray(int(l))
|
||||||
}
|
}
|
||||||
|
@ -14,10 +14,7 @@
|
|||||||
|
|
||||||
package opengl
|
package opengl
|
||||||
|
|
||||||
type locationCacheKey struct {
|
// Note: This cache is created only for one program.
|
||||||
program Program
|
// If we use two or more programs, the key of the map should be changed.
|
||||||
name string
|
var uniformLocationCache = map[string]UniformLocation{}
|
||||||
}
|
var attribLocationCache = map[string]AttribLocation{}
|
||||||
|
|
||||||
var uniformLocationCache = map[locationCacheKey]UniformLocation{}
|
|
||||||
var attribLocationCache = map[locationCacheKey]AttribLocation{}
|
|
||||||
|
Loading…
Reference in New Issue
Block a user