From 8c2913c2e67a6d5a031f59bbbd887943f4ccfbe5 Mon Sep 17 00:00:00 2001 From: Elias Naur Date: Thu, 26 Aug 2021 12:31:17 +0200 Subject: [PATCH] gpu: tolerate changing maximum dimensions in packer.tryAdd This change allows atlas packer clients to start with large maximum atlas dimensions, then shrink the maximum once the underlying atlas has been allocated. Signed-off-by: Elias Naur --- gpu/pack.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/gpu/pack.go b/gpu/pack.go index abf738c7..bfa77a1a 100644 --- a/gpu/pack.go +++ b/gpu/pack.go @@ -41,7 +41,7 @@ func (p *packer) newPage() { p.sizes = append(p.sizes, image.Point{}) p.spaces = p.spaces[:0] p.spaces = append(p.spaces, image.Rectangle{ - Max: image.Point{X: p.maxDim, Y: p.maxDim}, + Max: image.Point{X: 1e6, Y: 1e6}, }) } @@ -61,9 +61,15 @@ func (p *packer) tryAdd(s image.Point) (placement, bool) { idx := len(p.sizes) - 1 size := p.sizes[idx] if x := space.Min.X + s.X; x > size.X { + if x > p.maxDim { + continue + } size.X = x } if y := space.Min.Y + s.Y; y > size.Y { + if y > p.maxDim { + continue + } size.Y = y } if size.X*size.Y < bestSize.X*bestSize.Y {