|
|
@@ -3,14 +3,12 @@ package stats
|
|
|
import (
|
|
|
"github.com/g3n/engine/gls"
|
|
|
"github.com/g3n/engine/gui"
|
|
|
- "time"
|
|
|
)
|
|
|
|
|
|
// StatsTable is a gui.Table panel with statistics
|
|
|
type StatsTable struct {
|
|
|
*gui.Table // embedded table panel
|
|
|
fields []*field // array of fields to show
|
|
|
- stats *Stats // statistics object
|
|
|
}
|
|
|
|
|
|
type field struct {
|
|
|
@@ -21,6 +19,7 @@ type field struct {
|
|
|
// NewStatsTable creates and returns a pointer to a new statistics table panel
|
|
|
func NewStatsTable(width, height float32, gs *gls.GLS) *StatsTable {
|
|
|
|
|
|
+ // Creates table panel
|
|
|
st := new(StatsTable)
|
|
|
t, err := gui.NewTable(width, height, []gui.TableColumn{
|
|
|
{Id: "f", Header: "Stat", Width: 50, Minwidth: 32, Align: gui.AlignRight, Format: "%s", Resize: true, Expand: 2},
|
|
|
@@ -31,6 +30,8 @@ func NewStatsTable(width, height float32, gs *gls.GLS) *StatsTable {
|
|
|
}
|
|
|
st.Table = t
|
|
|
st.ShowHeader(false)
|
|
|
+
|
|
|
+ // Add rows
|
|
|
st.addRow("shaders", "Shaders:")
|
|
|
st.addRow("vaos", "Vaos:")
|
|
|
st.addRow("buffers", "Buffers:")
|
|
|
@@ -38,37 +39,29 @@ func NewStatsTable(width, height float32, gs *gls.GLS) *StatsTable {
|
|
|
st.addRow("unisets", "Uniforms/frame:")
|
|
|
st.addRow("drawcalls", "Draw calls/frame:")
|
|
|
st.addRow("cgocalls", "CGO calls/frame:")
|
|
|
- st.stats = NewStats(gs)
|
|
|
return st
|
|
|
}
|
|
|
|
|
|
-// Update should be called normally in the render loop with the desired update interval
|
|
|
-func (st *StatsTable) Update(d time.Duration) {
|
|
|
-
|
|
|
- if st.stats.Update(d) {
|
|
|
- st.update()
|
|
|
- }
|
|
|
-}
|
|
|
-
|
|
|
-func (st *StatsTable) update() {
|
|
|
+// Update updates the table values from the specified stats table
|
|
|
+func (st *StatsTable) Update(s *Stats) {
|
|
|
|
|
|
for i := 0; i < len(st.fields); i++ {
|
|
|
f := st.fields[i]
|
|
|
switch f.id {
|
|
|
case "shaders":
|
|
|
- st.Table.SetCell(f.row, "v", st.stats.Glstats.Shaders)
|
|
|
+ st.Table.SetCell(f.row, "v", s.Glstats.Shaders)
|
|
|
case "vaos":
|
|
|
- st.Table.SetCell(f.row, "v", st.stats.Glstats.Vaos)
|
|
|
+ st.Table.SetCell(f.row, "v", s.Glstats.Vaos)
|
|
|
case "buffers":
|
|
|
- st.Table.SetCell(f.row, "v", st.stats.Glstats.Buffers)
|
|
|
+ st.Table.SetCell(f.row, "v", s.Glstats.Buffers)
|
|
|
case "textures":
|
|
|
- st.Table.SetCell(f.row, "v", st.stats.Glstats.Textures)
|
|
|
+ st.Table.SetCell(f.row, "v", s.Glstats.Textures)
|
|
|
case "unisets":
|
|
|
- st.Table.SetCell(f.row, "v", st.stats.Unisets)
|
|
|
+ st.Table.SetCell(f.row, "v", s.Unisets)
|
|
|
case "drawcalls":
|
|
|
- st.Table.SetCell(f.row, "v", st.stats.Drawcalls)
|
|
|
+ st.Table.SetCell(f.row, "v", s.Drawcalls)
|
|
|
case "cgocalls":
|
|
|
- st.Table.SetCell(f.row, "v", st.stats.Cgocalls)
|
|
|
+ st.Table.SetCell(f.row, "v", s.Cgocalls)
|
|
|
}
|
|
|
}
|
|
|
}
|