internal/ui: optimize GPU usages when the screen doesn't have to be updated

This change skips rendering when 1) the screen is not cleared every frame
(`SetScreenClearedEveryFrame(false)`) and 2) Draw doesn't draw anything
onto the screen. The GPU usages decreased on some machines (e.g. GPU usage
was 10% with an empty Ebitengine project and became 2-3 % on a Windows
machine).

Updates #2341
This commit is contained in:
Hajime Hoshi
2022-10-24 01:51:37 +09:00
parent fcda4143a5
commit b019a3723a
6 changed files with 152 additions and 16 deletions

View File

@@ -168,7 +168,8 @@ func (q *commandQueue) Flush(graphicsDriver graphicsdriver.Graphics, endFrame bo
// flush must be called the main thread.
func (q *commandQueue) flush(graphicsDriver graphicsdriver.Graphics, endFrame bool) (err error) {
if len(q.commands) == 0 {
// If endFrame is true, Begin/End should be called to ensure the framebuffer is swapped.
if len(q.commands) == 0 && !endFrame {
return nil
}