diff --git a/internal/graphics/opengl/context.go b/internal/graphics/opengl/context.go index f9454a712..7da4f6fd1 100644 --- a/internal/graphics/opengl/context.go +++ b/internal/graphics/opengl/context.go @@ -38,8 +38,8 @@ type Context struct { } func (c *Context) bindFramebuffer(f Framebuffer) { - // TODO: This is a temporal hack to pass the tests. - // Fix the bug (#227). - c.bindFramebufferImpl(f) - c.lastFramebuffer = f + if c.lastFramebuffer != f { + c.bindFramebufferImpl(f) + c.lastFramebuffer = f + } } diff --git a/internal/graphics/opengl/context_desktop.go b/internal/graphics/opengl/context_desktop.go index ec53192bf..6749092ab 100644 --- a/internal/graphics/opengl/context_desktop.go +++ b/internal/graphics/opengl/context_desktop.go @@ -247,6 +247,12 @@ func (c *Context) FillFramebuffer(r, g, b, a float64) error { func (c *Context) DeleteFramebuffer(f Framebuffer) { c.RunOnContextThread(func() error { ff := uint32(f) + // If a framebuffer to be delted is bound, a newly bound framebuffer + // will be a default framebuffer. + // https://www.khronos.org/opengles/sdk/docs/man/xhtml/glDeleteFramebuffers.xml + if c.lastFramebuffer == f { + c.lastFramebuffer = ZeroFramebuffer + } gl.DeleteFramebuffers(1, &ff) return nil }) diff --git a/internal/graphics/opengl/context_js.go b/internal/graphics/opengl/context_js.go index 3bd9b836c..525a4b7c3 100644 --- a/internal/graphics/opengl/context_js.go +++ b/internal/graphics/opengl/context_js.go @@ -223,6 +223,12 @@ func (c *Context) FillFramebuffer(r, g, b, a float64) error { func (c *Context) DeleteFramebuffer(f Framebuffer) { gl := c.gl + // If a framebuffer to be delted is bound, a newly bound framebuffer + // will be a default framebuffer. + // https://www.khronos.org/opengles/sdk/docs/man/xhtml/glDeleteFramebuffers.xml + if c.lastFramebuffer == f { + c.lastFramebuffer = ZeroFramebuffer + } gl.DeleteFramebuffer(f.Object) } diff --git a/internal/graphics/opengl/context_mobile.go b/internal/graphics/opengl/context_mobile.go index a1d191131..f7e35e848 100644 --- a/internal/graphics/opengl/context_mobile.go +++ b/internal/graphics/opengl/context_mobile.go @@ -199,6 +199,12 @@ func (c *Context) FillFramebuffer(r, g, b, a float64) error { func (c *Context) DeleteFramebuffer(f Framebuffer) { gl := c.gl + // If a framebuffer to be delted is bound, a newly bound framebuffer + // will be a default framebuffer. + // https://www.khronos.org/opengles/sdk/docs/man/xhtml/glDeleteFramebuffers.xml + if c.lastFramebuffer == f { + c.lastFramebuffer = ZeroFramebuffer + } gl.DeleteFramebuffer(mgl.Framebuffer(f)) }