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 <mail@eliasnaur.com>
This commit is contained in:
Elias Naur
2021-08-26 12:31:17 +02:00
parent 589c94e64b
commit 8c2913c2e6
+7 -1
View File
@@ -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 {