mirror of
https://github.com/OpenSpace/OpenSpace.git
synced 2026-02-19 11:29:08 -06:00
Replace commandline argument with automatically detecting the supported OpenGL version
This commit is contained in:
@@ -59,7 +59,7 @@ namespace scripting {
|
||||
|
||||
class OpenSpaceEngine {
|
||||
public:
|
||||
static bool create(int argc, char** argv, std::vector<std::string>& sgctArguments, std::string& openGlVersion);
|
||||
static bool create(int argc, char** argv, std::vector<std::string>& sgctArguments);
|
||||
static void destroy();
|
||||
static OpenSpaceEngine& ref();
|
||||
|
||||
|
||||
@@ -96,7 +96,6 @@ namespace {
|
||||
struct {
|
||||
std::string configurationName;
|
||||
std::string sgctConfigurationName;
|
||||
std::string openGlVersion;
|
||||
} commandlineArgumentPlaceholders;
|
||||
}
|
||||
|
||||
@@ -148,8 +147,7 @@ OpenSpaceEngine& OpenSpaceEngine::ref() {
|
||||
|
||||
bool OpenSpaceEngine::create(
|
||||
int argc, char** argv,
|
||||
std::vector<std::string>& sgctArguments,
|
||||
std::string& openGlVersion)
|
||||
std::vector<std::string>& sgctArguments)
|
||||
{
|
||||
ghoul::initialize();
|
||||
|
||||
@@ -260,10 +258,6 @@ bool OpenSpaceEngine::create(
|
||||
sgctConfigurationPath = commandlineArgumentPlaceholders.sgctConfigurationName;
|
||||
}
|
||||
|
||||
openGlVersion = commandlineArgumentPlaceholders.openGlVersion;
|
||||
if (openGlVersion != DefaultOpenGlVersion)
|
||||
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]);
|
||||
@@ -401,13 +395,6 @@ bool OpenSpaceEngine::gatherCommandlineArguments() {
|
||||
"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;
|
||||
}
|
||||
|
||||
|
||||
44
src/main.cpp
44
src/main.cpp
@@ -47,6 +47,21 @@ void mainDecodeFun();
|
||||
void mainExternalControlCallback(const char * receivedChars, int size);
|
||||
void mainLogCallback(const char* msg);
|
||||
|
||||
std::pair<int, int> supportedOpenGLVersion () {
|
||||
glfwInit();
|
||||
glfwWindowHint(GLFW_VISIBLE, GL_FALSE);
|
||||
GLFWwindow* offscreen = glfwCreateWindow(128, 128, "", nullptr, nullptr);
|
||||
glfwMakeContextCurrent(offscreen);
|
||||
|
||||
int major, minor;
|
||||
glGetIntegerv(GL_MAJOR_VERSION, &major);
|
||||
glGetIntegerv(GL_MINOR_VERSION, &minor);
|
||||
|
||||
glfwDestroyWindow(offscreen);
|
||||
glfwWindowHint(GLFW_VISIBLE, GL_TRUE);
|
||||
return { major, minor };
|
||||
}
|
||||
|
||||
//temporary post-FX functions, TODO make a more permanent solution to this @JK
|
||||
void postFXPass();
|
||||
void setupPostFX();
|
||||
@@ -60,13 +75,13 @@ namespace {
|
||||
}
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
auto glVersion = supportedOpenGLVersion();
|
||||
|
||||
// create the OpenSpace engine and get arguments for the sgct engine
|
||||
std::vector<std::string> sgctArguments;
|
||||
std::string openGlVersion = "";
|
||||
const bool success = openspace::OpenSpaceEngine::create(
|
||||
argc, argv,
|
||||
sgctArguments,
|
||||
openGlVersion
|
||||
sgctArguments
|
||||
);
|
||||
if (!success)
|
||||
return EXIT_FAILURE;
|
||||
@@ -115,21 +130,20 @@ int main(int argc, char** argv) {
|
||||
|
||||
// try to open a window
|
||||
LDEBUG("Initialize SGCT Engine");
|
||||
#ifdef __APPLE__
|
||||
sgct::Engine::RunMode rm = sgct::Engine::RunMode::OpenGL_4_1_Core_Profile;
|
||||
#else
|
||||
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 }
|
||||
std::map<std::pair<int, int>, sgct::Engine::RunMode> versionMapping = {
|
||||
{ { 3, 3 }, sgct::Engine::RunMode::OpenGL_3_3_Core_Profile },
|
||||
{ { 4, 0 }, sgct::Engine::RunMode::OpenGL_4_0_Core_Profile },
|
||||
{ { 4, 1 }, sgct::Engine::RunMode::OpenGL_4_1_Core_Profile },
|
||||
{ { 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");
|
||||
if (versionMapping.find(glVersion) == versionMapping.end()) {
|
||||
LFATAL("Requested OpenGL version " << glVersion.first << "." << glVersion.second << " not supported");
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
sgct::Engine::RunMode rm = versionMapping[openGlVersion];
|
||||
#endif
|
||||
sgct::Engine::RunMode rm = versionMapping[glVersion];
|
||||
const bool initSuccess = _sgctEngine->init(rm);
|
||||
if (!initSuccess) {
|
||||
LFATAL("Initializing failed");
|
||||
|
||||
Reference in New Issue
Block a user