opengl: Bug fix: glViewport must be called after framebuffer deletion

This commit is contained in:
Hajime Hoshi 2016-06-05 07:47:11 +09:00
parent 37473d2f9f
commit 12904d168d
4 changed files with 21 additions and 9 deletions

View File

@ -35,15 +35,16 @@ type Context struct {
oneMinusDstAlpha operation
locationCache *locationCache
lastFramebuffer Framebuffer
lastViewportWidth int
lastViewportHeight int
lastCompositeMode CompositeMode
context
}
func (c *Context) bindFramebuffer(f Framebuffer) bool {
if c.lastFramebuffer != f {
func (c *Context) bindFramebuffer(f Framebuffer) {
if c.lastFramebuffer == f {
return
}
c.bindFramebufferImpl(f)
c.lastFramebuffer = f
return true
}
return false
}

View File

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

View File

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

View File

@ -182,9 +182,12 @@ func (c *Context) NewFramebuffer(texture Texture) (Framebuffer, error) {
}
func (c *Context) SetViewport(f Framebuffer, width, height int) error {
if c.bindFramebuffer(f) {
c.bindFramebuffer(f)
if c.lastViewportWidth != width || c.lastViewportHeight != height {
gl := c.gl
gl.Viewport(0, 0, width, height)
c.lastViewportWidth = width
c.lastViewportHeight = height
}
return nil
}
@ -203,6 +206,8 @@ func (c *Context) DeleteFramebuffer(f Framebuffer) {
// https://www.khronos.org/opengles/sdk/docs/man/xhtml/glDeleteFramebuffers.xml
if c.lastFramebuffer == f {
c.lastFramebuffer = ZeroFramebuffer
c.lastViewportWidth = 0
c.lastViewportHeight = 0
}
gl.DeleteFramebuffer(mgl.Framebuffer(f))
}