mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-12-26 03:38:55 +01:00
graphics: Refactoring: easier way to clear framebuffer
This commit is contained in:
parent
8ef0f1ac6a
commit
9db042ae9e
@ -57,8 +57,8 @@ 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)
|
||||
px0, py0, _, _ := ui.ScreenPadding()
|
||||
c.screen = newImageWithScreenFramebuffer(w, h)
|
||||
_ = c.screen.Clear()
|
||||
|
||||
c.offscreen = offscreen
|
||||
|
4
image.go
4
image.go
@ -421,9 +421,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 int) *Image {
|
||||
checkSize(width, height)
|
||||
r := restorable.NewScreenFramebufferImage(width, height, paddingX0, paddingY0, paddingX1, paddingY1)
|
||||
r := restorable.NewScreenFramebufferImage(width, height)
|
||||
i := &Image{
|
||||
restorable: r,
|
||||
filter: FilterDefault,
|
||||
|
@ -111,3 +111,7 @@ func (i *Image) createFramebufferIfNeeded() (*framebuffer, error) {
|
||||
i.framebuffer = f
|
||||
return i.framebuffer, nil
|
||||
}
|
||||
|
||||
func (i *Image) ViewportSize() (int, int) {
|
||||
return i.framebuffer.viewportSize()
|
||||
}
|
||||
|
@ -17,7 +17,6 @@ package restorable
|
||||
import (
|
||||
"errors"
|
||||
"image/color"
|
||||
"math"
|
||||
"runtime"
|
||||
|
||||
"github.com/hajimehoshi/ebiten/internal/affine"
|
||||
@ -74,11 +73,6 @@ type Image struct {
|
||||
|
||||
// screen indicates whether the image is used as an actual screen.
|
||||
screen bool
|
||||
|
||||
paddingX0 float64
|
||||
paddingY0 float64
|
||||
paddingX1 float64
|
||||
paddingY1 float64
|
||||
}
|
||||
|
||||
// NewImage creates an empty image with the given size.
|
||||
@ -93,15 +87,11 @@ func NewImage(width, height int, volatile bool) *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 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,
|
||||
}
|
||||
theImages.add(i)
|
||||
runtime.SetFinalizer(i, (*Image).Dispose)
|
||||
@ -146,11 +136,11 @@ func (i *Image) clearIfVolatile() {
|
||||
panic("not reached")
|
||||
}
|
||||
|
||||
w, h := i.image.Size()
|
||||
w, h := i.image.ViewportSize()
|
||||
x0 := float32(0)
|
||||
y0 := float32(0)
|
||||
x1 := float32(w + int(math.Ceil(i.paddingX0+i.paddingX1)))
|
||||
y1 := float32(h + int(math.Ceil(i.paddingY0+i.paddingY1)))
|
||||
x1 := float32(w)
|
||||
y1 := float32(h)
|
||||
// For the rule of values, see vertices.go.
|
||||
clearVertices := []float32{
|
||||
x0, y0, 0, 0, 1, 1,
|
||||
|
Loading…
Reference in New Issue
Block a user