mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2025-01-11 19:48:54 +01:00
internal/restorable: bug fix: no pixels were read only with DrawTriangles
Closes #2324
This commit is contained in:
parent
0f00eac24c
commit
6179158812
@ -491,7 +491,11 @@ func (i *Image) makeStaleIfDependingOnShader(shader *Shader) {
|
|||||||
// readPixelsFromGPU reads the pixels from GPU and resolves the image's 'stale' state.
|
// readPixelsFromGPU reads the pixels from GPU and resolves the image's 'stale' state.
|
||||||
func (i *Image) readPixelsFromGPU(graphicsDriver graphicsdriver.Graphics) error {
|
func (i *Image) readPixelsFromGPU(graphicsDriver graphicsdriver.Graphics) error {
|
||||||
i.basePixels = Pixels{}
|
i.basePixels = Pixels{}
|
||||||
if r := i.staleRegion; !r.Empty() {
|
r := i.staleRegion
|
||||||
|
if len(i.drawTrianglesHistory) > 0 {
|
||||||
|
r = image.Rect(0, 0, i.width, i.height)
|
||||||
|
}
|
||||||
|
if !r.Empty() {
|
||||||
pix := make([]byte, 4*r.Dx()*r.Dy())
|
pix := make([]byte, 4*r.Dx()*r.Dy())
|
||||||
if err := i.image.ReadPixels(graphicsDriver, pix, r.Min.X, r.Min.Y, r.Dx(), r.Dy()); err != nil {
|
if err := i.image.ReadPixels(graphicsDriver, pix, r.Min.X, r.Min.Y, r.Dx(), r.Dy()); err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -1073,3 +1073,30 @@ func TestOverlappedPixels(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Issue #2324
|
||||||
|
func TestDrawTrianglesAndReadPixels(t *testing.T) {
|
||||||
|
const w, h = 1, 1
|
||||||
|
src := restorable.NewImage(w, h, restorable.ImageTypeRegular)
|
||||||
|
dst := restorable.NewImage(w, h, restorable.ImageTypeRegular)
|
||||||
|
|
||||||
|
src.WritePixels([]byte{0x80, 0x80, 0x80, 0x80}, 0, 0, 1, 1)
|
||||||
|
|
||||||
|
vs := quadVertices(src, w, h, 0, 0)
|
||||||
|
is := graphics.QuadIndices()
|
||||||
|
dr := graphicsdriver.Region{
|
||||||
|
X: 0,
|
||||||
|
Y: 0,
|
||||||
|
Width: w,
|
||||||
|
Height: h,
|
||||||
|
}
|
||||||
|
dst.DrawTriangles([graphics.ShaderImageCount]*restorable.Image{src}, [graphics.ShaderImageCount - 1][2]float32{}, vs, is, affine.ColorMIdentity{}, graphicsdriver.CompositeModeSourceOver, graphicsdriver.FilterNearest, graphicsdriver.AddressUnsafe, dr, graphicsdriver.Region{}, nil, nil, false)
|
||||||
|
|
||||||
|
pix := make([]byte, 4*w*h)
|
||||||
|
if err := dst.ReadPixels(ui.GraphicsDriverForTesting(), pix, 0, 0, w, h); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
if got, want := (color.RGBA{pix[0], pix[1], pix[2], pix[3]}), (color.RGBA{0x80, 0x80, 0x80, 0x80}); !sameColors(got, want, 1) {
|
||||||
|
t.Errorf("got: %v, want: %v", got, want)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user