mirror of
https://github.com/OpenSpace/OpenSpace.git
synced 2026-02-17 10:29:03 -06:00
Ability to request an OpenGL version from SGCT using commandline arguments
This commit is contained in:
@@ -53,7 +53,7 @@ namespace scripting {
|
||||
|
||||
class OpenSpaceEngine {
|
||||
public:
|
||||
static bool create(int argc, char** argv, std::vector<std::string>& sgctArguments);
|
||||
static bool create(int argc, char** argv, std::vector<std::string>& sgctArguments, std::string& openGlVersion);
|
||||
static void destroy();
|
||||
static OpenSpaceEngine& ref();
|
||||
|
||||
|
||||
@@ -24,7 +24,6 @@
|
||||
|
||||
#include <openspace/engine/openspaceengine.h>
|
||||
|
||||
// sgct
|
||||
#define SGCT_WINDOWS_INCLUDE
|
||||
#include <sgct.h>
|
||||
#include <openspace/version.h>
|
||||
@@ -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<std::string>& sgctArguments)
|
||||
bool OpenSpaceEngine::create(
|
||||
int argc, char** argv,
|
||||
std::vector<std::string>& 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<std::string>(
|
||||
&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;
|
||||
}
|
||||
|
||||
|
||||
22
src/main.cpp
22
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<std::string> 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<std::string, sgct::Engine::RunMode> 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) {
|
||||
|
||||
Reference in New Issue
Block a user