mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2025-01-26 02:42:02 +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 {
|
if c.offscreen != nil {
|
||||||
_ = c.offscreen.Dispose()
|
_ = 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)
|
// Round up the screensize not to cause glitches e.g. on Xperia (#622)
|
||||||
w := int(math.Ceil(float64(screenWidth) * screenScale))
|
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
|
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.
|
// A volatile image is always cleared at the start of a frame.
|
||||||
//
|
//
|
||||||
// This is suitable for offscreen images that pixels are changed often.
|
// 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.
|
// 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.
|
// 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.
|
// When the image is disposed, makeVolatile does nothing.
|
||||||
func newVolatileImage(width, height int) *Image {
|
func (i *Image) makeVolatile() {
|
||||||
s := shareable.NewImage(width, height)
|
if i.isDisposed() {
|
||||||
s.MakeVolatile()
|
return
|
||||||
i := &Image{
|
|
||||||
mipmap: newMipmap(s),
|
|
||||||
}
|
}
|
||||||
i.addr = i
|
i.mipmap.orig.MakeVolatile()
|
||||||
runtime.SetFinalizer(i, (*Image).Dispose)
|
i.disposeMipmaps()
|
||||||
return i
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewImageFromImage creates a new image with the given image (source).
|
// NewImageFromImage creates a new image with the given image (source).
|
||||||
|
Loading…
Reference in New Issue
Block a user