opengl: Remove struct usages to avoid copying

This commit is contained in:
Hajime Hoshi 2018-02-19 01:38:17 +09:00
parent 896a47b2ee
commit 2fbfd0bdcb

View File

@ -57,9 +57,7 @@ func (f Framebuffer) equals(other Framebuffer) bool {
return f.Object == other.Object return f.Object == other.Object
} }
type uniformLocation struct { type uniformLocation interface{}
*js.Object
}
type attribLocation int type attribLocation int
@ -333,13 +331,13 @@ func (c *Context) DeleteProgram(p Program) {
func (c *Context) getUniformLocationImpl(p Program, location string) uniformLocation { func (c *Context) getUniformLocationImpl(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) {
gl := c.gl gl := c.gl
l := c.locationCache.GetUniformLocation(c, p, location) l := c.locationCache.GetUniformLocation(c, p, location)
gl.Uniform1i(l.Object, v) gl.Uniform1i(l.(*js.Object), v)
} }
func (c *Context) UniformFloats(p Program, location string, v []float32) { func (c *Context) UniformFloats(p Program, location string, v []float32) {
@ -347,11 +345,11 @@ func (c *Context) UniformFloats(p Program, location string, v []float32) {
l := c.locationCache.GetUniformLocation(c, p, location) l := c.locationCache.GetUniformLocation(c, p, location)
switch len(v) { switch len(v) {
case 2: case 2:
gl.Call("uniform2fv", l.Object, v) gl.Call("uniform2fv", l.(*js.Object), v)
case 4: case 4:
gl.Call("uniform4fv", l.Object, v) gl.Call("uniform4fv", l.(*js.Object), v)
case 16: case 16:
gl.UniformMatrix4fv(l.Object, false, v) gl.UniformMatrix4fv(l.(*js.Object), false, v)
default: default:
panic("not reached") panic("not reached")
} }