graphics: Bug fix: render source might not be initialized

This commit is contained in:
Hajime Hoshi 2018-12-01 20:44:06 +01:00
parent 3f75da5f35
commit e537cb2c27
2 changed files with 45 additions and 0 deletions

View File

@ -1095,3 +1095,33 @@ func TestImageSubImageSize(t *testing.T) {
t.Errorf("got: %v, want: %v", got, want) t.Errorf("got: %v, want: %v", got, want)
} }
} }
func TestImageDrawImmediately(t *testing.T) {
const w, h = 16, 16
img0, _ := NewImage(w, h, FilterDefault)
img1, _ := NewImage(w, h, FilterDefault)
// Do not manipulate img0 here.
img0.Fill(color.RGBA{0xff, 0, 0, 0xff})
for j := 0; j < h; j++ {
for i := 0; i < w; i++ {
got := img0.At(i, j).(color.RGBA)
want := color.RGBA{0xff, 0, 0, 0xff}
if got != want {
t.Errorf("img0.At(%d, %d): got %v, want: %v", i, j, got, want)
}
}
}
img0.DrawImage(img1, nil)
for j := 0; j < h; j++ {
for i := 0; i < w; i++ {
got := img0.At(i, j).(color.RGBA)
want := color.RGBA{0xff, 0, 0, 0xff}
if got != want {
t.Errorf("img0.At(%d, %d): got %v, want: %v", i, j, got, want)
}
}
}
}

View File

@ -143,6 +143,21 @@ func (i *Image) DrawImage(src *Image, vertices []float32, indices []uint16, clr
default: default:
panic("not reached") panic("not reached")
} }
switch src.state {
case imageStateInit:
src.clearByReplacingPixels()
case imageStateReplacePixelsOnly:
// Do nothing
// TODO: Check the region.
case imageStateDrawable:
// Do nothing
case imageStateScreen:
panic("not reached")
default:
panic("not reached")
}
theCommandQueue.EnqueueDrawImageCommand(i, src, vertices, indices, clr, mode, filter) theCommandQueue.EnqueueDrawImageCommand(i, src, vertices, indices, clr, mode, filter)
} }