graphics: Add logging when 'ebitendebug' tag is specified

Fixes #563
This commit is contained in:
Hajime Hoshi 2018-03-05 00:45:03 +09:00
parent 1aabdd58f1
commit a03b335c24
3 changed files with 74 additions and 0 deletions

View File

@ -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)

View File

@ -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
}

View File

@ -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
}