graphicscommand: Dump internal image info on the debug mode

Closes #1714
This commit is contained in:
Hajime Hoshi 2021-08-05 01:15:41 +09:00
parent 852c787743
commit 60b8f82bfd
6 changed files with 30 additions and 2 deletions

View File

@ -21,6 +21,8 @@ import (
"fmt" "fmt"
) )
const IsDebug = true
func Logf(format string, args ...interface{}) { func Logf(format string, args ...interface{}) {
fmt.Printf(format, args...) fmt.Printf(format, args...)
} }

View File

@ -17,5 +17,7 @@
package debug package debug
const IsDebug = false
func Logf(format string, args ...interface{}) { func Logf(format string, args ...interface{}) {
} }

View File

@ -217,7 +217,7 @@ func (q *commandQueue) flush() error {
es := q.indices es := q.indices
vs := q.vertices vs := q.vertices
debug.Logf("--\nGraphics commands:\n") debug.Logf("Graphics commands:\n")
if theGraphicsDriver.HasHighPrecisionFloat() { if theGraphicsDriver.HasHighPrecisionFloat() {
n := q.nvertices / graphics.VertexFloatNum n := q.nvertices / graphics.VertexFloatNum

View File

@ -18,9 +18,11 @@ import (
"fmt" "fmt"
"image" "image"
"os" "os"
"sort"
"strings" "strings"
"github.com/hajimehoshi/ebiten/v2/internal/affine" "github.com/hajimehoshi/ebiten/v2/internal/affine"
"github.com/hajimehoshi/ebiten/v2/internal/debug"
"github.com/hajimehoshi/ebiten/v2/internal/driver" "github.com/hajimehoshi/ebiten/v2/internal/driver"
"github.com/hajimehoshi/ebiten/v2/internal/graphics" "github.com/hajimehoshi/ebiten/v2/internal/graphics"
"github.com/hajimehoshi/ebiten/v2/internal/png" "github.com/hajimehoshi/ebiten/v2/internal/png"
@ -240,3 +242,13 @@ func (i *Image) Dump(path string, blackbg bool, rect image.Rectangle) error {
} }
return nil return nil
} }
func LogImagesInfo(images []*Image) {
sort.Slice(images, func(a, b int) bool {
return images[a].id < images[b].id
})
for _, i := range images {
w, h := i.InternalSize()
debug.Logf(" %d: (%d, %d)\n", i.id, w, h)
}
}

View File

@ -18,6 +18,7 @@ import (
"image" "image"
"path/filepath" "path/filepath"
"github.com/hajimehoshi/ebiten/v2/internal/debug"
"github.com/hajimehoshi/ebiten/v2/internal/driver" "github.com/hajimehoshi/ebiten/v2/internal/driver"
"github.com/hajimehoshi/ebiten/v2/internal/graphicscommand" "github.com/hajimehoshi/ebiten/v2/internal/graphicscommand"
) )
@ -57,6 +58,15 @@ var theImages = &images{
// //
// ResolveStaleImages is intended to be called at the end of a frame. // ResolveStaleImages is intended to be called at the end of a frame.
func ResolveStaleImages() error { func ResolveStaleImages() error {
if debug.IsDebug {
debug.Logf("Internal image sizes:\n")
imgs := make([]*graphicscommand.Image, 0, len(theImages.images))
for i := range theImages.images {
imgs = append(imgs, i.image)
}
graphicscommand.LogImagesInfo(imgs)
}
if err := graphicscommand.FlushCommands(); err != nil { if err := graphicscommand.FlushCommands(); err != nil {
return err return err
} }

View File

@ -160,6 +160,8 @@ func (c *uiContext) update(updateCount int) error {
return err return err
} }
debug.Logf("----\n")
if err := buffered.BeginFrame(); err != nil { if err := buffered.BeginFrame(); err != nil {
return err return err
} }
@ -185,7 +187,7 @@ func (c *uiContext) updateImpl(updateCount int) error {
updateCount = 1 updateCount = 1
c.updateCalled = true c.updateCalled = true
} }
debug.Logf("--\nUpdate count per frame: %d\n", updateCount) debug.Logf("Update count per frame: %d\n", updateCount)
for i := 0; i < updateCount; i++ { for i := 0; i < updateCount; i++ {
if err := hooks.RunBeforeUpdateHooks(); err != nil { if err := hooks.RunBeforeUpdateHooks(); err != nil {