mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-12-25 11:18:54 +01:00
graphics: Refactoring: clearing framebuffer
This commit is contained in:
parent
a2d40e0908
commit
58f5c9c1d0
@ -17,6 +17,7 @@ package ebiten
|
|||||||
import (
|
import (
|
||||||
"github.com/hajimehoshi/ebiten/internal/clock"
|
"github.com/hajimehoshi/ebiten/internal/clock"
|
||||||
"github.com/hajimehoshi/ebiten/internal/hooks"
|
"github.com/hajimehoshi/ebiten/internal/hooks"
|
||||||
|
"github.com/hajimehoshi/ebiten/internal/math"
|
||||||
"github.com/hajimehoshi/ebiten/internal/restorable"
|
"github.com/hajimehoshi/ebiten/internal/restorable"
|
||||||
"github.com/hajimehoshi/ebiten/internal/ui"
|
"github.com/hajimehoshi/ebiten/internal/ui"
|
||||||
"github.com/hajimehoshi/ebiten/internal/web"
|
"github.com/hajimehoshi/ebiten/internal/web"
|
||||||
@ -58,7 +59,9 @@ func (c *graphicsContext) SetSize(screenWidth, screenHeight int, screenScale flo
|
|||||||
w := int(float64(screenWidth) * screenScale)
|
w := int(float64(screenWidth) * screenScale)
|
||||||
h := int(float64(screenHeight) * screenScale)
|
h := int(float64(screenHeight) * screenScale)
|
||||||
px0, py0, px1, py1 := ui.ScreenPadding()
|
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.screen.Clear()
|
||||||
|
|
||||||
c.offscreen = offscreen
|
c.offscreen = offscreen
|
||||||
|
4
image.go
4
image.go
@ -382,9 +382,9 @@ func NewImageFromImage(source image.Image, filter Filter) (*Image, error) {
|
|||||||
return i, nil
|
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)
|
checkSize(width, height)
|
||||||
r := restorable.NewScreenFramebufferImage(width, height, paddingX0, paddingY0, paddingX1, paddingY1)
|
r := restorable.NewScreenFramebufferImage(width, height, framebufferWidth, framebufferHeight)
|
||||||
i := &Image{r, FilterDefault}
|
i := &Image{r, FilterDefault}
|
||||||
runtime.SetFinalizer(i, (*Image).Dispose)
|
runtime.SetFinalizer(i, (*Image).Dispose)
|
||||||
return i
|
return i
|
||||||
|
@ -80,10 +80,8 @@ type Image struct {
|
|||||||
// screen indicates whether the image is used as an actual screen.
|
// screen indicates whether the image is used as an actual screen.
|
||||||
screen bool
|
screen bool
|
||||||
|
|
||||||
paddingX0 float64
|
framebufferWidth int
|
||||||
paddingY0 float64
|
framebufferHeight int
|
||||||
paddingX1 float64
|
|
||||||
paddingY1 float64
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewImage creates an empty image with the given size.
|
// 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.
|
// 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{
|
i := &Image{
|
||||||
image: graphics.NewScreenFramebufferImage(width, height),
|
image: graphics.NewScreenFramebufferImage(width, height),
|
||||||
volatile: true,
|
volatile: true,
|
||||||
screen: true,
|
screen: true,
|
||||||
paddingX0: paddingX0,
|
framebufferWidth: framebufferWidth,
|
||||||
paddingY0: paddingY0,
|
framebufferHeight: framebufferHeight,
|
||||||
paddingX1: paddingX1,
|
|
||||||
paddingY1: paddingY1,
|
|
||||||
}
|
}
|
||||||
theImages.add(i)
|
theImages.add(i)
|
||||||
runtime.SetFinalizer(i, (*Image).Dispose)
|
runtime.SetFinalizer(i, (*Image).Dispose)
|
||||||
@ -170,11 +166,10 @@ func (i *Image) clearIfVolatile() {
|
|||||||
panic("not reached")
|
panic("not reached")
|
||||||
}
|
}
|
||||||
|
|
||||||
w, h := i.image.Size()
|
|
||||||
x0 := float32(0)
|
x0 := float32(0)
|
||||||
y0 := float32(0)
|
y0 := float32(0)
|
||||||
x1 := float32(w) + float32(i.paddingX0+i.paddingX1)
|
x1 := float32(i.framebufferWidth)
|
||||||
y1 := float32(h) + float32(i.paddingY0+i.paddingY1)
|
y1 := float32(i.framebufferHeight)
|
||||||
// For the rule of values, see vertices.go.
|
// For the rule of values, see vertices.go.
|
||||||
clearVertices := []float32{
|
clearVertices := []float32{
|
||||||
x0, y0, 0, 0, 1, 1,
|
x0, y0, 0, 0, 1, 1,
|
||||||
|
Loading…
Reference in New Issue
Block a user