opengl: Define Texture/Framebuffer Equals for JS performance

This commit is contained in:
Hajime Hoshi 2017-07-02 22:18:49 +09:00
parent 3a3a4af035
commit 26a83c0e00
4 changed files with 29 additions and 2 deletions

View File

@ -54,7 +54,7 @@ func GetContext() *Context {
}
func (c *Context) BindTexture(t Texture) error {
if c.lastTexture == t {
if c.lastTexture.equals(t) {
return nil
}
if err := c.bindTextureImpl(t); err != nil {
@ -65,7 +65,7 @@ func (c *Context) BindTexture(t Texture) error {
}
func (c *Context) bindFramebuffer(f Framebuffer) error {
if c.lastFramebuffer == f {
if c.lastFramebuffer.equals(f) {
return nil
}
if err := c.bindFramebufferImpl(f); err != nil {

View File

@ -32,6 +32,14 @@ type Shader uint32
type Program uint32
type Buffer uint32
func (t Texture) equals(other Texture) bool {
return t == other
}
func (f Framebuffer) equals(other Framebuffer) bool {
return f == other
}
type uniformLocation int32
type attribLocation int32

View File

@ -24,6 +24,9 @@ import (
"github.com/gopherjs/webgl"
)
// Note that `type Texture *js.Object` doesn't work.
// There is no way to get the internal object in that case.
type Texture struct {
*js.Object
}
@ -44,6 +47,14 @@ type Buffer struct {
*js.Object
}
func (t Texture) equals(other Texture) bool {
return t.Object == other.Object
}
func (f Framebuffer) equals(other Framebuffer) bool {
return f.Object == other.Object
}
type uniformLocation struct {
*js.Object
}

View File

@ -31,6 +31,14 @@ type Shader mgl.Shader
type Program mgl.Program
type Buffer mgl.Buffer
func (t Texture) equals(other Texture) bool {
return t == other
}
func (f Framebuffer) equals(other Framebuffer) bool {
return f == other
}
type uniformLocation mgl.Uniform
type attribLocation mgl.Attrib