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()
var present bool
cs := q.commands
for len(cs) > 0 {
nv := 0
@ -308,6 +309,9 @@ func (q *commandQueue) flush() error {
}
nv += dtc.numVertices()
ne += dtc.numIndices()
if dtc.dst.screen {
present = true
}
}
nc++
}
@ -331,7 +335,7 @@ func (q *commandQueue) flush() error {
}
cs = cs[nc:]
}
theGraphicsDriver.End()
theGraphicsDriver.End(present)
// Release the commands explicitly (#1803).
// 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 {
Begin()
End()
End(present bool)
SetTransparent(transparent bool)
SetVertices(vertices []float32, indices []uint16)
NewImage(width, height int) (Image, error)

View File

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

View File

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