mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-12-25 03:08:54 +01:00
internal/ui: recreate an offscreen image when isScreenClearedEveryFrame is toggled
This is a preparation to remove SetVolatile and SetIsolated in the atlas package.
This commit is contained in:
parent
b30700ac31
commit
d3e3df812a
@ -145,7 +145,18 @@ func (c *context) updateFrameImpl(graphicsDriver graphicsdriver.Graphics, update
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (c *context) drawGame(graphicsDriver graphicsdriver.Graphics) {
|
func (c *context) drawGame(graphicsDriver graphicsdriver.Graphics) {
|
||||||
c.offscreen.mipmap.SetVolatile(theGlobalState.isScreenClearedEveryFrame())
|
if c.offscreen.volatile != theGlobalState.isScreenClearedEveryFrame() {
|
||||||
|
w, h := c.offscreen.width, c.offscreen.height
|
||||||
|
c.offscreen.MarkDisposed()
|
||||||
|
c.offscreen = c.game.NewOffscreenImage(w, h)
|
||||||
|
|
||||||
|
// TODO: Give volatile/isolated property to the constructor.
|
||||||
|
if theGlobalState.isScreenClearedEveryFrame() {
|
||||||
|
c.offscreen.setVolatile(true)
|
||||||
|
} else {
|
||||||
|
c.offscreen.mipmap.SetIsolated(true)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Even though updateCount == 0, the offscreen is cleared and Draw is called.
|
// Even though updateCount == 0, the offscreen is cleared and Draw is called.
|
||||||
// Draw should not update the game state and then the screen should not be updated without Update, but
|
// Draw should not update the game state and then the screen should not be updated without Update, but
|
||||||
@ -245,12 +256,17 @@ func (c *context) layoutGame(outsideWidth, outsideHeight float64, deviceScaleFac
|
|||||||
if c.offscreen == nil {
|
if c.offscreen == nil {
|
||||||
c.offscreen = c.game.NewOffscreenImage(ow, oh)
|
c.offscreen = c.game.NewOffscreenImage(ow, oh)
|
||||||
|
|
||||||
|
// TODO: Give volatile/isolated property to the constructor.
|
||||||
|
if theGlobalState.isScreenClearedEveryFrame() {
|
||||||
|
c.offscreen.setVolatile(true)
|
||||||
|
} else {
|
||||||
// Keep the offscreen an isolated image from an atlas (#1938).
|
// Keep the offscreen an isolated image from an atlas (#1938).
|
||||||
// The shader program for the screen is special and doesn't work well with an image on an atlas.
|
// The shader program for the screen is special and doesn't work well with an image on an atlas.
|
||||||
// An image on an atlas is surrounded by a transparent edge,
|
// An image on an atlas is surrounded by a transparent edge,
|
||||||
// and the shader program unexpectedly picks the pixel on the edges.
|
// and the shader program unexpectedly picks the pixel on the edges.
|
||||||
c.offscreen.mipmap.SetIsolated(true)
|
c.offscreen.mipmap.SetIsolated(true)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return ow, oh
|
return ow, oh
|
||||||
}
|
}
|
||||||
|
@ -33,6 +33,7 @@ type Image struct {
|
|||||||
mipmap *mipmap.Mipmap
|
mipmap *mipmap.Mipmap
|
||||||
width int
|
width int
|
||||||
height int
|
height int
|
||||||
|
volatile bool
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewImage(width, height int) *Image {
|
func NewImage(width, height int) *Image {
|
||||||
@ -51,6 +52,11 @@ func newScreenFramebufferImage(width, height int) *Image {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (i *Image) setVolatile(volatile bool) {
|
||||||
|
i.volatile = volatile
|
||||||
|
i.mipmap.SetVolatile(volatile)
|
||||||
|
}
|
||||||
|
|
||||||
func (i *Image) MarkDisposed() {
|
func (i *Image) MarkDisposed() {
|
||||||
if i.mipmap == nil {
|
if i.mipmap == nil {
|
||||||
return
|
return
|
||||||
|
Loading…
Reference in New Issue
Block a user