mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2025-09-26 20:11:28 +08:00
@@ -353,6 +353,9 @@ func (g *game) Draw(screen *ebiten.Image) {
|
||||
fg = "No"
|
||||
}
|
||||
|
||||
var debug ebiten.DebugInfo
|
||||
ebiten.ReadDebugInfo(&debug)
|
||||
|
||||
msg := fmt.Sprintf(`[Arrow keys] Move the window
|
||||
[Shift + Arrow keys] Change the window size
|
||||
%s
|
||||
@@ -375,7 +378,8 @@ Window size limitation: (%d, %d) - (%d, %d)
|
||||
Cursor: (%d, %d)
|
||||
TPS: Current: %0.2f / Max: %s
|
||||
FPS: %0.2f
|
||||
Device Scale Factor: %0.2f`, msgM, msgR, fg, wx, wy, ww, wh, minw, minh, maxw, maxh, cx, cy, ebiten.ActualTPS(), tpsStr, ebiten.ActualFPS(), ebiten.Monitor().DeviceScaleFactor())
|
||||
Device Scale Factor: %0.2f
|
||||
GPU Memory Usage: %d`, msgM, msgR, fg, wx, wy, ww, wh, minw, minh, maxw, maxh, cx, cy, ebiten.ActualTPS(), tpsStr, ebiten.ActualFPS(), ebiten.Monitor().DeviceScaleFactor(), debug.TotalGPUImageMemoryUsageInBytes)
|
||||
ebitenutil.DebugPrint(screen, msg)
|
||||
}
|
||||
|
||||
|
@@ -15,6 +15,7 @@
|
||||
package ebiten
|
||||
|
||||
import (
|
||||
"github.com/hajimehoshi/ebiten/v2/internal/atlas"
|
||||
"github.com/hajimehoshi/ebiten/v2/internal/builtinshader"
|
||||
"github.com/hajimehoshi/ebiten/v2/internal/ui"
|
||||
)
|
||||
@@ -70,11 +71,18 @@ var _ [GraphicsLibraryAuto]int = [0]int{}
|
||||
type DebugInfo struct {
|
||||
// GraphicsLibrary represents the graphics library currently in use.
|
||||
GraphicsLibrary GraphicsLibrary
|
||||
|
||||
// TotalGPUImageMemoryUsageInBytes is the total image memory usage for GPU in bytes.
|
||||
// TotalGPUImageMemoryUsageInBytes is approximately the total memory usage for GPU.
|
||||
TotalGPUImageMemoryUsageInBytes int64
|
||||
}
|
||||
|
||||
// ReadDebugInfo writes debug info (e.g. current graphics library) into a provided struct.
|
||||
//
|
||||
// ReadDebugInfo is concurrent-safe.
|
||||
func ReadDebugInfo(d *DebugInfo) {
|
||||
d.GraphicsLibrary = GraphicsLibrary(ui.Get().GraphicsLibrary())
|
||||
d.TotalGPUImageMemoryUsageInBytes = atlas.TotalGPUImageMemoryUsageInBytes()
|
||||
}
|
||||
|
||||
// ColorSpace represents the color space of the screen.
|
||||
|
@@ -838,3 +838,18 @@ func DumpImages(graphicsDriver graphicsdriver.Graphics, dir string) (string, err
|
||||
|
||||
return restorable.DumpImages(graphicsDriver, dir)
|
||||
}
|
||||
|
||||
func TotalGPUImageMemoryUsageInBytes() int64 {
|
||||
backendsM.Lock()
|
||||
defer backendsM.Unlock()
|
||||
|
||||
var sum int64
|
||||
for _, b := range theBackends {
|
||||
if b.restorable == nil {
|
||||
continue
|
||||
}
|
||||
w, h := b.restorable.InternalSize()
|
||||
sum += 4 * int64(w) * int64(h)
|
||||
}
|
||||
return sum
|
||||
}
|
||||
|
Reference in New Issue
Block a user