From d30f8a2bbff1b72004d18a100d85fed9ad8c45e5 Mon Sep 17 00:00:00 2001 From: Hajime Hoshi Date: Thu, 7 Sep 2017 03:08:22 +0900 Subject: [PATCH] graphics: Fix viewport sizes for Edge (#71) --- internal/graphics/command.go | 2 ++ internal/graphics/framebuffer.go | 30 +++++++++++++++++++++--------- internal/graphics/image.go | 4 ++-- 3 files changed, 25 insertions(+), 11 deletions(-) diff --git a/internal/graphics/command.go b/internal/graphics/command.go index 666276625..315bd9b86 100644 --- a/internal/graphics/command.go +++ b/internal/graphics/command.go @@ -381,6 +381,8 @@ func (c *newScreenFramebufferImageCommand) Exec(indexOffsetInBytes int) error { f := &framebuffer{ native: opengl.GetContext().ScreenFramebuffer(), flipY: true, + width: c.width, + height: c.height, offsetX: c.offsetX, offsetY: c.offsetY, } diff --git a/internal/graphics/framebuffer.go b/internal/graphics/framebuffer.go index 233b6bb1b..7c56b6df2 100644 --- a/internal/graphics/framebuffer.go +++ b/internal/graphics/framebuffer.go @@ -16,6 +16,7 @@ package graphics import ( "github.com/hajimehoshi/ebiten/internal/opengl" + "github.com/hajimehoshi/ebiten/internal/web" ) func orthoProjectionMatrix(left, right, bottom, top int) []float32 { @@ -36,39 +37,50 @@ type framebuffer struct { native opengl.Framebuffer flipY bool proMatrix []float32 + width int + height int offsetX float64 offsetY float64 } -func newFramebufferFromTexture(texture *texture) (*framebuffer, error) { +func newFramebufferFromTexture(texture *texture, width, height int) (*framebuffer, error) { native, err := opengl.GetContext().NewFramebuffer(opengl.Texture(texture.native)) if err != nil { return nil, err } return &framebuffer{ native: native, + width: width, + height: height, }, nil } -const viewportSize = 4096 +const defaultViewportSize = 4096 + +func (f *framebuffer) viewportSize() (int, int) { + if web.IsEdgeBrowser() { + return f.width, f.height + } + return defaultViewportSize, defaultViewportSize +} func (f *framebuffer) setAsViewport() error { - width := viewportSize - height := viewportSize - return opengl.GetContext().SetViewport(f.native, width, height) + w, h := f.viewportSize() + return opengl.GetContext().SetViewport(f.native, w, h) } func (f *framebuffer) projectionMatrix(height int) []float32 { if f.proMatrix != nil { return f.proMatrix } - m := orthoProjectionMatrix(0, viewportSize, 0, viewportSize) + w, h := f.viewportSize() + m := orthoProjectionMatrix(0, w, 0, h) if f.flipY { m[4*1+1] *= -1 - m[4*3+1] += float32(height) / float32(viewportSize) * 2 + m[4*3+1] += float32(height) / float32(h) * 2 } - m[4*3+0] += float32(f.offsetX) / float32(viewportSize) * 2 - m[4*3+1] += float32(f.offsetY) / float32(viewportSize) * 2 + m[4*3+0] += float32(f.offsetX) / float32(w) * 2 + m[4*3+1] += float32(f.offsetY) / float32(h) * 2 f.proMatrix = m return f.proMatrix } diff --git a/internal/graphics/image.go b/internal/graphics/image.go index e2b8caeb6..9c1ee29a0 100644 --- a/internal/graphics/image.go +++ b/internal/graphics/image.go @@ -29,7 +29,7 @@ type Image struct { height int } -const MaxImageSize = viewportSize +const MaxImageSize = defaultViewportSize func NewImage(width, height int, filter opengl.Filter) *Image { i := &Image{ @@ -132,7 +132,7 @@ func (i *Image) createFramebufferIfNeeded() (*framebuffer, error) { if i.framebuffer != nil { return i.framebuffer, nil } - f, err := newFramebufferFromTexture(i.texture) + f, err := newFramebufferFromTexture(i.texture, math.NextPowerOf2Int(i.width), math.NextPowerOf2Int(i.height)) if err != nil { return nil, err }