opengl: Unexport Attrib/UniformLocation

This commit is contained in:
Hajime Hoshi 2016-02-27 03:13:42 +09:00
parent ccf0acf7ca
commit 997539b243
4 changed files with 28 additions and 28 deletions

View File

@ -37,8 +37,8 @@ func (p Program) Equals(other Program) bool {
return p == other return p == other
} }
type UniformLocation int32 type uniformLocation int32
type AttribLocation int32 type attribLocation int32
type programID uint32 type programID uint32
@ -313,8 +313,8 @@ func (c *Context) UseProgram(p Program) {
}) })
} }
func (c *Context) getUniformLocation(p Program, location string) UniformLocation { func (c *Context) getUniformLocation(p Program, location string) uniformLocation {
uniform := UniformLocation(gl.GetUniformLocation(uint32(p), gl.Str(location+"\x00"))) uniform := uniformLocation(gl.GetUniformLocation(uint32(p), gl.Str(location+"\x00")))
if uniform == -1 { if uniform == -1 {
panic("opengl: invalid uniform location: " + location) panic("opengl: invalid uniform location: " + location)
} }
@ -342,8 +342,8 @@ func (c *Context) UniformFloats(p Program, location string, v []float32) {
}) })
} }
func (c *Context) getAttribLocation(p Program, location string) AttribLocation { func (c *Context) getAttribLocation(p Program, location string) attribLocation {
attrib := AttribLocation(gl.GetAttribLocation(uint32(p), gl.Str(location+"\x00"))) attrib := attribLocation(gl.GetAttribLocation(uint32(p), gl.Str(location+"\x00")))
if attrib == -1 { if attrib == -1 {
panic("invalid attrib location: " + location) panic("invalid attrib location: " + location)
} }

View File

@ -50,11 +50,11 @@ func (p Program) Equals(other Program) bool {
return p.Object == other.Object return p.Object == other.Object
} }
type UniformLocation struct { type uniformLocation struct {
*js.Object *js.Object
} }
type AttribLocation int type attribLocation int
type programID int type programID int
@ -289,9 +289,9 @@ func (c *Context) UseProgram(p Program) {
gl.UseProgram(p.Object) gl.UseProgram(p.Object)
} }
func (c *Context) getUniformLocation(p Program, location string) UniformLocation { func (c *Context) getUniformLocation(p Program, location string) uniformLocation {
gl := c.gl gl := c.gl
return UniformLocation{gl.GetUniformLocation(p.Object, location)} return uniformLocation{gl.GetUniformLocation(p.Object, location)}
} }
func (c *Context) UniformInt(p Program, location string, v int) { func (c *Context) UniformInt(p Program, location string, v int) {
@ -313,9 +313,9 @@ func (c *Context) UniformFloats(p Program, location string, v []float32) {
} }
} }
func (c *Context) getAttribLocation(p Program, location string) AttribLocation { func (c *Context) getAttribLocation(p Program, location string) attribLocation {
gl := c.gl gl := c.gl
return AttribLocation(gl.GetAttribLocation(p.Object, location)) return attribLocation(gl.GetAttribLocation(p.Object, location))
} }
func (c *Context) VertexAttribPointer(p Program, location string, normalize bool, stride int, size int, v int) { func (c *Context) VertexAttribPointer(p Program, location string, normalize bool, stride int, size int, v int) {

View File

@ -38,8 +38,8 @@ func (p Program) Equals(other Program) bool {
return p == other return p == other
} }
type UniformLocation mgl.Uniform type uniformLocation mgl.Uniform
type AttribLocation mgl.Attrib type attribLocation mgl.Attrib
type programID uint32 type programID uint32
@ -252,8 +252,8 @@ func (c *Context) UseProgram(p Program) {
gl.UseProgram(mgl.Program(p)) gl.UseProgram(mgl.Program(p))
} }
func (c *Context) getUniformLocation(p Program, location string) UniformLocation { func (c *Context) getUniformLocation(p Program, location string) uniformLocation {
u := UniformLocation(gl.GetUniformLocation(mgl.Program(p), location)) u := uniformLocation(gl.GetUniformLocation(mgl.Program(p), location))
if u.Value == -1 { if u.Value == -1 {
panic("invalid uniform location: " + location) panic("invalid uniform location: " + location)
} }
@ -276,8 +276,8 @@ func (c *Context) UniformFloats(p Program, location string, v []float32) {
} }
} }
func (c *Context) getAttribLocation(p Program, location string) AttribLocation { func (c *Context) getAttribLocation(p Program, location string) attribLocation {
a := AttribLocation(gl.GetAttribLocation(mgl.Program(p), location)) a := attribLocation(gl.GetAttribLocation(mgl.Program(p), location))
if a.Value == ^uint(0) { if a.Value == ^uint(0) {
panic("invalid attrib location: " + location) panic("invalid attrib location: " + location)
} }

View File

@ -17,27 +17,27 @@ package opengl
// Since js.Object (Program) can't be keys of a map, use integers (programID) instead. // Since js.Object (Program) can't be keys of a map, use integers (programID) instead.
type locationCache struct { type locationCache struct {
uniformLocationCache map[programID]map[string]UniformLocation uniformLocationCache map[programID]map[string]uniformLocation
attribLocationCache map[programID]map[string]AttribLocation attribLocationCache map[programID]map[string]attribLocation
} }
func newLocationCache() *locationCache { func newLocationCache() *locationCache {
return &locationCache{ return &locationCache{
uniformLocationCache: map[programID]map[string]UniformLocation{}, uniformLocationCache: map[programID]map[string]uniformLocation{},
attribLocationCache: map[programID]map[string]AttribLocation{}, attribLocationCache: map[programID]map[string]attribLocation{},
} }
} }
type uniformLocationGetter interface { type uniformLocationGetter interface {
getUniformLocation(p Program, location string) UniformLocation getUniformLocation(p Program, location string) uniformLocation
} }
// TODO: Rename these functions not to be confusing // TODO: Rename these functions not to be confusing
func (c *locationCache) GetUniformLocation(g uniformLocationGetter, p Program, location string) UniformLocation { func (c *locationCache) GetUniformLocation(g uniformLocationGetter, p Program, location string) uniformLocation {
id := p.id() id := p.id()
if _, ok := c.uniformLocationCache[id]; !ok { if _, ok := c.uniformLocationCache[id]; !ok {
c.uniformLocationCache[id] = map[string]UniformLocation{} c.uniformLocationCache[id] = map[string]uniformLocation{}
} }
l, ok := c.uniformLocationCache[id][location] l, ok := c.uniformLocationCache[id][location]
if !ok { if !ok {
@ -48,13 +48,13 @@ func (c *locationCache) GetUniformLocation(g uniformLocationGetter, p Program, l
} }
type attribLocationGetter interface { type attribLocationGetter interface {
getAttribLocation(p Program, location string) AttribLocation getAttribLocation(p Program, location string) attribLocation
} }
func (c *locationCache) GetAttribLocation(g attribLocationGetter, p Program, location string) AttribLocation { func (c *locationCache) GetAttribLocation(g attribLocationGetter, p Program, location string) attribLocation {
id := p.id() id := p.id()
if _, ok := c.attribLocationCache[id]; !ok { if _, ok := c.attribLocationCache[id]; !ok {
c.attribLocationCache[id] = map[string]AttribLocation{} c.attribLocationCache[id] = map[string]attribLocation{}
} }
l, ok := c.attribLocationCache[id][location] l, ok := c.attribLocationCache[id][location]
if !ok { if !ok {