From c782380a1c8d10639f3c9e52ddb67cb14e125db4 Mon Sep 17 00:00:00 2001 From: Hajime Hoshi Date: Sun, 10 Jun 2018 18:17:58 +0900 Subject: [PATCH] restorable: Specify indices from restorable package --- internal/graphics/command.go | 2 +- internal/graphics/image.go | 24 ++---------------------- internal/restorable/image.go | 10 +++++++--- 3 files changed, 10 insertions(+), 26 deletions(-) diff --git a/internal/graphics/command.go b/internal/graphics/command.go index 9ed70f2cb..39b29ef52 100644 --- a/internal/graphics/command.go +++ b/internal/graphics/command.go @@ -126,7 +126,7 @@ func (q *commandQueue) EnqueueDrawImageCommand(dst, src *Image, vertices []float q.appendVertices(vertices) q.appendIndices(indices, uint16(q.nextIndex)) - q.nextIndex += len(vertices) * opengl.Float.SizeInBytes() / theArrayBufferLayout.totalBytes() + q.nextIndex += len(vertices) * opengl.Float.SizeInBytes() / VertexSizeInBytes() q.tmpNumIndices += len(indices) q.doEnqueueDrawImageCommand(dst, src, len(vertices), len(indices), color, mode, filter, split) diff --git a/internal/graphics/image.go b/internal/graphics/image.go index c8a0b940e..7ab2dd773 100644 --- a/internal/graphics/image.go +++ b/internal/graphics/image.go @@ -86,28 +86,8 @@ func (i *Image) Size() (int, int) { return i.width, i.height } -func (i *Image) DrawImage(src *Image, vertices []float32, clr *affine.ColorM, mode opengl.CompositeMode, filter Filter) { - for len(vertices) > 0 { - var next []float32 - nq := len(vertices) * opengl.Float.SizeInBytes() / VertexSizeInBytes() / 4 - if nq > maxQuads { - nq = maxQuads - i := 4 * nq * VertexSizeInBytes() / opengl.Float.SizeInBytes() - next = vertices[i:] - vertices = vertices[:i] - } - indices := make([]uint16, 6*nq) - for i := 0; i < nq; i++ { - indices[6*i+0] = uint16(4*i + 0) - indices[6*i+1] = uint16(4*i + 1) - indices[6*i+2] = uint16(4*i + 2) - indices[6*i+3] = uint16(4*i + 1) - indices[6*i+4] = uint16(4*i + 2) - indices[6*i+5] = uint16(4*i + 3) - } - theCommandQueue.EnqueueDrawImageCommand(i, src, vertices, indices, clr, mode, filter) - vertices = next - } +func (i *Image) DrawImage(src *Image, vertices []float32, indices []uint16, clr *affine.ColorM, mode opengl.CompositeMode, filter Filter) { + theCommandQueue.EnqueueDrawImageCommand(i, src, vertices, indices, clr, mode, filter) } func (i *Image) Pixels() ([]byte, error) { diff --git a/internal/restorable/image.go b/internal/restorable/image.go index bfb605d85..b9c7c8925 100644 --- a/internal/restorable/image.go +++ b/internal/restorable/image.go @@ -134,6 +134,10 @@ func (i *Image) makeStale() { // the former image can be restored from the latest state of the latter image. } +var ( + quadIndices = []uint16{0, 1, 2, 1, 2, 3} +) + // ReplacePixels replaces the image pixels with the given pixels slice. // // If pixels is nil, ReplacePixels clears the specified reagion. @@ -162,7 +166,7 @@ func (i *Image) ReplacePixels(pixels []byte, x, y, width, height int) { geom = geom.Translate(float64(x), float64(y)) colorm := (*affine.ColorM)(nil).Scale(0, 0, 0, 0) vs := vertices(w, h, 0, 0, w, h, geom) - i.image.DrawImage(dummyImage.image, vs, colorm, opengl.CompositeModeCopy, graphics.FilterNearest) + i.image.DrawImage(dummyImage.image, vs, quadIndices, colorm, opengl.CompositeModeCopy, graphics.FilterNearest) } if x == 0 && y == 0 && width == w && height == h { @@ -212,7 +216,7 @@ func (i *Image) DrawImage(img *Image, sx0, sy0, sx1, sy1 int, geom *affine.GeoM, } else { i.appendDrawImageHistory(img, vs, colorm, mode, filter) } - i.image.DrawImage(img.image, vs, colorm, mode, filter) + i.image.DrawImage(img.image, vs, quadIndices, colorm, mode, filter) } // appendDrawImageHistory appends a draw-image history item to the image. @@ -375,7 +379,7 @@ func (i *Image) restore() error { for _, v := range c.vertices { vs = append(vs, v...) } - gimg.DrawImage(c.image.image, vs, c.colorm, c.mode, c.filter) + gimg.DrawImage(c.image.image, vs, quadIndices, c.colorm, c.mode, c.filter) } i.image = gimg