mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2025-09-26 20:11:28 +08:00
internal/graphicsdriver/metal: refactoring
This commit is contained in:
@@ -860,7 +860,6 @@ func (i *Image) mtlTexture() mtl.Texture {
|
||||
if i.screen {
|
||||
g := i.graphics
|
||||
if g.screenDrawable == (ca.MetalDrawable{}) {
|
||||
i.graphics.view.waitForDisplayLinkOutputCallback()
|
||||
drawable := g.view.nextDrawable()
|
||||
if drawable == (ca.MetalDrawable{}) {
|
||||
return mtl.Texture{}
|
||||
|
@@ -97,20 +97,11 @@ func (v *view) initialize(device mtl.Device, colorSpace graphicsdriver.ColorSpac
|
||||
|
||||
v.ml.SetMaximumDrawableCount(maximumDrawableCount)
|
||||
|
||||
v.initializeDisplayLink()
|
||||
v.initializeOS()
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (v *view) nextDrawable() ca.MetalDrawable {
|
||||
d, err := v.ml.NextDrawable()
|
||||
if err != nil {
|
||||
// Drawable is nil. This can happen at the initial state. Let's wait and see.
|
||||
return ca.MetalDrawable{}
|
||||
}
|
||||
return d
|
||||
}
|
||||
|
||||
type fence struct {
|
||||
value uint64
|
||||
lastValue uint64
|
||||
|
@@ -39,6 +39,7 @@ import "C"
|
||||
import (
|
||||
"unsafe"
|
||||
|
||||
"github.com/hajimehoshi/ebiten/v2/internal/graphicsdriver/metal/ca"
|
||||
"github.com/hajimehoshi/ebiten/v2/internal/graphicsdriver/metal/mtl"
|
||||
)
|
||||
|
||||
@@ -65,10 +66,15 @@ const (
|
||||
resourceStorageMode = mtl.ResourceStorageModeShared
|
||||
)
|
||||
|
||||
func (v *view) initializeDisplayLink() {
|
||||
// Do nothing.
|
||||
func (v *view) nextDrawable() ca.MetalDrawable {
|
||||
d, err := v.ml.NextDrawable()
|
||||
if err != nil {
|
||||
// Drawable is nil. This can happen at the initial state. Let's wait and see.
|
||||
return ca.MetalDrawable{}
|
||||
}
|
||||
return d
|
||||
}
|
||||
|
||||
func (v *view) waitForDisplayLinkOutputCallback() {
|
||||
func (v *view) initializeOS() {
|
||||
// Do nothing.
|
||||
}
|
||||
|
@@ -28,6 +28,7 @@ import (
|
||||
"github.com/ebitengine/purego/objc"
|
||||
|
||||
"github.com/hajimehoshi/ebiten/v2/internal/cocoa"
|
||||
"github.com/hajimehoshi/ebiten/v2/internal/graphicsdriver/metal/ca"
|
||||
"github.com/hajimehoshi/ebiten/v2/internal/graphicsdriver/metal/mtl"
|
||||
)
|
||||
|
||||
@@ -61,7 +62,7 @@ const (
|
||||
resourceStorageMode = mtl.ResourceStorageModeManaged
|
||||
)
|
||||
|
||||
func (v *view) initializeDisplayLink() {
|
||||
func (v *view) initializeOS() {
|
||||
v.fence = newFence()
|
||||
|
||||
// TODO: CVDisplayLink APIs are deprecated in macOS 10.15 and later.
|
||||
@@ -97,3 +98,16 @@ func ebitengine_DisplayLinkOutputCallback(displayLinkRef C.CVDisplayLinkRef, inN
|
||||
view.fence.advance()
|
||||
return 0
|
||||
}
|
||||
|
||||
func (v *view) nextDrawable() ca.MetalDrawable {
|
||||
// TODO: Use CAMetalDisplayLink if available.
|
||||
|
||||
v.waitForDisplayLinkOutputCallback()
|
||||
|
||||
d, err := v.ml.NextDrawable()
|
||||
if err != nil {
|
||||
// Drawable is nil. This can happen at the initial state. Let's wait and see.
|
||||
return ca.MetalDrawable{}
|
||||
}
|
||||
return d
|
||||
}
|
||||
|
Reference in New Issue
Block a user