diff --git a/internal/graphics/opengl/context.go b/internal/graphics/opengl/context.go index f32a28f29..b90bbb134 100644 --- a/internal/graphics/opengl/context.go +++ b/internal/graphics/opengl/context.go @@ -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 { - c.bindFramebufferImpl(f) - c.lastFramebuffer = f - return true +func (c *Context) bindFramebuffer(f Framebuffer) { + if c.lastFramebuffer == f { + return } - return false + c.bindFramebufferImpl(f) + c.lastFramebuffer = f } diff --git a/internal/graphics/opengl/context_desktop.go b/internal/graphics/opengl/context_desktop.go index b87da67f6..2037c10c4 100644 --- a/internal/graphics/opengl/context_desktop.go +++ b/internal/graphics/opengl/context_desktop.go @@ -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 }) diff --git a/internal/graphics/opengl/context_js.go b/internal/graphics/opengl/context_js.go index 348720fd4..8576d9f94 100644 --- a/internal/graphics/opengl/context_js.go +++ b/internal/graphics/opengl/context_js.go @@ -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 } diff --git a/internal/graphics/opengl/context_mobile.go b/internal/graphics/opengl/context_mobile.go index 04f9ba39a..e6e43a041 100644 --- a/internal/graphics/opengl/context_mobile.go +++ b/internal/graphics/opengl/context_mobile.go @@ -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)) }