graphics: Refactoring: clearing framebuffer

This commit is contained in:
Hajime Hoshi 2018-02-24 23:51:05 +09:00
parent a2d40e0908
commit 58f5c9c1d0
3 changed files with 16 additions and 18 deletions

View File

@ -17,6 +17,7 @@ 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"
@ -58,7 +59,9 @@ 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()
c.screen = newImageWithScreenFramebuffer(w, h, px0, py0, px1, py1)
fw := math.NextPowerOf2Int(w + int(px0+px1))
fh := math.NextPowerOf2Int(h + int(py0+py1))
c.screen = newImageWithScreenFramebuffer(w, h, fw, fh)
_ = c.screen.Clear()
c.offscreen = offscreen

View File

@ -382,9 +382,9 @@ func NewImageFromImage(source image.Image, filter Filter) (*Image, error) {
return i, nil
}
func newImageWithScreenFramebuffer(width, height int, paddingX0, paddingY0, paddingX1, paddingY1 float64) *Image {
func newImageWithScreenFramebuffer(width, height, framebufferWidth, framebufferHeight int) *Image {
checkSize(width, height)
r := restorable.NewScreenFramebufferImage(width, height, paddingX0, paddingY0, paddingX1, paddingY1)
r := restorable.NewScreenFramebufferImage(width, height, framebufferWidth, framebufferHeight)
i := &Image{r, FilterDefault}
runtime.SetFinalizer(i, (*Image).Dispose)
return i

View File

@ -80,10 +80,8 @@ type Image struct {
// screen indicates whether the image is used as an actual screen.
screen bool
paddingX0 float64
paddingY0 float64
paddingX1 float64
paddingY1 float64
framebufferWidth int
framebufferHeight int
}
// NewImage creates an empty image with the given size.
@ -117,15 +115,13 @@ func NewImageFromImage(source image.Image) *Image {
}
// NewScreenFramebufferImage creates a special image that framebuffer is one for the screen.
func NewScreenFramebufferImage(width, height int, paddingX0, paddingY0, paddingX1, paddingY1 float64) *Image {
func NewScreenFramebufferImage(width, height, framebufferWidth, framebufferHeight int) *Image {
i := &Image{
image: graphics.NewScreenFramebufferImage(width, height),
volatile: true,
screen: true,
paddingX0: paddingX0,
paddingY0: paddingY0,
paddingX1: paddingX1,
paddingY1: paddingY1,
image: graphics.NewScreenFramebufferImage(width, height),
volatile: true,
screen: true,
framebufferWidth: framebufferWidth,
framebufferHeight: framebufferHeight,
}
theImages.add(i)
runtime.SetFinalizer(i, (*Image).Dispose)
@ -170,11 +166,10 @@ func (i *Image) clearIfVolatile() {
panic("not reached")
}
w, h := i.image.Size()
x0 := float32(0)
y0 := float32(0)
x1 := float32(w) + float32(i.paddingX0+i.paddingX1)
y1 := float32(h) + float32(i.paddingY0+i.paddingY1)
x1 := float32(i.framebufferWidth)
y1 := float32(i.framebufferHeight)
// For the rule of values, see vertices.go.
clearVertices := []float32{
x0, y0, 0, 0, 1, 1,