optimize Drawer.Dirty (defer the hard part until drawing)

This commit is contained in:
faiface 2017-05-02 22:46:27 +02:00
parent ec4f5e3663
commit a9d735dafe
1 changed files with 9 additions and 3 deletions

View File

@ -27,6 +27,7 @@ type Drawer struct {
tris map[Target]TargetTriangles
clean map[Target]bool
pics map[targetPicturePair]TargetPicture
dirty bool
inited bool
}
@ -49,9 +50,7 @@ func (d *Drawer) lazyInit() {
func (d *Drawer) Dirty() {
d.lazyInit()
for t := range d.clean {
d.clean[t] = false
}
d.dirty = true
}
// Draw efficiently draws Triangles with Picture onto the provided Target.
@ -61,6 +60,13 @@ func (d *Drawer) Dirty() {
func (d *Drawer) Draw(t Target) {
d.lazyInit()
if d.dirty {
for t := range d.clean {
d.clean[t] = false
}
d.dirty = false
}
if d.Triangles == nil {
return
}