internal/atlas: bug fix: the offscreen must be an independent image

Closes #1938
This commit is contained in:
Hajime Hoshi 2022-01-08 23:21:38 +09:00
parent f51d691d87
commit 0680ca413d
4 changed files with 35 additions and 5 deletions

View File

@ -221,6 +221,7 @@ type Image struct {
width int width int
height int height int
disposed bool disposed bool
independent bool
volatile bool volatile bool
screen bool screen bool
@ -694,6 +695,10 @@ func NewImage(width, height int) *Image {
} }
} }
func (i *Image) SetIndependent(independent bool) {
i.independent = independent
}
func (i *Image) SetVolatile(volatile bool) { func (i *Image) SetVolatile(volatile bool) {
i.volatile = volatile i.volatile = volatile
if i.backend == nil { if i.backend == nil {
@ -709,6 +714,9 @@ func (i *Image) canBePutOnAtlas() bool {
if minSize == 0 || maxSize == 0 { if minSize == 0 || maxSize == 0 {
panic("atlas: minSize or maxSize must be initialized") panic("atlas: minSize or maxSize must be initialized")
} }
if i.independent {
return false
}
if i.volatile { if i.volatile {
return false return false
} }

View File

@ -65,6 +65,18 @@ func (i *Image) initialize(width, height int) {
i.height = height i.height = height
} }
func (i *Image) SetIndependent(volatile bool) {
if maybeCanAddDelayedCommand() {
if tryAddDelayedCommand(func() error {
i.SetIndependent(volatile)
return nil
}) {
return
}
}
i.img.SetIndependent(volatile)
}
func (i *Image) SetVolatile(volatile bool) { func (i *Image) SetVolatile(volatile bool) {
if maybeCanAddDelayedCommand() { if maybeCanAddDelayedCommand() {
if tryAddDelayedCommand(func() error { if tryAddDelayedCommand(func() error {

View File

@ -59,6 +59,10 @@ func NewScreenFramebufferMipmap(width, height int) *Mipmap {
} }
} }
func (m *Mipmap) SetIndependent(volatile bool) {
m.orig.SetIndependent(volatile)
}
func (m *Mipmap) SetVolatile(volatile bool) { func (m *Mipmap) SetVolatile(volatile bool) {
m.volatile = volatile m.volatile = volatile
if m.volatile { if m.volatile {

View File

@ -93,6 +93,12 @@ func (c *uiContext) updateOffscreen() {
if c.offscreen == nil { if c.offscreen == nil {
c.offscreen = NewImage(ow, oh) c.offscreen = NewImage(ow, oh)
c.offscreen.mipmap.SetVolatile(IsScreenClearedEveryFrame()) c.offscreen.mipmap.SetVolatile(IsScreenClearedEveryFrame())
// Keep the offscreen an independent image from an atlas (#1938).
// 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,
// and the shader program unexpectedly picks the pixel on the edges.
c.offscreen.mipmap.SetIndependent(true)
} }
} }