mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-12-25 03:08:54 +01:00
internal/atlas: bug fix: too aggressive counting up destinationCount
Closes #2586
This commit is contained in:
parent
7c10e48afd
commit
1c09ec5e44
@ -220,11 +220,9 @@ type Image struct {
|
|||||||
// WritePixels doesn't affect this value since WritePixels can be done on images on an atlas.
|
// WritePixels doesn't affect this value since WritePixels can be done on images on an atlas.
|
||||||
usedAsSourceCount int
|
usedAsSourceCount int
|
||||||
|
|
||||||
// destinationCount represents how many times an image on an atlas is used as a rendering destination at DrawTriangles.
|
// destinationCount represents how many times an image switches its backend when the image is used
|
||||||
|
// as a rendering destination at DrawTriangles.
|
||||||
// destinationCount affects the calculation when to put the image onto a texture atlas again.
|
// destinationCount affects the calculation when to put the image onto a texture atlas again.
|
||||||
//
|
|
||||||
// The current counting way is derived from the old implementation in which a destination image was always isolated
|
|
||||||
// e.g. not on an atlas. This might have to be revisited.
|
|
||||||
destinationCount int
|
destinationCount int
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -281,8 +279,6 @@ func (i *Image) ensureIsolatedFromSource(backends []*backend) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
i.destinationCount++
|
|
||||||
|
|
||||||
// Check if i has the same backend as the given backends.
|
// Check if i has the same backend as the given backends.
|
||||||
var needsIsolation bool
|
var needsIsolation bool
|
||||||
for _, b := range backends {
|
for _, b := range backends {
|
||||||
@ -322,6 +318,10 @@ func (i *Image) ensureIsolatedFromSource(backends []*backend) {
|
|||||||
delete(theSourceBackendsForOneFrame, origBackend)
|
delete(theSourceBackendsForOneFrame, origBackend)
|
||||||
|
|
||||||
newI.moveTo(i)
|
newI.moveTo(i)
|
||||||
|
|
||||||
|
// Count up only when the backend is switched. (#2586).
|
||||||
|
// This counting up must be done after moveTo.
|
||||||
|
i.destinationCount++
|
||||||
}
|
}
|
||||||
|
|
||||||
func (i *Image) putOnSourceBackend(graphicsDriver graphicsdriver.Graphics) error {
|
func (i *Image) putOnSourceBackend(graphicsDriver graphicsdriver.Graphics) error {
|
||||||
|
@ -213,6 +213,14 @@ func TestReputOnSourceBackend(t *testing.T) {
|
|||||||
t.Errorf("got: %v, want: %v", got, want)
|
t.Errorf("got: %v, want: %v", got, want)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// Finally, img1 is on a source backend.
|
||||||
|
if err := atlas.PutImagesOnSourceBackendForTesting(ui.GraphicsDriverForTesting()); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
img0.DrawTriangles([graphics.ShaderImageCount]*atlas.Image{img1}, vs, is, graphicsdriver.BlendCopy, dr, graphicsdriver.Region{}, [graphics.ShaderImageCount - 1][2]float32{}, atlas.NearestFilterShader, nil, false)
|
||||||
|
if got, want := img1.IsOnSourceBackendForTesting(), true; got != want {
|
||||||
|
t.Errorf("got: %v, want: %v", got, want)
|
||||||
|
}
|
||||||
if err := atlas.PutImagesOnSourceBackendForTesting(ui.GraphicsDriverForTesting()); err != nil {
|
if err := atlas.PutImagesOnSourceBackendForTesting(ui.GraphicsDriverForTesting()); err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user