diff --git a/CMakeLists.txt b/CMakeLists.txt index 13d51d25..4e7983cb 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -18,6 +18,7 @@ option(GLFW_DOCUMENT_INTERNALS "Include internals in documentation" OFF) if (WIN32) option(GLFW_USE_DWM_SWAP_INTERVAL "Set swap interval even when DWM compositing is enabled" OFF) + option(GLFW_USE_OPTIMUS_HPG "Force use of high-performance GPU on Optimus systems" OFF) endif() if (APPLE) @@ -159,6 +160,9 @@ if (_GLFW_WIN32) if (GLFW_USE_DWM_SWAP_INTERVAL) set(_GLFW_USE_DWM_SWAP_INTERVAL 1) endif() + if (GLFW_USE_OPTIMUS_HPG) + set(_GLFW_USE_OPTIMUS_HPG 1) + endif() endif() #-------------------------------------------------------------------- diff --git a/README.md b/README.md index 8cfad847..711b9cda 100644 --- a/README.md +++ b/README.md @@ -173,6 +173,10 @@ static library version of the Visual C++ runtime library. when DWM compositing is enabled. This can lead to severe jitter and is not usually recommended. +`GLFW_USE_OPTIMUS_HPG` determines whether to export the `NvOptimusEnablement` +symbol, which forces the use of the high-performance GPU on nVidia Optimus +systems. + #### EGL specific options @@ -204,6 +208,8 @@ See the [GLFW documentation](http://www.glfw.org/docs/latest/). - Bugfix: The default for `GLFW_ALPHA_BITS` was set to zero - [Win32] Added `_GLFW_USE_DWM_SWAP_INTERVAL` for forcing the swap interval to be set even when DWM compositing is enabled + - [Win32] Added support for forcing the use of the high-performance GPU + on nVidia Optimus systems - [Win32] Bugfix: The clipboard string was not freed on terminate - [Win32] Bugfix: Entry points for OpenGL 1.0 and 1.1 functions were not returned by `glfwGetProcAddress` diff --git a/src/config.h.in b/src/config.h.in index 82af6fb9..59259661 100644 --- a/src/config.h.in +++ b/src/config.h.in @@ -55,6 +55,8 @@ #cmakedefine _GLFW_NO_DLOAD_WINMM // Define this to 1 if glfwSwapInterval should ignore DWM compositing status #cmakedefine _GLFW_USE_DWM_SWAP_INTERVAL +// Define this to 1 to force use of high-performance GPU on Optimus systems +#cmakedefine _GLFW_USE_OPTIMUS_HPG // Define this to 1 if glXGetProcAddress is available #cmakedefine _GLFW_HAS_GLXGETPROCADDRESS diff --git a/src/win32_init.c b/src/win32_init.c index dc71130d..8e0c19b0 100644 --- a/src/win32_init.c +++ b/src/win32_init.c @@ -36,6 +36,15 @@ #endif // __BORLANDC__ +#if defined(_GLFW_USE_OPTIMUS_HPG) + +// Applications exporting this symbol with this value will be automatically +// directed to the high-performance GPU on nVidia Optimus systems +// +GLFWAPI DWORD NvOptimusEnablement = 0x00000001; + +#endif // _GLFW_USE_OPTIMUS_HPG + #if defined(_GLFW_BUILD_DLL) // GLFW DLL entry point