Skip to content

Commit

Permalink
internal/graphicsdriver/metal: Bug fix: Vsync didn't work on macOS
Browse files Browse the repository at this point in the history
This fix works only for Metal. There is not a good solution for
OpenGL so far unfortunately.

Closes hajimehoshi#1885
  • Loading branch information
hajimehoshi committed Nov 26, 2021
1 parent b7cd990 commit 1dd13ae
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions internal/graphicsdriver/metal/view_macos.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,24 @@

package metal

// #cgo CFLAGS: -x objective-c
// #cgo LDFLAGS: -framework Foundation
//
// #import <Foundation/Foundation.h>
//
// static int getMacOSMajorVersion() {
// NSOperatingSystemVersion version = [[NSProcessInfo processInfo] operatingSystemVersion];
// return (int)version.majorVersion;
// }
import "C"

import (
"github.com/hajimehoshi/ebiten/v2/internal/graphicsdriver/metal/mtl"
"github.com/hajimehoshi/ebiten/v2/internal/graphicsdriver/metal/ns"
)

var macOSMajorVersion = int(C.getMacOSMajorVersion())

func (v *view) setWindow(window uintptr) {
// NSView can be updated e.g., fullscreen-state is switched.
v.window = window
Expand All @@ -44,6 +57,12 @@ func (v *view) update() {
}

func (v *view) usePresentsWithTransaction() bool {
// On macOS 12 (or later), do not use presentsWithTransaction, or vsync doesn't work (#1885).
// This works only for Metal. Unfortunately, there is not a good solution for OpenGL.
if macOSMajorVersion >= 12 {
return false
}

// Disable presentsWithTransaction on the fullscreen mode (#1745).
return !v.vsyncDisabled
}
Expand Down

0 comments on commit 1dd13ae

Please sign in to comment.