diff --git a/graphicscontext.go b/graphicscontext.go index e316466a3..7799237ee 100644 --- a/graphicscontext.go +++ b/graphicscontext.go @@ -17,7 +17,6 @@ package ebiten import ( "github.com/hajimehoshi/ebiten/internal/clock" "github.com/hajimehoshi/ebiten/internal/hooks" - "github.com/hajimehoshi/ebiten/internal/math" "github.com/hajimehoshi/ebiten/internal/restorable" "github.com/hajimehoshi/ebiten/internal/ui" "github.com/hajimehoshi/ebiten/internal/web" @@ -59,9 +58,7 @@ func (c *graphicsContext) SetSize(screenWidth, screenHeight int, screenScale flo w := int(float64(screenWidth) * screenScale) h := int(float64(screenHeight) * screenScale) px0, py0, px1, py1 := ui.ScreenPadding() - fw := math.NextPowerOf2Int(w + int(px0+px1)) - fh := math.NextPowerOf2Int(h + int(py0+py1)) - c.screen = newImageWithScreenFramebuffer(w, h, fw, fh) + c.screen = newImageWithScreenFramebuffer(w, h, px0, py0, px1, py1) _ = c.screen.Clear() c.offscreen = offscreen diff --git a/image.go b/image.go index 30540d981..4a289f01b 100644 --- a/image.go +++ b/image.go @@ -407,9 +407,9 @@ func NewImageFromImage(source image.Image, filter Filter) (*Image, error) { return i, nil } -func newImageWithScreenFramebuffer(width, height, framebufferWidth, framebufferHeight int) *Image { +func newImageWithScreenFramebuffer(width, height int, paddingX0, paddingY0, paddingX1, paddingY1 float64) *Image { checkSize(width, height) - r := restorable.NewScreenFramebufferImage(width, height, framebufferWidth, framebufferHeight) + r := restorable.NewScreenFramebufferImage(width, height, paddingX0, paddingY0, paddingX1, paddingY1) i := &Image{ restorable: r, filter: FilterDefault, diff --git a/internal/restorable/image.go b/internal/restorable/image.go index c8f28dd83..89cd6cb9d 100644 --- a/internal/restorable/image.go +++ b/internal/restorable/image.go @@ -80,8 +80,10 @@ type Image struct { // screen indicates whether the image is used as an actual screen. screen bool - framebufferWidth int - framebufferHeight int + paddingX0 float64 + paddingY0 float64 + paddingX1 float64 + paddingY1 float64 } // NewImage creates an empty image with the given size. @@ -115,13 +117,15 @@ func NewImageFromImage(source image.Image) *Image { } // NewScreenFramebufferImage creates a special image that framebuffer is one for the screen. -func NewScreenFramebufferImage(width, height, framebufferWidth, framebufferHeight int) *Image { +func NewScreenFramebufferImage(width, height int, paddingX0, paddingY0, paddingX1, paddingY1 float64) *Image { i := &Image{ - image: graphics.NewScreenFramebufferImage(width, height), - volatile: true, - screen: true, - framebufferWidth: framebufferWidth, - framebufferHeight: framebufferHeight, + image: graphics.NewScreenFramebufferImage(width, height), + volatile: true, + screen: true, + paddingX0: paddingX0, + paddingY0: paddingY0, + paddingX1: paddingX1, + paddingY1: paddingY1, } theImages.add(i) runtime.SetFinalizer(i, (*Image).Dispose) @@ -166,10 +170,11 @@ func (i *Image) clearIfVolatile() { panic("not reached") } + w, h := i.image.Size() x0 := float32(0) y0 := float32(0) - x1 := float32(i.framebufferWidth) - y1 := float32(i.framebufferHeight) + x1 := float32(w) + float32(i.paddingX0+i.paddingX1) + y1 := float32(h) + float32(i.paddingY0+i.paddingY1) // For the rule of values, see vertices.go. clearVertices := []float32{ x0, y0, 0, 0, 1, 1,