From a03b335c24db87ebb9d062a3dabaa0c2dba0a112 Mon Sep 17 00:00:00 2001 From: Hajime Hoshi Date: Mon, 5 Mar 2018 00:45:03 +0900 Subject: [PATCH] graphics: Add logging when 'ebitendebug' tag is specified Fixes #563 --- internal/graphics/command.go | 32 +++++++++++++++++++++++ internal/graphics/debug_ebitendebug.go | 21 +++++++++++++++ internal/graphics/debug_notebitendebug.go | 21 +++++++++++++++ 3 files changed, 74 insertions(+) create mode 100644 internal/graphics/debug_ebitendebug.go create mode 100644 internal/graphics/debug_notebitendebug.go diff --git a/internal/graphics/command.go b/internal/graphics/command.go index 8ad670462..1b3e28316 100644 --- a/internal/graphics/command.go +++ b/internal/graphics/command.go @@ -29,6 +29,8 @@ import ( // A command is not immediately executed after created. Instaed, it is queued after created, // and executed only when necessary. type command interface { + fmt.Stringer + Exec(indexOffsetInBytes int) error NumVertices() int NumIndices() int @@ -147,6 +149,9 @@ func (q *commandQueue) Flush() { opengl.GetContext().ResetViewportSize() es := q.indices vs := q.vertices + if recordLog() { + fmt.Println("--") + } for len(q.commands) > 0 { nv := 0 ne := 0 @@ -177,6 +182,9 @@ func (q *commandQueue) Flush() { q.err = err return } + if recordLog() { + fmt.Printf("%s\n", c) + } // TODO: indexOffsetInBytes should be reset if the command type is different // from the previous one. This fix is needed when another drawing command is // introduced than drawImageCommand. @@ -221,6 +229,10 @@ func VertexSizeInBytes() int { return theArrayBufferLayout.totalBytes() } +func (c *drawImageCommand) String() string { + return fmt.Sprintf("draw-image: dst: %p <- src: %p, colorm: %v, mode %d, filter: %d", c.dst, c.src, c.color, c.mode, c.filter) +} + // Exec executes the drawImageCommand. func (c *drawImageCommand) Exec(indexOffsetInBytes int) error { f, err := c.dst.createFramebufferIfNeeded() @@ -292,6 +304,10 @@ type replacePixelsCommand struct { height int } +func (c *replacePixelsCommand) String() string { + return fmt.Sprintf("replace-pixels: dst: %p, x: %d, y: %d, width: %d, height: %d", c.dst, c.x, c.y, c.width, c.height) +} + // Exec executes the replacePixelsCommand. func (c *replacePixelsCommand) Exec(indexOffsetInBytes int) error { // glFlush is necessary on Android. @@ -339,6 +355,10 @@ func (c *pixelsCommand) Exec(indexOffsetInBytes int) error { return nil } +func (c *pixelsCommand) String() string { + return fmt.Sprintf("pixels: img: %p", c.img) +} + func (c *pixelsCommand) NumVertices() int { return 0 } @@ -362,6 +382,10 @@ type disposeCommand struct { target *Image } +func (c *disposeCommand) String() string { + return fmt.Sprintf("dispose: target: %p", c.target) +} + // Exec executes the disposeCommand. func (c *disposeCommand) Exec(indexOffsetInBytes int) error { if c.target.framebuffer != nil && @@ -415,6 +439,10 @@ func checkSize(width, height int) { } } +func (c *newImageCommand) String() string { + return fmt.Sprintf("new-image: result: %p, width: %d, height: %d", c.result, c.width, c.height) +} + // Exec executes a newImageCommand. func (c *newImageCommand) Exec(indexOffsetInBytes int) error { w := emath.NextPowerOf2Int(c.width) @@ -455,6 +483,10 @@ type newScreenFramebufferImageCommand struct { height int } +func (c *newScreenFramebufferImageCommand) String() string { + return fmt.Sprintf("new-screen-framebuffer-image: result: %p, width: %d, height: %d", c.result, c.width, c.height) +} + // Exec executes a newScreenFramebufferImageCommand. func (c *newScreenFramebufferImageCommand) Exec(indexOffsetInBytes int) error { checkSize(c.width, c.height) diff --git a/internal/graphics/debug_ebitendebug.go b/internal/graphics/debug_ebitendebug.go new file mode 100644 index 000000000..2615595a9 --- /dev/null +++ b/internal/graphics/debug_ebitendebug.go @@ -0,0 +1,21 @@ +// Copyright 2018 The Ebiten Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// +build ebitendebug + +package graphics + +func recordLog() bool { + return recordLog +} diff --git a/internal/graphics/debug_notebitendebug.go b/internal/graphics/debug_notebitendebug.go new file mode 100644 index 000000000..790cfc2dd --- /dev/null +++ b/internal/graphics/debug_notebitendebug.go @@ -0,0 +1,21 @@ +// Copyright 2018 The Ebiten Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// +build !ebitendebug + +package graphics + +func recordLog() bool { + return false +}