diff --git a/include/osg/DisplaySettings b/include/osg/DisplaySettings index c4b03e4ab..7bc324d0a 100644 --- a/include/osg/DisplaySettings +++ b/include/osg/DisplaySettings @@ -293,6 +293,11 @@ class OSG_EXPORT DisplaySettings : public osg::Referenced /** Get the hint of the profile mask to use in when creating graphic contexts.*/ unsigned int getGLContextProfileMask() const { return _glContextProfileMask; } + /** Set the NvOptimusEnablement value. Default can be set using OSG_NvOptimusEnablement env var.*/ + void setNvOptimusEnablement(int value); + /** Get the NvOptimusEnablement value. */ + int getNvOptimusEnablement() const; + void setKeystoneHint(bool enabled) { _keystoneHint = enabled; } bool getKeystoneHint() const { return _keystoneHint; } diff --git a/src/osg/DisplaySettings.cpp b/src/osg/DisplaySettings.cpp index de261b665..4e7ddbc83 100644 --- a/src/osg/DisplaySettings.cpp +++ b/src/osg/DisplaySettings.cpp @@ -23,12 +23,30 @@ using namespace osg; using namespace std; +#if defined(WIN32) && !defined(__CYGWIN__) +extern "C" { _declspec(dllexport) DWORD NvOptimusEnablement=0x00000001; } +#else +extern "C" { int NvOptimusEnablement=0x00000001; } +#endif + +void DisplaySettings::setNvOptimusEnablement(int value) +{ + NvOptimusEnablement = value; +} + +int DisplaySettings::getNvOptimusEnablement() const +{ + return NvOptimusEnablement; +} + ref_ptr& DisplaySettings::instance() { static ref_ptr s_displaySettings = new DisplaySettings; return s_displaySettings; } +OSG_INIT_SINGLETON_PROXY(ProxyInitDisplaySettings, DisplaySettings::instance()) + DisplaySettings::DisplaySettings(const DisplaySettings& vs):Referenced(true) { setDisplaySettings(vs); @@ -334,10 +352,12 @@ static ApplicationUsageProxy DisplaySetting_e28(ApplicationUsage::ENVIRONMENTAL_ static ApplicationUsageProxy DisplaySetting_e29(ApplicationUsage::ENVIRONMENTAL_VARIABLE, "OSG_KEYSTONE_FILES [:filename]..", "Specify filenames of keystone parameter files. Under Windows use ; to deliminate files, otherwise use :"); - static ApplicationUsageProxy DisplaySetting_e30(ApplicationUsage::ENVIRONMENTAL_VARIABLE, "OSG_MENUBAR_BEHAVIOR ", "OSX Only : Specify the behavior of the menubar (AUTO_HIDE, FORCE_HIDE, FORCE_SHOW)"); +static ApplicationUsageProxy DisplaySetting_e31(ApplicationUsage::ENVIRONMENTAL_VARIABLE, + "OSG_NvOptimusEnablement ", + "Set the hint to NvOptimus of whether to enable it or not, set 1 to enable, 0 to disable"); void DisplaySettings::readEnvironmentalVariables() { @@ -704,6 +724,11 @@ void DisplaySettings::readEnvironmentalVariables() _OSXMenubarBehavior = MENUBAR_FORCE_SHOW; } } + + if( (ptr = getenv("OSG_NvOptimusEnablement")) != 0) + { + setNvOptimusEnablement(atoi(ptr)); + } } void DisplaySettings::readCommandLine(ArgumentParser& arguments)