diff --git a/include/openspace/engine/openspaceengine.h b/include/openspace/engine/openspaceengine.h index ab451bfbbc..e6ce8570a7 100644 --- a/include/openspace/engine/openspaceengine.h +++ b/include/openspace/engine/openspaceengine.h @@ -53,7 +53,7 @@ namespace scripting { class OpenSpaceEngine { public: - static bool create(int argc, char** argv, std::vector& sgctArguments); + static bool create(int argc, char** argv, std::vector& sgctArguments, std::string& openGlVersion); static void destroy(); static OpenSpaceEngine& ref(); diff --git a/src/engine/openspaceengine.cpp b/src/engine/openspaceengine.cpp index 5e8869241c..d0943d82bc 100644 --- a/src/engine/openspaceengine.cpp +++ b/src/engine/openspaceengine.cpp @@ -24,7 +24,6 @@ #include -// sgct #define SGCT_WINDOWS_INCLUDE #include #include @@ -73,10 +72,13 @@ namespace { const std::string _defaultCacheLocation = "${BASE_PATH}/cache"; const std::string _sgctConfigArgumentCommand = "-config"; + + const std::string DefaultOpenGlVersion = "4.3"; struct { std::string configurationName; std::string sgctConfigurationName; + std::string openGlVersion; } commandlineArgumentPlaceholders; } @@ -123,8 +125,10 @@ OpenSpaceEngine& OpenSpaceEngine::ref() { return *_engine; } -bool OpenSpaceEngine::create(int argc, char** argv, - std::vector& sgctArguments) +bool OpenSpaceEngine::create( + int argc, char** argv, + std::vector& sgctArguments, + std::string& openGlVersion) { assert(_engine == nullptr); @@ -225,6 +229,9 @@ bool OpenSpaceEngine::create(int argc, char** argv, sgctConfigurationPath = commandlineArgumentPlaceholders.sgctConfigurationName; } + openGlVersion = commandlineArgumentPlaceholders.openGlVersion; + LINFO("Using OpenGL version " << openGlVersion); + // Prepend the outgoing sgctArguments with the program name // as well as the configuration file that sgct is supposed to use sgctArguments.insert(sgctArguments.begin(), argv[0]); @@ -354,7 +361,14 @@ bool OpenSpaceEngine::gatherCommandlineArguments() { "Provides the path to the SGCT configuration file, overriding the value set in" "the OpenSpace configuration file"); _commandlineParser->addCommand(sgctConfigFileCommand); - + + commandlineArgumentPlaceholders.openGlVersion = DefaultOpenGlVersion; + CommandlineCommand* openGlVersionCommand = new SingleCommand( + &commandlineArgumentPlaceholders.openGlVersion, + "-ogl", "-o", + "Sets the OpenGL version that is to be used; valid values are '4.2' and '4.3'"); + _commandlineParser->addCommand(openGlVersionCommand); + return true; } diff --git a/src/main.cpp b/src/main.cpp index d82e715002..86a3dfdf2a 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -56,11 +56,15 @@ namespace { const std::string _loggerCat = "main"; } -int main(int argc, char** argv) -{ +int main(int argc, char** argv) { // create the OpenSpace engine and get arguments for the sgct engine std::vector sgctArguments; - const bool success = openspace::OpenSpaceEngine::create(argc, argv, sgctArguments); + std::string openGlVersion = ""; + const bool success = openspace::OpenSpaceEngine::create( + argc, argv, + sgctArguments, + openGlVersion + ); if (!success) return EXIT_FAILURE; @@ -105,7 +109,17 @@ int main(int argc, char** argv) #ifdef __APPLE__ sgct::Engine::RunMode rm = sgct::Engine::RunMode::OpenGL_4_1_Core_Profile; #else - sgct::Engine::RunMode rm = sgct::Engine::RunMode::OpenGL_4_3_Core_Profile; + std::map versionMapping = { + { "4.2", sgct::Engine::RunMode::OpenGL_4_2_Core_Profile }, + { "4.3", sgct::Engine::RunMode::OpenGL_4_3_Core_Profile }, + { "4.4", sgct::Engine::RunMode::OpenGL_4_4_Core_Profile }, + { "4.5", sgct::Engine::RunMode::OpenGL_4_5_Core_Profile } + }; + if (versionMapping.find(openGlVersion) == versionMapping.end()) { + LFATAL("Requested OpenGL version " << openGlVersion << " not supported"); + return EXIT_FAILURE; + } + sgct::Engine::RunMode rm = versionMapping[openGlVersion]; #endif const bool initSuccess = _sgctEngine->init(rm); if (!initSuccess) {