diff --git a/tools/benchmark/sprite_bench.go b/tools/benchmark/sprite_bench.go index 4ca926e..02a6490 100644 --- a/tools/benchmark/sprite_bench.go +++ b/tools/benchmark/sprite_bench.go @@ -50,6 +50,7 @@ func newSpriteStatic(win *opengl.Window) (Benchmark, error) { width := bounds.W() height := bounds.H() rows, cols := 32, 32 + benchmark := &spriteStatic{ sprite: sprite, rows: rows, @@ -59,51 +60,36 @@ func newSpriteStatic(win *opengl.Window) (Benchmark, error) { return benchmark, nil } -type spriteStatic struct { - sprite *pixel.Sprite - rows, cols int - cell pixel.Vec -} - -func (ss *spriteStatic) Step(win *opengl.Window) { - win.Clear(backgroundColor) - spriteGrid(ss.sprite, win, ss.rows, ss.cols, ss.cell) -} - func newSpriteStaticBatched(win *opengl.Window) (Benchmark, error) { - sprite, err := loadSprite(logoPath, logoFrame) + benchmark, err := newSpriteStatic(win) if err != nil { return nil, err } - - bounds := win.Bounds() - width := bounds.W() - height := bounds.H() - rows, cols := 32, 32 - - benchmark := &spriteStaticBatched{ - sprite: sprite, - batch: pixel.NewBatch(&pixel.TrianglesData{}, sprite.Picture()), - rows: rows, - cols: cols, - cell: gridCell(width, height, rows, cols), - } - - return benchmark, nil + ss := benchmark.(*spriteStatic) + ss.batch = pixel.NewBatch(&pixel.TrianglesData{}, ss.sprite.Picture()) + return ss, nil } -type spriteStaticBatched struct { +type spriteStatic struct { sprite *pixel.Sprite - batch *pixel.Batch rows, cols int cell pixel.Vec + batch *pixel.Batch } -func (ssb *spriteStaticBatched) Step(win *opengl.Window) { +func (ss *spriteStatic) Step(win *opengl.Window) { win.Clear(backgroundColor) - ssb.batch.Clear() - spriteGrid(ssb.sprite, ssb.batch, ssb.rows, ssb.cols, ssb.cell) - ssb.batch.Draw(win) + var target pixel.Target + if ss.batch != nil { + ss.batch.Clear() + target = ss.batch + } else { + target = win + } + spriteGrid(ss.sprite, target, ss.rows, ss.cols, ss.cell) + if ss.batch != nil { + ss.batch.Draw(win) + } } func spriteGrid(sprite *pixel.Sprite, target pixel.Target, rows, cols int, cell pixel.Vec) {