mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-11-12 22:17:26 +01:00
restorable: Remove merging commands for code simplicity
This commit is contained in:
parent
03079ba067
commit
2e5e7e6e24
@ -27,30 +27,12 @@ import (
|
|||||||
// drawImageHistoryItem is an item for history of draw-image commands.
|
// drawImageHistoryItem is an item for history of draw-image commands.
|
||||||
type drawImageHistoryItem struct {
|
type drawImageHistoryItem struct {
|
||||||
image *Image
|
image *Image
|
||||||
vertices [][]float32
|
vertices []float32
|
||||||
colorm *affine.ColorM
|
colorm *affine.ColorM
|
||||||
mode opengl.CompositeMode
|
mode opengl.CompositeMode
|
||||||
filter graphics.Filter
|
filter graphics.Filter
|
||||||
}
|
}
|
||||||
|
|
||||||
// canMerge returns a boolean value indicating whether the drawImageHistoryItem d
|
|
||||||
// can be merged with the given conditions.
|
|
||||||
func (d *drawImageHistoryItem) canMerge(image *Image, colorm *affine.ColorM, mode opengl.CompositeMode, filter graphics.Filter) bool {
|
|
||||||
if d.image != image {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
if !d.colorm.Equals(colorm) {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
if d.mode != mode {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
if d.filter != filter {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
|
|
||||||
// Image represents an image that can be restored when GL context is lost.
|
// Image represents an image that can be restored when GL context is lost.
|
||||||
type Image struct {
|
type Image struct {
|
||||||
image *graphics.Image
|
image *graphics.Image
|
||||||
@ -224,13 +206,6 @@ func (i *Image) appendDrawImageHistory(image *Image, vertices []float32, colorm
|
|||||||
if i.stale || i.volatile || i.screen {
|
if i.stale || i.volatile || i.screen {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if len(i.drawImageHistory) > 0 {
|
|
||||||
last := i.drawImageHistory[len(i.drawImageHistory)-1]
|
|
||||||
if last.canMerge(image, colorm, mode, filter) {
|
|
||||||
last.vertices = append(last.vertices, vertices)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}
|
|
||||||
const maxDrawImageHistoryNum = 100
|
const maxDrawImageHistoryNum = 100
|
||||||
if len(i.drawImageHistory)+1 > maxDrawImageHistoryNum {
|
if len(i.drawImageHistory)+1 > maxDrawImageHistoryNum {
|
||||||
i.makeStale()
|
i.makeStale()
|
||||||
@ -240,7 +215,7 @@ func (i *Image) appendDrawImageHistory(image *Image, vertices []float32, colorm
|
|||||||
// So we don't have to care if image is stale or not here.
|
// So we don't have to care if image is stale or not here.
|
||||||
item := &drawImageHistoryItem{
|
item := &drawImageHistoryItem{
|
||||||
image: image,
|
image: image,
|
||||||
vertices: [][]float32{vertices},
|
vertices: vertices,
|
||||||
colorm: colorm,
|
colorm: colorm,
|
||||||
mode: mode,
|
mode: mode,
|
||||||
filter: filter,
|
filter: filter,
|
||||||
@ -375,9 +350,7 @@ func (i *Image) restore() error {
|
|||||||
if c.image.hasDependency() {
|
if c.image.hasDependency() {
|
||||||
panic("not reached")
|
panic("not reached")
|
||||||
}
|
}
|
||||||
for _, v := range c.vertices {
|
gimg.DrawImage(c.image.image, c.vertices, quadIndices, c.colorm, c.mode, c.filter)
|
||||||
gimg.DrawImage(c.image.image, v, quadIndices, c.colorm, c.mode, c.filter)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
i.image = gimg
|
i.image = gimg
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user