mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-11-10 04:57:26 +01:00
graphics: Add makeVolatile instead of newVolatileImage
This commit is contained in:
parent
5fed3d3bed
commit
5990da4844
@ -62,7 +62,8 @@ func (c *graphicsContext) SetSize(screenWidth, screenHeight int, screenScale flo
|
||||
if c.offscreen != nil {
|
||||
_ = c.offscreen.Dispose()
|
||||
}
|
||||
c.offscreen = newVolatileImage(screenWidth, screenHeight)
|
||||
c.offscreen, _ = NewImage(screenWidth, screenHeight, FilterDefault)
|
||||
c.offscreen.makeVolatile()
|
||||
|
||||
// Round up the screensize not to cause glitches e.g. on Xperia (#622)
|
||||
w := int(math.Ceil(float64(screenWidth) * screenScale))
|
||||
|
17
image.go
17
image.go
@ -729,7 +729,7 @@ func NewImage(width, height int, filter Filter) (*Image, error) {
|
||||
return i, nil
|
||||
}
|
||||
|
||||
// newVolatileImage returns an empty 'volatile' image.
|
||||
// makeVolatile makes the image 'volatile'.
|
||||
// A volatile image is always cleared at the start of a frame.
|
||||
//
|
||||
// This is suitable for offscreen images that pixels are changed often.
|
||||
@ -739,16 +739,13 @@ func NewImage(width, height int, filter Filter) (*Image, error) {
|
||||
// On the other hand, pixels in volatile images are not saved.
|
||||
// Saving pixels is an expensive operation, and it is desirable to avoid it if possible.
|
||||
//
|
||||
// If width or height is less than 1 or more than device-dependent maximum size, newVolatileImage panics.
|
||||
func newVolatileImage(width, height int) *Image {
|
||||
s := shareable.NewImage(width, height)
|
||||
s.MakeVolatile()
|
||||
i := &Image{
|
||||
mipmap: newMipmap(s),
|
||||
// When the image is disposed, makeVolatile does nothing.
|
||||
func (i *Image) makeVolatile() {
|
||||
if i.isDisposed() {
|
||||
return
|
||||
}
|
||||
i.addr = i
|
||||
runtime.SetFinalizer(i, (*Image).Dispose)
|
||||
return i
|
||||
i.mipmap.orig.MakeVolatile()
|
||||
i.disposeMipmaps()
|
||||
}
|
||||
|
||||
// NewImageFromImage creates a new image with the given image (source).
|
||||
|
Loading…
Reference in New Issue
Block a user