mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2025-01-27 03:02:49 +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.end0 = make(chan struct{})
|
||||||
g.end1 = make(chan struct{})
|
g.end1 = make(chan struct{})
|
||||||
g.errCh = make(chan error)
|
g.errCh = make(chan error)
|
||||||
img := ebiten.NewImage(1, 1)
|
src := ebiten.NewImage(1, 2)
|
||||||
img.WritePixels([]byte{0xff, 0xff, 0xff, 0xff})
|
src.WritePixels([]byte{0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff})
|
||||||
|
img := ebiten.NewImage(1, 2)
|
||||||
go func() {
|
go func() {
|
||||||
t := time.Tick(time.Microsecond)
|
t := time.Tick(time.Microsecond)
|
||||||
loop:
|
loop:
|
||||||
for {
|
for {
|
||||||
select {
|
select {
|
||||||
case <-t:
|
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)
|
got := img.At(0, 0).(color.RGBA)
|
||||||
want := color.RGBA{0xff, 0xff, 0xff, 0xff}
|
want := color.RGBA{0xff, 0xff, 0xff, 0xff}
|
||||||
if got != want {
|
if got != want {
|
||||||
|
@ -130,15 +130,16 @@ func (u *UserInterface) readPixels(mipmap *mipmap.Mipmap, pixels []byte, region
|
|||||||
if !ok {
|
if !ok {
|
||||||
ch := make(chan error)
|
ch := make(chan error)
|
||||||
u.context.appendDeferredFunc(func() {
|
u.context.appendDeferredFunc(func() {
|
||||||
|
defer close(ch)
|
||||||
ok, err := mipmap.ReadPixels(u.graphicsDriver, pixels, region)
|
ok, err := mipmap.ReadPixels(u.graphicsDriver, pixels, region)
|
||||||
|
if err != nil {
|
||||||
|
ch <- err
|
||||||
|
return
|
||||||
|
}
|
||||||
if !ok {
|
if !ok {
|
||||||
// This never reaches since this function must be called in a frame.
|
// This never reaches since this function must be called in a frame.
|
||||||
panic("ui: ReadPixels unexpectedly failed")
|
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,
|
// If this function is called from the game (Update/Draw) goroutine in between two frames,
|
||||||
|
Loading…
Reference in New Issue
Block a user