1
0
Fork 0
mirror of https://github.com/gwm17/glfw.git synced 2024-11-26 12:18:51 -05:00

Add GLFW_COCOA_GRAPHICS_SWICTHING

This provides control over whether the context should participate in
macOS Automatic Graphics Switching.

Closes #377.
Closes #935.
This commit is contained in:
Camilla Löwy 2017-01-27 12:02:09 +01:00
parent 4250725a60
commit 77a8f103d8
7 changed files with 47 additions and 0 deletions

View File

@ -133,6 +133,7 @@ information on what to include when reporting a bug.
(#749,#842)
- Added macOS specific `GLFW_COCOA_RETINA_FRAMEBUFFER` window hint
- Added macOS specific `GLFW_COCOA_FRAME_AUTOSAVE` window hint (#195)
- Added macOS specific `GLFW_COCOA_GRAPHICS_SWITCHING` window hint (#377,#935)
- Added `GLFW_INCLUDE_ES32` for including the OpenGL ES 3.2 header
- Removed `GLFW_USE_RETINA` compile-time option
- Bugfix: Calling `glfwMaximizeWindow` on a full screen window was not ignored
@ -236,6 +237,7 @@ skills.
- Cameron King
- Peter Knut
- Christoph Kubisch
- Konstantin Käfer
- Eric Larson
- Robin Leffmann
- Glenn Lewis

View File

@ -421,6 +421,23 @@ __GLFW_COCOA_FRAME_AUTOSAVE__ specifies whether to activate frame autosaving
using the window title specified at window creation. This is ignored on other
platforms.
@anchor GLFW_COCOA_GRAPHICS_SWITCHING_hint
__GLFW_COCOA_GRAPHICS_SWITCHING__ specifies whether to in Automatic Graphics
Switching, i.e. to allow the system to choose the integrated GPU for the OpenGL
context and move it between GPUs if necessary or whether to force it to always
run on the discrete GPU. This only affects systems with both integrated and
discrete GPUs. This is ignored on other platforms.
@par
Simpler programs and tools may want to enable this to save power, while games
and other applications performing advanced rendering will want to leave it
disabled.
@par
A bundled application that wishes to participate in Automatic Graphics Switching
should also declare this in its `Info.plist` by setting the
`NSSupportsAutomaticGraphicsSwitching` key to `true`.
@subsubsection window_hints_values Supported and default values
@ -461,6 +478,7 @@ GLFW_OPENGL_DEBUG_CONTEXT | `GLFW_FALSE` | `GLFW_TRUE` or `GL
GLFW_OPENGL_PROFILE | `GLFW_OPENGL_ANY_PROFILE` | `GLFW_OPENGL_ANY_PROFILE`, `GLFW_OPENGL_COMPAT_PROFILE` or `GLFW_OPENGL_CORE_PROFILE`
GLFW_COCOA_RETINA_FRAMEBUFFER | `GLFW_TRUE` | `GLFW_TRUE` or `GLFW_FALSE`
GLFW_COCOA_FRAME_AUTOSAVE | `GLFW_FALSE` | `GLFW_TRUE` or `GLFW_FALSE`
GLFW_COCOA_GRAPHICS_SWITCHING | `GLFW_FALSE` | `GLFW_TRUE` or `GLFW_FALSE`
@section window_events Window event processing

View File

@ -852,6 +852,7 @@ extern "C" {
#define GLFW_COCOA_RETINA_FRAMEBUFFER 0x00023001
#define GLFW_COCOA_FRAME_AUTOSAVE 0x00023002
#define GLFW_COCOA_GRAPHICS_SWITCHING 0x00023003
/*! @} */
#define GLFW_NO_API 0

View File

@ -340,6 +340,14 @@ static const NSRange kEmptyRange = { NSNotFound, 0 };
- (void)applicationDidChangeScreenParameters:(NSNotification *) notification
{
_GLFWwindow* window;
for (window = _glfw.windowListHead; window; window = window->next)
{
if (window->context.client != GLFW_NO_API)
[window->context.nsgl.object update];
}
_glfwPollMonitorsNS();
}

View File

@ -303,6 +303,9 @@ struct _GLFWctxconfig
int robustness;
int release;
_GLFWwindow* share;
struct {
GLFWbool offline;
} nsgl;
};
/*! @brief Framebuffer configuration.

View File

@ -160,6 +160,18 @@ GLFWbool _glfwCreateContextNSGL(_GLFWwindow* window,
ADD_ATTR(NSOpenGLPFAAccelerated);
ADD_ATTR(NSOpenGLPFAClosestPolicy);
if (ctxconfig->nsgl.offline)
{
ADD_ATTR(NSOpenGLPFAAllowOfflineRenderers);
// NOTE: This replaces the NSSupportsAutomaticGraphicsSwitching key in
// Info.plist for unbundled applications
// HACK: This assumes that NSOpenGLPixelFormat will remain
// a straightforward wrapper of its CGL counterpart
#if MAC_OS_X_VERSION_MAX_ALLOWED >= 100800
ADD_ATTR(kCGLPFASupportsAutomaticGraphicsSwitching);
#endif /*MAC_OS_X_VERSION_MAX_ALLOWED*/
}
#if MAC_OS_X_VERSION_MAX_ALLOWED >= 101000
if (ctxconfig->major >= 4)
{

View File

@ -345,6 +345,9 @@ GLFWAPI void glfwWindowHint(int hint, int value)
case GLFW_COCOA_FRAME_AUTOSAVE:
_glfw.hints.window.ns.frame = value ? GLFW_TRUE : GLFW_FALSE;
break;
case GLFW_COCOA_GRAPHICS_SWITCHING:
_glfw.hints.context.nsgl.offline = value ? GLFW_TRUE : GLFW_FALSE;
break;
case GLFW_CENTER_CURSOR:
_glfw.hints.window.centerCursor = value ? GLFW_TRUE : GLFW_FALSE;
break;