graphicscommand: Bug fix: Use graphics.InternalImageSize before specifying the size

Fixes #887
This commit is contained in:
Hajime Hoshi 2019-06-25 22:47:34 +09:00
parent 26296993f8
commit 7e0dee0730
2 changed files with 36 additions and 1 deletions

View File

@ -154,7 +154,7 @@ func (q *commandQueue) EnqueueDrawTrianglesCommand(dst, src *Image, vertices []f
}
n := len(vertices) / graphics.VertexFloatNum
q.appendVertices(vertices, float32(dst.width), float32(dst.height))
q.appendVertices(vertices, float32(graphics.InternalImageSize(dst.width)), float32(graphics.InternalImageSize(dst.height)))
q.appendIndices(indices, uint16(q.nextIndex))
q.nextIndex += n
q.tmpNumIndices += len(indices)

View File

@ -295,4 +295,39 @@ func TestReplacePixelsAfterDrawTriangles(t *testing.T) {
}
}
// Issue #887
func TestSmallImages(t *testing.T) {
const w, h = 4, 8
src := NewImage(w, h)
defer src.Dispose()
dst := NewImage(w, h)
defer dst.Dispose()
pix := make([]byte, 4*w*h)
for i := 0; i < w*h; i++ {
pix[4*i] = 0xff
pix[4*i+1] = 0xff
pix[4*i+2] = 0xff
pix[4*i+3] = 0xff
}
src.ReplacePixels(pix)
vs := make([]float32, 4*graphics.VertexFloatNum)
graphics.PutQuadVertices(vs, src, 0, 0, w, h, 1, 0, 0, 1, 0, 0, 1, 1, 1, 1)
is := graphics.QuadIndices()
dst.DrawTriangles(src, vs, is, nil, graphics.CompositeModeSourceOver, graphics.FilterNearest, graphics.AddressClampToZero)
for j := 0; j < h; j++ {
for i := 0; i < w; i++ {
r, _, _, a := dst.At(i, j)
if got, want := r, byte(0xff); got != want {
t.Errorf("At(%d, %d) red: got: %d, want: %d", i, j, got, want)
}
if got, want := a, byte(0xff); got != want {
t.Errorf("At(%d, %d) alpha: got: %d, want: %d", i, j, got, want)
}
}
}
}
// TODO: Add tests to extend shareable image out of the main loop