internal/graphicsdriver/metal: call PresentDrawable only when necessary

This commit is contained in:
Hajime Hoshi 2022-02-22 01:37:13 +09:00
parent ee911fd892
commit 8b7273b74a
4 changed files with 9 additions and 5 deletions

View File

@ -293,6 +293,7 @@ func (q *commandQueue) flush() error {
} }
theGraphicsDriver.Begin() theGraphicsDriver.Begin()
var present bool
cs := q.commands cs := q.commands
for len(cs) > 0 { for len(cs) > 0 {
nv := 0 nv := 0
@ -308,6 +309,9 @@ func (q *commandQueue) flush() error {
} }
nv += dtc.numVertices() nv += dtc.numVertices()
ne += dtc.numIndices() ne += dtc.numIndices()
if dtc.dst.screen {
present = true
}
} }
nc++ nc++
} }
@ -331,7 +335,7 @@ func (q *commandQueue) flush() error {
} }
cs = cs[nc:] cs = cs[nc:]
} }
theGraphicsDriver.End() theGraphicsDriver.End(present)
// Release the commands explicitly (#1803). // Release the commands explicitly (#1803).
// Apparently, the part of a slice between len and cap-1 still holds references. // Apparently, the part of a slice between len and cap-1 still holds references.

View File

@ -46,7 +46,7 @@ type Uniform struct {
type Graphics interface { type Graphics interface {
Begin() Begin()
End() End(present bool)
SetTransparent(transparent bool) SetTransparent(transparent bool)
SetVertices(vertices []float32, indices []uint16) SetVertices(vertices []float32, indices []uint16)
NewImage(width, height int) (Image, error) NewImage(width, height int) (Image, error)

View File

@ -369,8 +369,8 @@ func (g *Graphics) Begin() {
g.pool = C.allocAutoreleasePool() g.pool = C.allocAutoreleasePool()
} }
func (g *Graphics) End() { func (g *Graphics) End(present bool) {
g.flushIfNeeded(true) g.flushIfNeeded(present)
g.screenDrawable = ca.MetalDrawable{} g.screenDrawable = ca.MetalDrawable{}
C.releaseAutoreleasePool(g.pool) C.releaseAutoreleasePool(g.pool)
g.pool = nil g.pool = nil

View File

@ -60,7 +60,7 @@ func (g *Graphics) Begin() {
// Do nothing. // Do nothing.
} }
func (g *Graphics) End() { func (g *Graphics) End(present bool) {
// Call glFlush to prevent black flicking (especially on Android (#226) and iOS). // Call glFlush to prevent black flicking (especially on Android (#226) and iOS).
// TODO: examples/sprites worked without this. Is this really needed? // TODO: examples/sprites worked without this. Is this really needed?
g.context.flush() g.context.flush()