Browse Source

Move GPU switcher to separate file

1vanK 3 years ago
parent
commit
f7b6ab89c0
2 changed files with 36 additions and 10 deletions
  1. 0 10
      Source/Urho3D/Graphics/Graphics.cpp
  2. 36 0
      Source/Urho3D/GraphicsAPI/ForceDiscreteGPU.cpp

+ 0 - 10
Source/Urho3D/Graphics/Graphics.cpp

@@ -57,16 +57,6 @@
 
 #include "../DebugNew.h"
 
-#ifdef _WIN32
-// Prefer the high-performance GPU on switchable GPU systems
-#include <windows.h>
-extern "C"
-{
-    __declspec(dllexport) DWORD NvOptimusEnablement = 1;
-    __declspec(dllexport) int AmdPowerXpressRequestHighPerformance = 1;
-}
-#endif
-
 namespace Urho3D
 {
 

+ 36 - 0
Source/Urho3D/GraphicsAPI/ForceDiscreteGPU.cpp

@@ -0,0 +1,36 @@
+//
+// Copyright (c) 2008-2022 the Urho3D project.
+//
+// Permission is hereby granted, free of charge, to any person obtaining a copy
+// of this software and associated documentation files (the "Software"), to deal
+// in the Software without restriction, including without limitation the rights
+// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+// copies of the Software, and to permit persons to whom the Software is
+// furnished to do so, subject to the following conditions:
+//
+// The above copyright notice and this permission notice shall be included in
+// all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+// THE SOFTWARE.
+//
+
+// Prefer the high-performance GPU on switchable GPU systems
+
+#ifdef _WIN32
+
+extern "C"
+{
+    // https://developer.download.nvidia.com/devzone/devcenter/gamegraphics/files/OptimusRenderingPolicies.pdf
+    __declspec(dllexport) unsigned long NvOptimusEnablement = 1;
+
+    // https://community.amd.com/t5/archives-discussions/can-an-opengl-app-default-to-the-discrete-gpu-on-an-enduro/td-p/279440
+    __declspec(dllexport) int AmdPowerXpressRequestHighPerformance = 1;
+}
+
+#endif // def _WIN32