强制硬件加速渲染 [英] Forcing hardware accelerated rendering
问题描述
我有一个用C ++编写的OpenGL库,可从使用C ++/CLI适配器的C#应用程序中使用.我的问题是,如果该应用程序在采用Nvidia Optimus技术的笔记本电脑上使用,则该应用程序将不会使用硬件加速,并且会失败.
I have an OpenGL library written in c++ that is used from a C# application using C++/CLI adapters. My problem is that if the application is used on laptops with Nvidia Optimus technology the application will not use the hardware acceleration and fail.
我试图使用Nvidias文档 http://developer中的信息. download.nvidia.com/devzone/devcenter/gamegraphics/files/OptimusRenderingPolicies.pdf 关于将库链接到我的C ++-dll并从我的OpenGL库中导出NvOptimusEnablement,但这失败了. 我想我必须对.exe进行某些处理,而不要对链接到.exe的.dll进行处理
I have tried to use the info found in Nvidias document http://developer.download.nvidia.com/devzone/devcenter/gamegraphics/files/OptimusRenderingPolicies.pdf about linking libs to my C++-dll and exporting NvOptimusEnablement from my OpenGL-library but that fails. I guess I have to do something with the .exe not with the .dlls linked to the .exe
对于我们来说,使用配置文件不是一个好的选择,因为我们需要确保使用了nvidia硬件.
For us it is not a good option to use profiles since we need to ensure that the nvidia hardware is used.
C#应用程序是否有某种方式可以迫使Optimus使用Nvidia芯片组而不是集成的Intel芯片组?
Is there some way a C# application can force Optimus to use the Nvidia chipset instead of the integrated Intel chipset?
推荐答案
有效的解决方案.实际上所有这些都已经提到过,但是我花了一些时间来了解如何使其工作起来……
A working solution. Actually all those already mentioned, but it took me a time to understand how to get it work...
[System.Runtime.InteropServices.DllImport("nvapi64.dll", EntryPoint = "fake")]
static extern int LoadNvApi64();
[System.Runtime.InteropServices.DllImport("nvapi.dll", EntryPoint = "fake")]
static extern int LoadNvApi32();
private void InitializeDedicatedGraphics()
{
try
{
if (Environment.Is64BitProcess)
LoadNvApi64();
else
LoadNvApi32();
}
catch { } // will always fail since 'fake' entry point doesn't exists
}
重要-在创建任何窗口之前调用InitializeDedicatedGraphics()
Important - call InitializeDedicatedGraphics()
before any window is created
这篇关于强制硬件加速渲染的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!