From 44d1b137e736f8f87de2d4a7f6030e9a3dd34eae Mon Sep 17 00:00:00 2001 From: Hajime Hoshi Date: Sat, 17 Nov 2018 19:29:52 +0900 Subject: [PATCH] graphicsdriver/opengl: Refactoring --- internal/graphicsdriver/opengl/context.go | 4 ++++ internal/graphicsdriver/opengl/image.go | 4 ++-- internal/graphicsdriver/opengl/program.go | 3 --- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/internal/graphicsdriver/opengl/context.go b/internal/graphicsdriver/opengl/context.go index f887d96c1..835337f33 100644 --- a/internal/graphicsdriver/opengl/context.go +++ b/internal/graphicsdriver/opengl/context.go @@ -86,7 +86,11 @@ func (c *context) bindFramebuffer(f framebufferNative) { func (c *context) setViewport(f *framebuffer) { c.bindFramebuffer(f.native) if c.lastViewportWidth != f.width || c.lastViewportHeight != f.height { + // On some environments, viewport size must be within the framebuffer size. + // e.g. Edge (#71), Chrome on GPD Pocket (#420), macOS Mojave (#691). + // Use the same size of the framebuffer here. c.setViewportImpl(f.width, f.height) + // glViewport must be called at least at every frame on iOS. // As the screen framebuffer is the last render target, next SetViewport should be // the first call at a frame. diff --git a/internal/graphicsdriver/opengl/image.go b/internal/graphicsdriver/opengl/image.go index f4025448a..8a09bbd71 100644 --- a/internal/graphicsdriver/opengl/image.go +++ b/internal/graphicsdriver/opengl/image.go @@ -73,8 +73,8 @@ func (i *Image) ensureFramebuffer() error { if i.framebuffer != nil { return nil } - w, h := i.width, i.height - f, err := newFramebufferFromTexture(&i.driver.context, i.textureNative, math.NextPowerOf2Int(w), math.NextPowerOf2Int(h)) + w, h := math.NextPowerOf2Int(i.width), math.NextPowerOf2Int(i.height) + f, err := newFramebufferFromTexture(&i.driver.context, i.textureNative, w, h) if err != nil { return err } diff --git a/internal/graphicsdriver/opengl/program.go b/internal/graphicsdriver/opengl/program.go index 3f6beaab8..5a777c405 100644 --- a/internal/graphicsdriver/opengl/program.go +++ b/internal/graphicsdriver/opengl/program.go @@ -264,9 +264,6 @@ func (d *Driver) useProgram(mode graphics.CompositeMode, colorM *affine.ColorM, panic("source image is not set") } - // On some environments, viewport size must be within the framebuffer size. - // e.g. Edge (#71), Chrome on GPD Pocket (#420), macOS Mojave (#691). - // Use the same size of the framebuffer here. if err := destination.setViewport(); err != nil { return err }