mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2025-01-26 02:42:02 +01:00
internal/processtest: improve test issue2815
WritePixels for 1x1 image is optimized at internal/ui, and Ebitengine doesn't read pixels from GPU in this case. Enlarge the tested image, and use DrawImage to ensure to invalidate the internal cache. Updates #2815
This commit is contained in:
parent
e80e981bf5
commit
39688dd27d
7
internal/processtest/testdata/issue2815.go
vendored
7
internal/processtest/testdata/issue2815.go
vendored
@ -37,14 +37,17 @@ func (g *Game) Update() error {
|
||||
g.end0 = make(chan struct{})
|
||||
g.end1 = make(chan struct{})
|
||||
g.errCh = make(chan error)
|
||||
img := ebiten.NewImage(1, 1)
|
||||
img.WritePixels([]byte{0xff, 0xff, 0xff, 0xff})
|
||||
src := ebiten.NewImage(1, 2)
|
||||
src.WritePixels([]byte{0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff})
|
||||
img := ebiten.NewImage(1, 2)
|
||||
go func() {
|
||||
t := time.Tick(time.Microsecond)
|
||||
loop:
|
||||
for {
|
||||
select {
|
||||
case <-t:
|
||||
// Call DrawImage every time in order to invalidate the internal pixels cache.
|
||||
img.DrawImage(src, nil)
|
||||
got := img.At(0, 0).(color.RGBA)
|
||||
want := color.RGBA{0xff, 0xff, 0xff, 0xff}
|
||||
if got != want {
|
||||
|
@ -130,15 +130,16 @@ func (u *UserInterface) readPixels(mipmap *mipmap.Mipmap, pixels []byte, region
|
||||
if !ok {
|
||||
ch := make(chan error)
|
||||
u.context.appendDeferredFunc(func() {
|
||||
defer close(ch)
|
||||
ok, err := mipmap.ReadPixels(u.graphicsDriver, pixels, region)
|
||||
if err != nil {
|
||||
ch <- err
|
||||
return
|
||||
}
|
||||
if !ok {
|
||||
// This never reaches since this function must be called in a frame.
|
||||
panic("ui: ReadPixels unexpectedly failed")
|
||||
}
|
||||
if err != nil {
|
||||
ch <- err
|
||||
}
|
||||
close(ch)
|
||||
})
|
||||
|
||||
// If this function is called from the game (Update/Draw) goroutine in between two frames,
|
||||
|
Loading…
Reference in New Issue
Block a user