From 2c951cf418fccbe1309c393d577ea9e0223f1420 Mon Sep 17 00:00:00 2001 From: "C. J. Howard" Date: Wed, 19 Aug 2020 01:40:15 -0700 Subject: [PATCH] Export NvOptimusEnablement global variable to signal Nvidia drivers to use high-performance graphics --- CMakeLists.txt | 12 ++++++++++++ src/platform/windows/nvidia.cpp | 27 +++++++++++++++++++++++++++ 2 files changed, 39 insertions(+) create mode 100644 src/platform/windows/nvidia.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 55db635..b80be9e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -35,7 +35,19 @@ configure_file(${PROJECT_SOURCE_DIR}/src/configuration.hpp.in file(GLOB_RECURSE SOURCE_FILES ${PROJECT_SOURCE_DIR}/src/*.cpp) +# Remove platform-specific source files +set(EXCLUDE_DIR "${PROJECT_SOURCE_DIR}/src/platform/") +foreach(TMP_PATH ${SOURCE_FILES}) + string(FIND ${TMP_PATH} ${EXCLUDE_DIR} EXCLUDE_DIR_FOUND) + if (NOT ${EXCLUDE_DIR_FOUND} EQUAL -1) + list(REMOVE_ITEM SOURCE_FILES ${TMP_PATH}) + endif () +endforeach(TMP_PATH) + if(MSVC) + # Add platform-specific source files + list(APPEND SOURCE_FILES "${PROJECT_SOURCE_DIR}/src/platform/windows/nvidia.cpp") + # Generate Windows icon resource file set(ICON_FILE "${PROJECT_SOURCE_DIR}/../antkeeper-data/src/icons/antkeeper.ico") configure_file(${PROJECT_SOURCE_DIR}/src/platform/windows/icon.rc.in diff --git a/src/platform/windows/nvidia.cpp b/src/platform/windows/nvidia.cpp new file mode 100644 index 0000000..c4b7004 --- /dev/null +++ b/src/platform/windows/nvidia.cpp @@ -0,0 +1,27 @@ +/* + * Copyright (C) 2020 Christopher J. Howard + * + * This file is part of Antkeeper source code. + * + * Antkeeper source code is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Antkeeper source code is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Antkeeper source code. If not, see . + */ + +#define WIN32_LEAN_AND_MEAN +#include + +// Direct Nvidia Optimus to use high-performance graphics +extern "C" +{ + _declspec(dllexport) DWORD NvOptimusEnablement = 0x00000001; +}