Skip to content

Commit be727d9

Browse files
committed
More improvements to rendering. A leak exists.
- Switched over to queues for rendering - Added DirtyPostProcess - PostProcess does not modify cached buffers - Text & Base Basic animations share frames - Fix colorless vertex post processing - ColorModify improvements - Removed unused types/functions - Static layout fix & respecting only preferred sizes. - Clip & PostProcessing uses pooled buffers - Resolves #54
1 parent 19883a8 commit be727d9

23 files changed

+829
-467
lines changed

cmd/cube/main.go

Lines changed: 48 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ func main() {
205205
textAnimation := ui.BasicTextAnimation{
206206
Settings: []ui.BasicTextAnimationSettings{{
207207
Kind: ui.BasicTextAnimationKindChar,
208-
Frames: []ui.BasicTextAnimationFrame{{
208+
Frames: []ui.BasicAnimationFrame{{
209209
Translate: ui.NewAmountPoint(0, 40),
210210
Scale: &ui.Coord{X: 4, Y: 4},
211211
Origin: ui.NewAmountPointUnit(0.5, 1, ui.UnitParent),
@@ -222,7 +222,7 @@ func main() {
222222
}, {
223223
Start: 11,
224224
Kind: ui.BasicTextAnimationKindWord,
225-
Frames: []ui.BasicTextAnimationFrame{{
225+
Frames: []ui.BasicAnimationFrame{{
226226
Translate: ui.NewAmountPoint(0, -10),
227227
Color: ui.Alpha(0),
228228
Time: 0,
@@ -235,7 +235,7 @@ func main() {
235235
}, {
236236
Start: 39,
237237
Kind: ui.BasicTextAnimationKindLine,
238-
Frames: []ui.BasicTextAnimationFrame{{
238+
Frames: []ui.BasicAnimationFrame{{
239239
Translate: ui.NewAmountPoint(-100, 0),
240240
Color: ui.Alpha(0),
241241
Time: 0,
@@ -248,7 +248,7 @@ func main() {
248248
}, {
249249
Start: 159,
250250
Kind: ui.BasicTextAnimationKindColumn,
251-
Frames: []ui.BasicTextAnimationFrame{{
251+
Frames: []ui.BasicAnimationFrame{{
252252
Translate: ui.NewAmountPoint(-10, 0),
253253
Color: ui.Alpha(0),
254254
Time: 0,
@@ -264,12 +264,19 @@ func main() {
264264
textWindow := newWindow("Test Window", ui.Absolute(900, 20, 500, 400))
265265
textWindow.Children = append(textWindow.Children,
266266
&ui.Base{
267-
Placement: ui.MaximizeOffset(10, 34, 10, 10),
267+
Placement: ui.MaximizeOffset(10, 44, 10, 10),
268268
IgnoreLayoutPreferredHeight: true,
269269
Clip: ui.Maximized(),
270270
Layout: ui.LayoutStatic{
271271
EnforcePreferredSize: true,
272272
},
273+
Events: ui.Events{
274+
OnPointer: func(ev *ui.PointerEvent) {
275+
if !ev.Capture && ev.Type == ui.PointerEventWheel {
276+
fmt.Printf("Wheel event: %+v\n", ev.Amount)
277+
}
278+
},
279+
},
273280
Children: []*ui.Base{{
274281
Layers: []ui.Layer{{
275282
Visual: ui.MustTextToVisual(strings.Join([]string{
@@ -283,7 +290,7 @@ func main() {
283290
"{p}{h:0.25}25% aligned?",
284291
"{p}{h}{w:word}This should wrap at the word and not at the character and should take up at least two lines. Resize the window!",
285292
"{p}{pt:20}{h:0.5}{w:char}This should wrap at the character and not at the word and be centered.",
286-
}, "\n")).Animate(textAnimation),
293+
}, "\n")).Play(textAnimation),
287294
}},
288295
Events: ui.Events{
289296
OnPointer: func(ev *ui.PointerEvent) {
@@ -298,8 +305,19 @@ func main() {
298305
},
299306
},
300307
},
301-
newButton(ui.Placement{}.Attach(1, 0, 100, 30).Shift(-10, 10), "Do a barrel roll!", false, func() {
302-
308+
newButton(ui.Placement{}.Attach(1, 0, 0, 0), "{h:center}{w:none}Do a barrel roll!", false, func() {
309+
textWindow.Play(ui.BasicAnimation{
310+
Duration: 1.0,
311+
Easing: func(x float32) float32 {
312+
inv := 1.0 - x
313+
return (1.0 - util.Abs(inv*inv*util.Cos(x*x*7.0)))
314+
},
315+
Save: true,
316+
Frames: []ui.BasicAnimationFrame{
317+
{Rotate: 360, Time: 0, Origin: ui.NewAmountPointUnit(0.5, 0.5, ui.UnitParent)},
318+
{Rotate: 0, Time: 1, Origin: ui.NewAmountPointUnit(0.5, 0.5, ui.UnitParent)},
319+
},
320+
})
303321
}),
304322
},
305323
},
@@ -311,7 +329,7 @@ func main() {
311329
frame := userInterface.Named.Get(layoutColumnName)
312330
layout := frame.Layout.(*ui.LayoutColumn)
313331
change(layout)
314-
frame.Dirty(ui.DirtyPlacement)
332+
frame.Relayout()
315333
}
316334
layoutColumnWindow := newWindow("Layout Column", ui.Absolute(10, 500, 300, 300))
317335
layoutColumnWindow.Children = append(layoutColumnWindow.Children, &ui.Base{
@@ -366,7 +384,7 @@ func main() {
366384
frame := userInterface.Named.Get(layoutRowName)
367385
layout := frame.Layout.(*ui.LayoutRow)
368386
change(layout)
369-
frame.Dirty(ui.DirtyPlacement)
387+
frame.Relayout()
370388
}
371389
layoutRowWindow := newWindow("Layout Row", ui.Absolute(800, 500, 300, 300))
372390
layoutRowWindow.Children = append(layoutRowWindow.Children, &ui.Base{
@@ -568,7 +586,7 @@ func main() {
568586
frame := userInterface.Named.Get(layoutInlineName)
569587
layout := frame.Layout.(*ui.LayoutInline)
570588
change(layout)
571-
frame.Dirty(ui.DirtyPlacement)
589+
frame.Relayout()
572590
}
573591
layoutInlineWindow := newWindow("Layout Inline", ui.Absolute(20, 700, 300, 300))
574592
layoutInlineWindow.Children = append(layoutInlineWindow.Children,
@@ -720,17 +738,17 @@ var FadeInAnimation = ui.BasicAnimation{
720738
Save: true,
721739
Duration: 0.5,
722740
Frames: []ui.BasicAnimationFrame{
723-
{Time: 0, Transparency: 1},
724-
{Time: 1, Transparency: 0},
741+
{Time: 0, Color: ui.Alpha(0)},
742+
{Time: 1, Color: ui.Alpha(1)},
725743
},
726744
}
727745

728746
var FadeOutAnimation = ui.BasicAnimation{
729747
Save: true,
730748
Duration: 0.5,
731749
Frames: []ui.BasicAnimationFrame{
732-
{Time: 0, Transparency: 0},
733-
{Time: 1, Transparency: 1},
750+
{Time: 0, Color: ui.Alpha(1)},
751+
{Time: 1, Color: ui.Alpha(0)},
734752
},
735753
}
736754

@@ -739,15 +757,15 @@ var FadeOutSlideUpAnimation = ui.BasicAnimation{
739757
Duration: 0.7,
740758
Frames: []ui.BasicAnimationFrame{
741759
{Time: 0, Origin: OriginCenter},
742-
{Time: 1, Translate: ui.AmountPoint{Y: ui.Amount{Value: -100}}, Origin: OriginCenter, Transparency: 1},
760+
{Time: 1, Translate: ui.AmountPoint{Y: ui.Amount{Value: -100}}, Origin: OriginCenter, Color: ui.Alpha(0)},
743761
},
744762
}
745763

746764
var FadeInSlideDownAnimation = ui.BasicAnimation{
747765
Save: true,
748766
Duration: 0.7,
749767
Frames: []ui.BasicAnimationFrame{
750-
{Time: 0, Transparency: 1, Translate: ui.AmountPoint{Y: ui.Amount{Value: -100}}, Origin: OriginCenter},
768+
{Time: 0, Color: ui.Alpha(0), Translate: ui.AmountPoint{Y: ui.Amount{Value: -100}}, Origin: OriginCenter},
751769
{Time: 1, Origin: OriginCenter},
752770
},
753771
}
@@ -756,32 +774,32 @@ var FadeInSlideRightAnimation = ui.BasicAnimation{
756774
Save: true,
757775
Duration: 0.7,
758776
Frames: []ui.BasicAnimationFrame{
759-
{Time: 0, Translate: ui.AmountPoint{X: ui.Amount{Value: -100}}, Origin: OriginCenter, Transparency: 1},
777+
{Time: 0, Translate: ui.AmountPoint{X: ui.Amount{Value: -100}}, Origin: OriginCenter, Color: ui.Alpha(0)},
760778
{Time: 1, Origin: OriginCenter},
761779
},
762780
}
763781

764782
var ExplodeAnimation = ui.BasicAnimation{
765783
Duration: 0.2,
766784
Frames: []ui.BasicAnimationFrame{
767-
{Time: 0, Transparency: 0, Scale: &ui.Coord{X: 1, Y: 1}, Origin: OriginCenter},
768-
{Time: 1, Transparency: 1, Scale: &ui.Coord{X: 4, Y: 4}, Origin: OriginCenter},
785+
{Time: 0, Color: ui.Alpha(1), Scale: &ui.Coord{X: 1, Y: 1}, Origin: OriginCenter},
786+
{Time: 1, Color: ui.Alpha(0), Scale: &ui.Coord{X: 4, Y: 4}, Origin: OriginCenter},
769787
},
770788
}
771789

772790
var CollapseOpenAnimation = ui.BasicAnimation{
773791
Duration: 0.3,
774792
Frames: []ui.BasicAnimationFrame{
775-
{Time: 0, Scale: &ui.Coord{X: 1, Y: 0}, Transparency: 1},
776-
{Time: 1, Scale: &ui.Coord{X: 1, Y: 1}, Transparency: 0},
793+
{Time: 0, Scale: &ui.Coord{X: 1, Y: 0}, Color: ui.Alpha(0)},
794+
{Time: 1, Scale: &ui.Coord{X: 1, Y: 1}, Color: ui.Alpha(1)},
777795
},
778796
}
779797

780798
var CollapseCloseAnimation = ui.BasicAnimation{
781799
Duration: 0.3,
782800
Frames: []ui.BasicAnimationFrame{
783-
{Time: 0, Scale: &ui.Coord{X: 1, Y: 1}, Transparency: 0},
784-
{Time: 1, Scale: &ui.Coord{X: 1, Y: 0}, Transparency: 1},
801+
{Time: 0, Scale: &ui.Coord{X: 1, Y: 1}, Color: ui.Alpha(1)},
802+
{Time: 1, Scale: &ui.Coord{X: 1, Y: 0}, Color: ui.Alpha(0)},
785803
},
786804
}
787805

@@ -1297,12 +1315,12 @@ func newWindow(title string, placement ui.Placement) *ui.Base {
12971315
}
12981316
switch ev.Type {
12991317
case ui.DragEventStart:
1300-
frame.Transparency.Set(0.2)
1318+
frame.SetTransparency(0.2)
13011319
frame.BringToFront()
13021320
case ui.DragEventMove:
13031321
frame.SetPlacement(frame.Placement.Shift(ev.DeltaMove.X, ev.DeltaMove.Y))
13041322
case ui.DragEventEnd:
1305-
frame.Transparency.Set(0)
1323+
frame.SetTransparency(0)
13061324
}
13071325
},
13081326
},
@@ -1369,11 +1387,11 @@ func newWindowClose(win *ui.Base, barSize float32) *ui.Base {
13691387
Events: ui.Events{
13701388
OnPointer: func(ev *ui.PointerEvent) {
13711389
if !ev.Capture && ev.Type == ui.PointerEventUp {
1372-
win.Transparency.Set(1)
1390+
win.SetTransparency(1)
13731391

13741392
go func() {
13751393
time.Sleep(time.Second * 3)
1376-
win.Transparency.Set(0)
1394+
win.SetTransparency(0)
13771395
}()
13781396
}
13791397
},
@@ -1498,7 +1516,7 @@ func newWindowResizer(win *ui.Base, cursor id.Identifier, placement ui.Placement
14981516
ev.Stop = true
14991517
switch ev.Type {
15001518
case ui.DragEventStart:
1501-
win.Transparency.Set(0.2)
1519+
win.SetTransparency(0.2)
15021520
start = win.Placement
15031521
case ui.DragEventMove:
15041522
current := win.Placement
@@ -1515,7 +1533,7 @@ func newWindowResizer(win *ui.Base, cursor id.Identifier, placement ui.Placement
15151533
case ui.DragEventCancel:
15161534
win.SetPlacement(start)
15171535
case ui.DragEventEnd:
1518-
win.Transparency.Set(0)
1536+
win.SetTransparency(0)
15191537
}
15201538
}
15211539
},

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,4 @@ require (
1515
github.com/vulkan-go/vulkan v0.0.0-20221209234627-c0a353ae26c8
1616
)
1717

18-
require github.com/fzipp/bmfont v0.1.0 // indirect
18+
require github.com/fzipp/bmfont v0.1.0

pkg/buf/buffer.go

Lines changed: 29 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,16 @@ package buf
33
import "github.com/axe/axe-go/pkg/util"
44

55
type Buffer[D any] struct {
6-
data []D
7-
dataCount int
8-
index []int
9-
indexCount int
6+
data []D
7+
dataCount int
8+
dataReserved int
9+
index []int
10+
indexCount int
11+
indexReserved int
1012
}
1113

1214
var _ Bufferable[int] = Buffer[int]{}
15+
var _ HasBuffers[Buffer[int]] = Buffer[int]{}
1316

1417
func (b *Buffer[D]) Init(capacity int) {
1518
if b.data == nil {
@@ -19,6 +22,14 @@ func (b *Buffer[D]) Init(capacity int) {
1922
b.Clear()
2023
}
2124

25+
func (b *Buffer[D]) CloneTo(target Buffer[D]) Buffer[D] {
26+
target.data = util.SliceAppendAt(target.data, 0, b.data[:b.dataCount])
27+
target.dataCount = b.dataCount
28+
target.index = util.SliceAppendAt(target.index, 0, b.index[:b.indexCount])
29+
target.indexCount = b.indexCount
30+
return target
31+
}
32+
2233
func (b *Buffer[D]) Clear() {
2334
b.dataCount = 0
2435
b.indexCount = 0
@@ -73,16 +84,18 @@ func (b Buffer[D]) Remaining() int {
7384
}
7485

7586
func (b *Buffer[D]) Reserve(datas int, indices int) {
76-
b.data = util.SliceEnsureSize(b.data, b.dataCount+datas+1)
77-
b.index = util.SliceEnsureSize(b.index, b.indexCount+indices+1)
87+
b.ReserveData(datas)
88+
b.ReserveIndex(indices)
7889
}
7990

8091
func (b *Buffer[D]) ReserveData(datas int) {
81-
b.data = util.SliceEnsureSize(b.data, b.dataCount+datas+1)
92+
b.dataReserved += datas
93+
b.data = util.SliceEnsureSize(b.data, b.dataCount+b.dataReserved)
8294
}
8395

8496
func (b *Buffer[D]) ReserveIndex(indices int) {
85-
b.index = util.SliceEnsureSize(b.index, b.indexCount+indices+1)
97+
b.indexReserved += indices
98+
b.index = util.SliceEnsureSize(b.index, b.indexCount+b.indexReserved)
8699
}
87100

88101
func (b *Buffer[D]) Reserved(dataCount, indexCount int) (dataIndex int, data []D, index []int) {
@@ -91,18 +104,22 @@ func (b *Buffer[D]) Reserved(dataCount, indexCount int) (dataIndex int, data []D
91104
index = b.index[b.indexCount : b.indexCount+indexCount]
92105
b.dataCount += dataCount
93106
b.indexCount += indexCount
107+
b.dataReserved -= dataCount
108+
b.indexReserved -= indexCount
94109
return
95110
}
96111

97112
func (b *Buffer[D]) ReservedNext() *D {
98113
data := &b.data[b.dataCount]
99114
b.dataCount++
115+
b.dataReserved--
100116
return data
101117
}
102118

103119
func (b *Buffer[D]) ReservedNextIndex() *int {
104120
index := &b.index[b.indexCount]
105121
b.indexCount++
122+
b.indexReserved--
106123
return index
107124
}
108125

@@ -136,3 +153,7 @@ func (b *Buffer[D]) AddRelative(data []D, relative []int) {
136153
b.index[i] += index
137154
}
138155
}
156+
157+
func (b Buffer[D]) GetBuffers() []Buffer[D] {
158+
return []Buffer[D]{b}
159+
}

0 commit comments

Comments
 (0)