mirror of
https://git.sr.ht/~eliasnaur/gio
synced 2026-07-06 09:55:40 +00:00
gpu: give compute.atlas a more precise name, reset atlas efficiently
Refactor only, in preparation for adding another atlas with pre-processed materials. Signed-off-by: Elias Naur <mail@eliasnaur.com>
This commit is contained in:
+12
-14
@@ -46,12 +46,13 @@ type compute struct {
|
|||||||
}
|
}
|
||||||
output struct {
|
output struct {
|
||||||
size image.Point
|
size image.Point
|
||||||
// image is the output texture. Note that it is RGBA format,
|
// image is the output texture. Note that it is in RGBA format,
|
||||||
// but contains data in sRGB. See blitOutput for more detail.
|
// but contains data in sRGB. See blitOutput for more detail.
|
||||||
image backend.Texture
|
image backend.Texture
|
||||||
blitProg backend.Program
|
blitProg backend.Program
|
||||||
}
|
}
|
||||||
atlas struct {
|
// images contains ImageOp images packed into a texture atlas.
|
||||||
|
images struct {
|
||||||
packer packer
|
packer packer
|
||||||
// positions maps imageOpData.handles to positions inside tex.
|
// positions maps imageOpData.handles to positions inside tex.
|
||||||
positions map[interface{}]image.Point
|
positions map[interface{}]image.Point
|
||||||
@@ -303,7 +304,7 @@ func (g *compute) uploadImages(ops []imageOp) error {
|
|||||||
// images, to avoid atlas filtering artifacts.
|
// images, to avoid atlas filtering artifacts.
|
||||||
const padding = 1
|
const padding = 1
|
||||||
|
|
||||||
a := &g.atlas
|
a := &g.images
|
||||||
var uploads map[interface{}]*image.RGBA
|
var uploads map[interface{}]*image.RGBA
|
||||||
resize := false
|
resize := false
|
||||||
reclaimed := false
|
reclaimed := false
|
||||||
@@ -320,12 +321,9 @@ restart:
|
|||||||
size.Y += padding
|
size.Y += padding
|
||||||
place, fits := a.packer.tryAdd(size)
|
place, fits := a.packer.tryAdd(size)
|
||||||
if !fits {
|
if !fits {
|
||||||
maxDim := a.packer.maxDim
|
|
||||||
a.positions = nil
|
a.positions = nil
|
||||||
uploads = nil
|
uploads = nil
|
||||||
a.packer = packer{
|
a.packer.clear()
|
||||||
maxDim: maxDim,
|
|
||||||
}
|
|
||||||
if !reclaimed {
|
if !reclaimed {
|
||||||
// Some images may no longer be in use, try again
|
// Some images may no longer be in use, try again
|
||||||
// after clearing existing maps.
|
// after clearing existing maps.
|
||||||
@@ -341,7 +339,7 @@ restart:
|
|||||||
continue restart
|
continue restart
|
||||||
}
|
}
|
||||||
if a.positions == nil {
|
if a.positions == nil {
|
||||||
g.atlas.positions = make(map[interface{}]image.Point)
|
g.images.positions = make(map[interface{}]image.Point)
|
||||||
}
|
}
|
||||||
a.positions[m.data.handle] = place.Pos
|
a.positions[m.data.handle] = place.Pos
|
||||||
if uploads == nil {
|
if uploads == nil {
|
||||||
@@ -393,7 +391,7 @@ func (g *compute) encodeOps(trans f32.Affine2D, viewport image.Point, ops []imag
|
|||||||
switch m.material {
|
switch m.material {
|
||||||
case materialTexture:
|
case materialTexture:
|
||||||
img := m.data
|
img := m.data
|
||||||
pos, ok := g.atlas.positions[img.handle]
|
pos, ok := g.images.positions[img.handle]
|
||||||
if !ok {
|
if !ok {
|
||||||
panic("compute: internal error: image not placed")
|
panic("compute: internal error: image not placed")
|
||||||
}
|
}
|
||||||
@@ -401,7 +399,7 @@ func (g *compute) encodeOps(trans f32.Affine2D, viewport image.Point, ops []imag
|
|||||||
Min: pos,
|
Min: pos,
|
||||||
Max: pos.Add(img.src.Bounds().Size()),
|
Max: pos.Add(img.src.Bounds().Size()),
|
||||||
}
|
}
|
||||||
maxDim := g.atlas.packer.maxDim
|
maxDim := g.images.packer.maxDim
|
||||||
atlasSize := f32.Pt(float32(maxDim), float32(maxDim))
|
atlasSize := f32.Pt(float32(maxDim), float32(maxDim))
|
||||||
uvBounds := f32.Rectangle{
|
uvBounds := f32.Rectangle{
|
||||||
Min: f32.Point{
|
Min: f32.Point{
|
||||||
@@ -521,8 +519,8 @@ func (g *compute) render(tileDims image.Point) error {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
g.ctx.BindImageTexture(kernel4OutputUnit, g.output.image, backend.AccessWrite, backend.TextureFormatRGBA8)
|
g.ctx.BindImageTexture(kernel4OutputUnit, g.output.image, backend.AccessWrite, backend.TextureFormatRGBA8)
|
||||||
if g.atlas.tex != nil {
|
if g.images.tex != nil {
|
||||||
g.ctx.BindTexture(kernel4AtlasUnit, g.atlas.tex)
|
g.ctx.BindTexture(kernel4AtlasUnit, g.images.tex)
|
||||||
}
|
}
|
||||||
|
|
||||||
// alloc is the number of allocated bytes for static buffers.
|
// alloc is the number of allocated bytes for static buffers.
|
||||||
@@ -693,8 +691,8 @@ func (g *compute) Release() {
|
|||||||
if g.output.image != nil {
|
if g.output.image != nil {
|
||||||
g.output.image.Release()
|
g.output.image.Release()
|
||||||
}
|
}
|
||||||
if g.atlas.tex != nil {
|
if g.images.tex != nil {
|
||||||
g.atlas.tex.Release()
|
g.images.tex.Release()
|
||||||
}
|
}
|
||||||
if g.timers.t != nil {
|
if g.timers.t != nil {
|
||||||
g.timers.t.release()
|
g.timers.t.release()
|
||||||
|
|||||||
Reference in New Issue
Block a user