draw optimizations

This commit is contained in:
IliaDenisov
2026-03-08 23:30:11 +02:00
parent fdcbb5d6f4
commit ac35360d60
18 changed files with 875 additions and 566 deletions
@@ -0,0 +1,53 @@
package world
import (
"image/color"
"testing"
"github.com/fogleman/gg"
)
func BenchmarkDrawPlanSinglePass_DrawItemsReuse(b *testing.B) {
w := NewWorld(600, 600)
// Make grid + index available.
w.IndexOnViewportChange(1000, 700, 1.0)
// Add enough objects so tiles have candidates.
for i := range 2000 {
_, _ = w.AddPoint(float64(i%600), float64((i*7)%600))
}
for i := range 500 {
_, _ = w.AddCircle(float64((i*11)%600), float64((i*13)%600), 5.0)
}
w.Reindex()
params := RenderParams{
ViewportWidthPx: 1000,
ViewportHeightPx: 700,
MarginXPx: 250,
MarginYPx: 175,
CameraXWorldFp: 300 * SCALE,
CameraYWorldFp: 300 * SCALE,
CameraZoom: 1.0,
Options: &RenderOptions{
BackgroundColor: color.RGBA{A: 255},
},
}
plan, err := w.buildRenderPlanStageA(params)
if err != nil {
b.Fatalf("build plan: %v", err)
}
dc := gg.NewContext(params.CanvasWidthPx(), params.CanvasHeightPx())
drawer := &GGDrawer{DC: dc}
b.ReportAllocs()
b.ResetTimer()
for i := 0; i < b.N; i++ {
// We don't clear here; we only measure the draw loop overhead.
w.drawPlanSinglePass(drawer, plan, true, drawPlanSinglePassClipEnabled, false)
}
}