optimize Drawer.Dirty (defer the hard part until drawing)
This commit is contained in:
parent
f7dad2f3c2
commit
5303ec5648
12
drawer.go
12
drawer.go
|
@ -27,6 +27,7 @@ type Drawer struct {
|
||||||
tris map[Target]TargetTriangles
|
tris map[Target]TargetTriangles
|
||||||
clean map[Target]bool
|
clean map[Target]bool
|
||||||
pics map[targetPicturePair]TargetPicture
|
pics map[targetPicturePair]TargetPicture
|
||||||
|
dirty bool
|
||||||
inited bool
|
inited bool
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -49,9 +50,7 @@ func (d *Drawer) lazyInit() {
|
||||||
func (d *Drawer) Dirty() {
|
func (d *Drawer) Dirty() {
|
||||||
d.lazyInit()
|
d.lazyInit()
|
||||||
|
|
||||||
for t := range d.clean {
|
d.dirty = true
|
||||||
d.clean[t] = false
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Draw efficiently draws Triangles with Picture onto the provided Target.
|
// Draw efficiently draws Triangles with Picture onto the provided Target.
|
||||||
|
@ -61,6 +60,13 @@ func (d *Drawer) Dirty() {
|
||||||
func (d *Drawer) Draw(t Target) {
|
func (d *Drawer) Draw(t Target) {
|
||||||
d.lazyInit()
|
d.lazyInit()
|
||||||
|
|
||||||
|
if d.dirty {
|
||||||
|
for t := range d.clean {
|
||||||
|
d.clean[t] = false
|
||||||
|
}
|
||||||
|
d.dirty = false
|
||||||
|
}
|
||||||
|
|
||||||
if d.Triangles == nil {
|
if d.Triangles == nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue