opengl: Reduce calls of glSetViewport

This commit is contained in:
Hajime Hoshi 2016-06-05 03:16:54 +09:00
parent 4c2650c721
commit e5965d7771
4 changed files with 14 additions and 9 deletions

View File

@ -39,9 +39,11 @@ type Context struct {
context
}
func (c *Context) bindFramebuffer(f Framebuffer) {
func (c *Context) bindFramebuffer(f Framebuffer) bool {
if c.lastFramebuffer != f {
c.bindFramebufferImpl(f)
c.lastFramebuffer = f
return true
}
return false
}

View File

@ -228,8 +228,9 @@ func (c *Context) NewFramebuffer(texture Texture) (Framebuffer, error) {
func (c *Context) SetViewport(f Framebuffer, width, height int) error {
return c.RunOnContextThread(func() error {
c.bindFramebuffer(f)
gl.Viewport(0, 0, int32(width), int32(height))
if c.bindFramebuffer(f) {
gl.Viewport(0, 0, int32(width), int32(height))
}
return nil
})
}

View File

@ -205,9 +205,10 @@ func (c *Context) NewFramebuffer(t Texture) (Framebuffer, error) {
}
func (c *Context) SetViewport(f Framebuffer, width, height int) error {
c.bindFramebuffer(f)
gl := c.gl
gl.Viewport(0, 0, width, height)
if c.bindFramebuffer(f) {
gl := c.gl
gl.Viewport(0, 0, width, height)
}
return nil
}

View File

@ -182,9 +182,10 @@ func (c *Context) NewFramebuffer(texture Texture) (Framebuffer, error) {
}
func (c *Context) SetViewport(f Framebuffer, width, height int) error {
gl := c.gl
c.bindFramebuffer(f)
gl.Viewport(0, 0, width, height)
if c.bindFramebuffer(f) {
gl := c.gl
gl.Viewport(0, 0, width, height)
}
return nil
}