mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2025-02-03 22:44:28 +01:00
restorable: Specify indices from restorable package
This commit is contained in:
parent
2853895e6b
commit
c782380a1c
@ -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)
|
||||
|
@ -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)
|
||||
}
|
||||
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)
|
||||
vertices = next
|
||||
}
|
||||
}
|
||||
|
||||
func (i *Image) Pixels() ([]byte, error) {
|
||||
|
@ -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
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user