From 72c02fc3981871bf6a02a32342fb7a72fe3a5aa2 Mon Sep 17 00:00:00 2001 From: Hajime Hoshi Date: Sat, 9 Sep 2017 19:24:56 +0900 Subject: [PATCH] graphics: Bug fix: viewport size must be within the framebuffer size This fixes #71 and #420 --- internal/graphics/framebuffer.go | 6 +++++- internal/web/js.go | 9 ++++----- internal/web/notjs.go | 4 ++-- 3 files changed, 11 insertions(+), 8 deletions(-) diff --git a/internal/graphics/framebuffer.go b/internal/graphics/framebuffer.go index 7c56b6df2..16cfa04e0 100644 --- a/internal/graphics/framebuffer.go +++ b/internal/graphics/framebuffer.go @@ -58,9 +58,13 @@ func newFramebufferFromTexture(texture *texture, width, height int) (*framebuffe const defaultViewportSize = 4096 func (f *framebuffer) viewportSize() (int, int) { - if web.IsEdgeBrowser() { + // On some browsers, viewport size must be within the framebuffer size. + // e.g. Edge (#71), Chrome on GPD Pocket (#420) + if web.IsBrowser() { return f.width, f.height } + + // If possible, always use the same viewport size to reduce draw calls. return defaultViewportSize, defaultViewportSize } diff --git a/internal/web/js.go b/internal/web/js.go index 0e323f0fb..3ae242c57 100644 --- a/internal/web/js.go +++ b/internal/web/js.go @@ -22,6 +22,10 @@ import ( "github.com/gopherjs/gopherjs/js" ) +func IsBrowser() bool { + return true +} + func isIOS() bool { ua := js.Global.Get("navigator").Get("userAgent").String() if !strings.Contains(ua, "iPhone") { @@ -44,8 +48,3 @@ func isAndroidChrome() bool { func IsMobileBrowser() bool { return isIOS() || isAndroidChrome() } - -func IsEdgeBrowser() bool { - ua := js.Global.Get("navigator").Get("userAgent").String() - return strings.Contains(ua, "Edge") -} diff --git a/internal/web/notjs.go b/internal/web/notjs.go index 3250b9ce0..bdd483258 100644 --- a/internal/web/notjs.go +++ b/internal/web/notjs.go @@ -16,10 +16,10 @@ package web -func IsMobileBrowser() bool { +func IsBrowser() bool { return false } -func IsEdgeBrowser() bool { +func IsMobileBrowser() bool { return false }