Skip to content

Instantly share code, notes, and snippets.

@ryandesign
Created June 29, 2018 21:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ryandesign/6072766bdb0d74e895bd59826a2fb51c to your computer and use it in GitHub Desktop.
Save ryandesign/6072766bdb0d74e895bd59826a2fb51c to your computer and use it in GitHub Desktop.
Patch to prevent Mini vMac from forcing the use of the discrete GPU, in two-GPU Macs
https://developer.apple.com/library/archive/technotes/tn2229/
--- src/Info.plist.orig 2018-06-22 00:41:55.000000000 -0500
+++ src/Info.plist 2018-06-29 13:12:51.000000000 -0500
@@ -3,4 +3,6 @@
<plist version="1.0">
<dict>
+ <key>NSSupportsAutomaticGraphicsSwitching</key>
+ <true/>
<key>CFBundleDevelopmentRegion</key>
<string>English</string>
--- src/OSGLUCCO.m.orig 2018-06-09 03:53:21.000000000 -0500
+++ src/OSGLUCCO.m 2018-06-22 06:33:03.000000000 -0500
@@ -51,6 +51,8 @@
typedef struct __CFError * CFErrorRef;
+#define NSOpenGLPFAAllowOfflineRenderers (NSOpenGLPixelFormatAttribute)96
+
#endif
#if MAC_OS_X_VERSION_10_6 > MAC_OS_X_VERSION_MAX_ALLOWED
@@ -3160,2 +3162,3 @@
NSOpenGLPixelFormatAttribute attr[] = {
+ NSOpenGLPFAAllowOfflineRenderers,
0};
@@ -3164,2 +3167,9 @@
fmt = [[NSOpenGLPixelFormat alloc] initWithAttributes:attr];
+#if MAC_OS_X_VERSION_10_5 > MAC_OS_X_VERSION_MIN_REQUIRED
+ if (nil == fmt) {
+ /* NSOpenGLPFAAllowOfflineRenderers is not supported; remove it */
+ attr[0] = (NSOpenGLPixelFormatAttribute)0;
+ fmt = [[NSOpenGLPixelFormat alloc] initWithAttributes:attr];
+ }
+#endif
if (nil == fmt) {
--- src/OSGLUOSX.c.orig 2018-05-25 02:41:10.000000000 -0500
+++ src/OSGLUOSX.c 2018-06-29 15:09:38.000000000 -0500
@@ -36,4 +36,14 @@
/* --- adapting to API/ABI version differences --- */
+#ifndef MAC_OS_X_VERSION_10_5
+#define MAC_OS_X_VERSION_10_5 1050
+#endif
+
+#if MAC_OS_X_VERSION_10_5 > MAC_OS_X_VERSION_MAX_ALLOWED
+
+#define AGL_ALLOW_OFFLINE_RENDERERS 96
+
+#endif
+
/*
if UsingCarbonLib, instead of native Macho,
@@ -2719,5 +2731,12 @@
&& HaveMyCGDisplayPixelsHigh())
{
- static const GLint fullscreen_attrib[] = {AGL_RGBA,
+#if MAC_OS_X_VERSION_10_5 > MAC_OS_X_VERSION_MIN_REQUIRED
+ GLenum err;
+#endif
+ static
+#if MAC_OS_X_VERSION_10_5 <= MAC_OS_X_VERSION_MIN_REQUIRED
+ const
+#endif
+ GLint fullscreen_attrib[] = {AGL_RGBA,
AGL_NO_RECOVERY,
AGL_FULLSCREEN,
@@ -2726,4 +2745,5 @@
AGL_DOUBLEBUFFER,
#endif
+ AGL_ALLOW_OFFLINE_RENDERERS,
AGL_NONE};
GDHandle theDevice;
@@ -2734,4 +2754,16 @@
fullscreen_fmt = aglChoosePixelFormat(
&theDevice, 1, fullscreen_attrib);
+#if MAC_OS_X_VERSION_10_5 > MAC_OS_X_VERSION_MIN_REQUIRED
+ err = aglGetError();
+ if (AGL_BAD_ATTRIBUTE == err || NULL == fullscreen_fmt) {
+ /* AGL_ALLOW_OFFLINE_RENDERERS is not supported; remove it */
+ fullscreen_attrib[5
+#if UseAGLdoublebuff
+ + 1
+#endif
+ ] = AGL_NONE;
+ fullscreen_fmt = aglChoosePixelFormat(&theDevice, 1, fullscreen_attrib);
+ }
+#endif
if (NULL == fullscreen_fmt) {
/* err = aglReportError() */
@@ -4229,9 +4261,17 @@
if (MyCreateNewWindow(&NewWinRect, &gMyMainWindow)) {
- static const GLint window_attrib[] = {AGL_RGBA,
+#if MAC_OS_X_VERSION_10_5 > MAC_OS_X_VERSION_MIN_REQUIRED
+ GLenum err;
+#endif
+ static
+#if MAC_OS_X_VERSION_10_5 <= MAC_OS_X_VERSION_MIN_REQUIRED
+ const
+#endif
+ GLint window_attrib[] = {AGL_RGBA,
#if UseAGLdoublebuff
AGL_DOUBLEBUFFER,
#endif
/* AGL_DEPTH_SIZE, 16, */
+ AGL_ALLOW_OFFLINE_RENDERERS,
AGL_NONE};
@@ -4241,4 +4281,16 @@
window_fmt = aglChoosePixelFormat(NULL, 0, window_attrib);
+#if MAC_OS_X_VERSION_10_5 > MAC_OS_X_VERSION_MIN_REQUIRED
+ err = aglGetError();
+ if (AGL_BAD_ATTRIBUTE == err || NULL == window_fmt) {
+ /* AGL_ALLOW_OFFLINE_RENDERERS is not supported; remove it */
+ window_attrib[1
+#if UseAGLdoublebuff
+ + 1
+#endif
+ ] = AGL_NONE;
+ window_fmt = aglChoosePixelFormat(NULL, 0, window_attrib);
+ }
+#endif
if (NULL == window_fmt) {
/* err = aglReportError() */
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment