50 lines
1.3 KiB
C++
50 lines
1.3 KiB
C++
#include "export.h"
|
|
#include <windows.h>
|
|
#include "nvapi.h"
|
|
#include "NvApiDriverSettings.h"
|
|
#include <iostream>
|
|
|
|
extern "C" bool ForceNvidiaNativePresent() {
|
|
// 初始化NvAPI
|
|
auto status = NvAPI_Initialize();
|
|
if (status != NVAPI_OK) {
|
|
return false; // 不是N卡或初始化失败
|
|
}
|
|
|
|
NvDRSSessionHandle hSession = 0;
|
|
status = NvAPI_DRS_CreateSession(&hSession);
|
|
if (status != NVAPI_OK) {
|
|
return false;
|
|
}
|
|
|
|
status = NvAPI_DRS_LoadSettings(hSession);
|
|
if (status != NVAPI_OK) {
|
|
NvAPI_DRS_DestroySession(hSession);
|
|
return false;
|
|
}
|
|
|
|
NvDRSProfileHandle hProfile = 0;
|
|
// 获取当前应用程序的配置(如果没有会自动创建默认配置)
|
|
status = NvAPI_DRS_GetBaseProfile(hSession, &hProfile);
|
|
if (status != NVAPI_OK) {
|
|
NvAPI_DRS_DestroySession(hSession);
|
|
return false;
|
|
}
|
|
|
|
NVDRS_SETTING setting = {0};
|
|
setting.version = NVDRS_SETTING_VER;
|
|
setting.settingId = OGL_CPL_PREFER_DXPRESENT_ID;
|
|
setting.u32CurrentValue = OGL_CPL_PREFER_DXPRESENT_PREFER_DISABLED; // 强制设为 Native
|
|
|
|
// 应用设置
|
|
status = NvAPI_DRS_SetSetting(hSession, hProfile, &setting);
|
|
if (status == NVAPI_OK) {
|
|
NvAPI_DRS_SaveSettings(hSession);
|
|
NvAPI_DRS_DestroySession(hSession);
|
|
return true;
|
|
}
|
|
|
|
NvAPI_DRS_DestroySession(hSession);
|
|
return false;
|
|
}
|