Files
aego/render/sprite/auxiliary.go
T
sanspie 50be5c04bc
ci-platforms / darwin amd64 smoke (push) Skipped
GitHub / linux amd64 native GitHub-hosted native CI: success
ci-platforms / windows amd64 smoke (push) Skipped
GitHub / windows amd64 native GitHub-hosted native CI: success
GitHub / darwin arm64 native GitHub-hosted native CI: success
GitHub / darwin amd64 native GitHub-hosted native CI: success
ci / checks (push) Failing after 1h21m34s
ci / native-authoring (push) Skipped
ci-platforms / darwin arm64 smoke (push) Skipped
github-native / gitea-pending (push) Skipped
github-native / darwin amd64 native (push) Skipped
github-native / linux amd64 native (push) Skipped
github-native / windows amd64 native (push) Skipped
github-native / darwin arm64 native (push) Skipped
github-native / gitea-result (push) Skipped
ci / build (amd64, linux, ubuntu-24.04) (push) Successful in 12m4s
ci / release (push) Skipped
Stage 12.5: Art Workspace and asset authoring
Add dockable Art tools, animation and previews, guarded asset workflows,
and the Web Asset Studio built on the shared Art Core. Expand English and
Russian documentation, interactive Try scenes, examples and editor icons.

Add audio waveform navigation, source analysis, guarded previews and a
browser Worker mixer. Preserve source changes and recovery with bounded
checks, and strengthen native, browser and interoperability CI.

Prepare version 0.12.5 and manually built native artifact candidates.
Fix the production site image demo build dependency.
Reuse immutable scene indices when capturing keyframes.
Wait for real Persist save/load completion in component tests.
Stabilize browser Game View captures outside pointer hover.
Aseprite interchange and persistent Audio EDL recovery remain limited;
the artifact workflow does not publish releases or change stable.
2026-11-15 10:37:50 +03:00

112 lines
3.1 KiB
Go

package sprite
import (
"unsafe"
"aego/gpu"
"aego/render/shader"
)
const (
AuxStride = shader.AuxStride
AuxSlot = shader.AuxSlot
AffineLocation = shader.AffineLocation
NormalUVLocation = shader.NormalUVLocation
NormalLocalLocation = shader.NormalLocalLocation
EmissionUVLocation = shader.EmissionUVLocation
EmissionLocalLocation = shader.EmissionLocalLocation
)
// Aux is an optional per-instance stream independent of material overrides; Affine stores (m00-1,m10,m01,m11) so disabled (0,0,0,1) decodes to identity.
// NormalUV/NormalLocal map the independently packed normal rectangle to its source canvas.
type Aux struct {
Affine [4]float32
NormalUV [4]float32
NormalLocal [4]float32
EmissionUV [4]float32
EmissionLocal [4]float32
}
const _ = uint(AuxStride - unsafe.Sizeof(Aux{}))
const _ = uint(unsafe.Sizeof(Aux{}) - AuxStride)
func identityAux() Aux {
return Aux{Affine: [4]float32{0, 0, 0, 1}, NormalLocal: [4]float32{0, 0, 1, 1}, EmissionLocal: [4]float32{0, 0, 1, 1}}
}
func makeAux(d *Draw) Aux {
a := identityAux()
a.Affine = d.Basis()
a.Affine[0]--
if d.Lighting && !d.Normal.IsZero() {
r := d.Normal
a.NormalUV = [4]float32{r.UVMin.X, r.UVMin.Y, r.UVMax.X, r.UVMax.Y}
a.NormalLocal = r.LocalRect()
}
if d.Lighting && d.Emission.Valid() {
r := d.Emission.Region
a.EmissionUV = [4]float32{r.UVMin.X, r.UVMin.Y, r.UVMax.X, r.UVMax.Y}
a.EmissionLocal = r.LocalRect()
}
return a
}
func (b *Batcher) collectAux(from, to int) int {
if len(b.aux) == 0 {
return -1
}
found := false
for i := from; i < to; i++ {
if b.sortedAux[i] >= 0 {
found = true
break
}
}
if !found {
return -1
}
first := len(b.auxOut)
for i := from; i < to; i++ {
a := identityAux()
if j := b.sortedAux[i]; j >= 0 {
a = b.aux[j]
}
b.auxOut = append(b.auxOut, a)
}
return first
}
// UploadAux leaves the ordinary sprite path untouched until a draw needs an
// affine basis or lighting. Capacity growth is reused by subsequent frames.
func (b *Batcher) UploadAux() bool {
n := len(b.auxOut)
if n == 0 {
return true
}
if n > b.auxCap {
c := max(n, 256, b.auxCap*2)
h, err := b.dev.CreateBuffer(gpu.BufferDesc{Usage: gpu.BufferVertex, Size: c * AuxStride, Dynamic: true, Label: "sprite.aux"})
if err != nil {
return false
}
if !b.auxVB.IsZero() {
b.dev.DestroyBuffer(b.auxVB)
}
b.auxVB, b.auxCap = h, c
}
raw := unsafe.Slice((*byte)(unsafe.Pointer(&b.auxOut[0])), n*AuxStride)
b.dev.UpdateBuffer(b.auxVB, 0, raw)
return true
}
func (b *Batcher) AuxBuffer() gpu.BufferHandle { return b.auxVB }
func (b *Batcher) AuxBytes() int { return len(b.auxOut) * AuxStride }
// AuxLayout adds the plain sprite shader's affine input; material.Cache adds feature-specific channel inputs, and a disabled stream uses the backend's generic float defaults.
func AuxLayout(l gpu.VertexLayout) gpu.VertexLayout {
l.Attrs = append(l.Attrs, gpu.VertexAttr{Location: AffineLocation, Slot: AuxSlot, Format: gpu.VFFloat4, Offset: 0})
l.Strides[AuxSlot] = AuxStride
l.PerInstance[AuxSlot] = true
return l
}