From 6818af93907077c1f6a1b78a48d744239019f058 Mon Sep 17 00:00:00 2001 From: Elias Naur Date: Fri, 27 Aug 2021 08:50:04 +0200 Subject: [PATCH] gpu: [compute] get rid of material regions The atlas allocations contains enough information to replace regions. Signed-off-by: Elias Naur --- gpu/compute.go | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/gpu/compute.go b/gpu/compute.go index 7e8bcacd..6528a826 100644 --- a/gpu/compute.go +++ b/gpu/compute.go @@ -82,8 +82,6 @@ type compute struct { materials struct { // allocs maps texture ops the their atlases and FillImage offsets. allocs map[textureKey]materialAlloc - // regions track new materials to be transferred to CPU images. - regions []image.Rectangle pipeline driver.Pipeline buffer sizedBuffer @@ -915,11 +913,11 @@ func (g *compute) renderMaterials() error { texOps := g.texOps for len(texOps) > 0 { m.quads = m.quads[:0] - m.regions = m.regions[:0] var ( atlas *textureAtlas imgAtlas *textureAtlas ) + var allocStart int for len(texOps) > 0 { op := &texOps[0] if a, exists := m.allocs[op.key]; exists { @@ -948,6 +946,9 @@ func (g *compute) renderMaterials() error { if !fits { break } + if atlas == nil { + allocStart = len(alloc.atlas.allocs) + } atlas = alloc.atlas alloc.cpu = g.useCPU // Position quad to match place. @@ -968,7 +969,6 @@ func (g *compute) renderMaterials() error { atlas.allocs = append(atlas.allocs, atlasAlloc.alloc) m.allocs[op.key] = atlasAlloc op.matAlloc = atlasAlloc - m.regions = append(m.regions, alloc.rect) texOps = texOps[1:] } if len(m.quads) == 0 { @@ -1004,12 +1004,13 @@ func (g *compute) renderMaterials() error { } copyFBO := atlas.fbo data := atlas.cpuImage.Data() - for _, r := range m.regions { + newAllocs := atlas.allocs[allocStart:] + for _, a := range newAllocs { stride := atlas.size.X * 4 - col := r.Min.X * 4 - row := stride * r.Min.Y + col := a.rect.Min.X * 4 + row := stride * a.rect.Min.Y off := col + row - copyFBO.ReadPixels(r, data[off:], stride) + copyFBO.ReadPixels(a.rect, data[off:], stride) } } return nil