mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2025-01-12 20:18:59 +01:00
parent
f40798b586
commit
ed09406655
@ -75,7 +75,7 @@ type commandQueue struct {
|
||||
// Rename or fix the program.
|
||||
nvertices int
|
||||
|
||||
dstSizes []size
|
||||
srcSizes []size
|
||||
|
||||
indices []uint16
|
||||
nindices int
|
||||
@ -94,13 +94,13 @@ func (q *commandQueue) appendVertices(vertices []float32, width, height float32)
|
||||
if len(q.vertices) < q.nvertices+len(vertices) {
|
||||
n := q.nvertices + len(vertices) - len(q.vertices)
|
||||
q.vertices = append(q.vertices, make([]float32, n)...)
|
||||
q.dstSizes = append(q.dstSizes, make([]size, n/graphics.VertexFloatNum)...)
|
||||
q.srcSizes = append(q.srcSizes, make([]size, n/graphics.VertexFloatNum)...)
|
||||
}
|
||||
copy(q.vertices[q.nvertices:], vertices)
|
||||
for i := 0; i < len(vertices)/graphics.VertexFloatNum; i++ {
|
||||
idx := q.nvertices/graphics.VertexFloatNum + i
|
||||
q.dstSizes[idx].width = width
|
||||
q.dstSizes[idx].height = height
|
||||
q.srcSizes[idx].width = width
|
||||
q.srcSizes[idx].height = height
|
||||
}
|
||||
q.nvertices += len(vertices)
|
||||
}
|
||||
@ -154,7 +154,7 @@ func (q *commandQueue) EnqueueDrawTrianglesCommand(dst, src *Image, vertices []f
|
||||
}
|
||||
|
||||
n := len(vertices) / graphics.VertexFloatNum
|
||||
q.appendVertices(vertices, float32(graphics.InternalImageSize(dst.width)), float32(graphics.InternalImageSize(dst.height)))
|
||||
q.appendVertices(vertices, float32(graphics.InternalImageSize(src.width)), float32(graphics.InternalImageSize(src.height)))
|
||||
q.appendIndices(indices, uint16(q.nextIndex))
|
||||
q.nextIndex += n
|
||||
q.tmpNumIndices += len(indices)
|
||||
@ -187,7 +187,7 @@ func (q *commandQueue) Flush() {
|
||||
// Adjust texels.
|
||||
const texelAdjustmentFactor = 1.0 / 512.0
|
||||
for i := 0; i < q.nvertices/graphics.VertexFloatNum; i++ {
|
||||
s := q.dstSizes[i]
|
||||
s := q.srcSizes[i]
|
||||
vs[i*graphics.VertexFloatNum+6] -= 1.0 / s.width * texelAdjustmentFactor
|
||||
vs[i*graphics.VertexFloatNum+7] -= 1.0 / s.height * texelAdjustmentFactor
|
||||
}
|
||||
|
@ -331,4 +331,40 @@ func TestSmallImages(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
// Issue #887
|
||||
func TestLongImages(t *testing.T) {
|
||||
const w, h = 1, 6
|
||||
src := NewImage(w, h)
|
||||
defer src.Dispose()
|
||||
dst := NewImage(256, 256)
|
||||
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)
|
||||
|
||||
const scale = 120
|
||||
vs := make([]float32, 4*graphics.VertexFloatNum)
|
||||
graphics.PutQuadVertices(vs, src, 0, 0, w, h, scale, 0, 0, 1, 0, 0, 1, 1, 1, 1)
|
||||
is := graphics.QuadIndices()
|
||||
dst.DrawTriangles(src, vs, is, nil, driver.CompositeModeSourceOver, driver.FilterNearest, driver.AddressClampToZero)
|
||||
|
||||
for j := 0; j < h; j++ {
|
||||
for i := 0; i < w*scale; 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
|
||||
|
Loading…
Reference in New Issue
Block a user