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

@ -218,11 +218,12 @@ func init() {
// Image is a renctangle pixel set that might be on an atlas.
type Image struct {
width int
height int
disposed bool
volatile bool
screen bool
width int
height int
disposed bool
independent bool
volatile bool
screen bool
backend *backend
@ -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) {
i.volatile = volatile
if i.backend == nil {
@ -709,6 +714,9 @@ func (i *Image) canBePutOnAtlas() bool {
if minSize == 0 || maxSize == 0 {
panic("atlas: minSize or maxSize must be initialized")
}
if i.independent {
return false
}
if i.volatile {
return false
}

View File

@ -65,6 +65,18 @@ func (i *Image) initialize(width, height int) {
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) {
if maybeCanAddDelayedCommand() {
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) {
m.volatile = volatile
if m.volatile {

View File

@ -93,6 +93,12 @@ func (c *uiContext) updateOffscreen() {
if c.offscreen == nil {
c.offscreen = NewImage(ow, oh)
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)
}
}