diff --git a/src/PrusaSlicer.cpp b/src/PrusaSlicer.cpp index 87e61ec5de..ecb1572185 100644 --- a/src/PrusaSlicer.cpp +++ b/src/PrusaSlicer.cpp @@ -173,19 +173,20 @@ int CLI::run(int argc, char **argv) m_actions.erase(it); } - it = std::find(m_actions.begin(), m_actions.end(), "opengl-core"); + it = std::find(m_actions.begin(), m_actions.end(), "opengl-version"); if (it != m_actions.end()) { - std::string opengl_version_str = m_config.opt_string("opengl-core"); - const std::vector valid_versions = { "3.2", "3.3", "4.0", "4.1", "4.2", "4.3", "4.4", "4.5", "4.6" }; - if (std::find(valid_versions.begin(), valid_versions.end(), opengl_version_str) == valid_versions.end()) { - boost::nowide::cerr << "Found invalid OpenGL version: " << opengl_version_str << std::endl; - opengl_version_str.clear(); + std::string opengl_version_str = m_config.opt_string("opengl-version"); + if (std::find(Slic3r::GUI::OpenGLVersions::core_str.begin(), Slic3r::GUI::OpenGLVersions::core_str.end(), opengl_version_str) == Slic3r::GUI::OpenGLVersions::core_str.end()) { + if (std::find(Slic3r::GUI::OpenGLVersions::precore_str.begin(), Slic3r::GUI::OpenGLVersions::precore_str.end(), opengl_version_str) == Slic3r::GUI::OpenGLVersions::precore_str.end()) { + boost::nowide::cerr << "Found invalid OpenGL version: " << opengl_version_str << std::endl; + opengl_version_str.clear(); + } } if (!opengl_version_str.empty()) { std::vector tokens; boost::split(tokens, opengl_version_str, boost::is_any_of("."), boost::token_compress_on); - opengl_version.first = std::stoi(tokens[0].c_str()); + opengl_version.first = std::stoi(tokens[0].c_str()); opengl_version.second = std::stoi(tokens[1].c_str()); } start_gui = true; diff --git a/src/libslic3r/PrintConfig.cpp b/src/libslic3r/PrintConfig.cpp index 945722ba4d..d58b5553a6 100644 --- a/src/libslic3r/PrintConfig.cpp +++ b/src/libslic3r/PrintConfig.cpp @@ -4305,10 +4305,10 @@ CLIActionsConfigDef::CLIActionsConfigDef() def->set_default_value(new ConfigOptionBool(false)); #if ENABLE_GL_CORE_PROFILE - def = this->add("opengl-core", coString); - def->label = L("OpenGL core version"); - def->tooltip = L("Select the specified OpenGL version supporting core profile"); - def->cli = "opengl-core"; + def = this->add("opengl-version", coString); + def->label = L("OpenGL version"); + def->tooltip = L("Select the specified OpenGL version"); + def->cli = "opengl-version"; def->set_default_value(new ConfigOptionString()); def = this->add("opengl-debug", coBool); diff --git a/src/slic3r/GUI/GUI_Init.cpp b/src/slic3r/GUI/GUI_Init.cpp index 6b7e38aa0a..5b5cca7dc4 100644 --- a/src/slic3r/GUI/GUI_Init.cpp +++ b/src/slic3r/GUI/GUI_Init.cpp @@ -26,6 +26,12 @@ namespace Slic3r { namespace GUI { +const std::vector OpenGLVersions::core_str = { "3.2", "3.3", "4.0", "4.1", "4.2", "4.3", "4.4", "4.5", "4.6" }; +const std::vector OpenGLVersions::precore_str = { "2.0", "2.1", "3.0", "3.1" }; + +const std::vector> OpenGLVersions::core = { {3,2}, {3,3}, {4,0}, {4,1}, {4,2}, {4,3}, {4,4}, {4,5}, {4,6} }; +const std::vector> OpenGLVersions::precore = { {2,0}, {2,1}, {3,0}, {3,1} }; + int GUI_Run(GUI_InitParams ¶ms) { #if __APPLE__ diff --git a/src/slic3r/GUI/GUI_Init.hpp b/src/slic3r/GUI/GUI_Init.hpp index d3ababe241..878edc1d97 100644 --- a/src/slic3r/GUI/GUI_Init.hpp +++ b/src/slic3r/GUI/GUI_Init.hpp @@ -8,6 +8,15 @@ namespace Slic3r { namespace GUI { +struct OpenGLVersions +{ + static const std::vector core_str; + static const std::vector precore_str; + + static const std::vector> core; + static const std::vector> precore; +}; + struct GUI_InitParams { int argc; diff --git a/src/slic3r/GUI/OpenGLManager.cpp b/src/slic3r/GUI/OpenGLManager.cpp index 339abe3010..90a8bd9d74 100644 --- a/src/slic3r/GUI/OpenGLManager.cpp +++ b/src/slic3r/GUI/OpenGLManager.cpp @@ -2,6 +2,9 @@ #include "OpenGLManager.hpp" #include "GUI.hpp" +#if ENABLE_GL_CORE_PROFILE +#include "GUI_Init.hpp" +#endif // ENABLE_GL_CORE_PROFILE #include "I18N.hpp" #include "3DScene.hpp" @@ -416,48 +419,60 @@ wxGLContext* OpenGLManager::init_glcontext(wxGLCanvas& canvas) m_debug_enabled = enable_debug; #endif // ENABLE_OPENGL_DEBUG_OPTION - if (required_opengl_version != std::make_pair(0, 0)) { // the user specified a required version in the command line using --opengl-core=M.m - const bool supports_core_profile = (required_opengl_version.first < 3) ? false : - (required_opengl_version.first > 3) ? true : required_opengl_version.second >= 2; + const int gl_major = required_opengl_version.first; + const int gl_minor = required_opengl_version.second; + const bool supports_core_profile = (gl_major < 3) ? false : (gl_major > 3) ? true : gl_minor >= 2; + + if (gl_major == 0) { + // search for highest supported core profile version + // disable wxWidgets logging to avoid showing the log dialog in case the following code fails generating a valid gl context + wxLogNull logNo; + for (auto v = OpenGLVersions::core.rbegin(); v != OpenGLVersions::core.rend(); ++v) { + wxGLContextAttrs attrs; +#if ENABLE_OPENGL_DEBUG_OPTION + attrs.MajorVersion(v->first).MinorVersion(v->second).CoreProfile().ForwardCompatible(); + if (m_debug_enabled) + attrs.DebugCtx(); + attrs.EndList(); +#else + attrs.MajorVersion(gl_major).MinorVersion(gl_minor).CoreProfile().ForwardCompatible().EndList(); +#endif // ENABLE_OPENGL_DEBUG_OPTION + m_context = new wxGLContext(&canvas, nullptr, &attrs); + if (m_context->IsOK()) { + s_gl_info.set_core_profile(true); + break; + } + else { + delete m_context; + m_context = nullptr; + } + } + } + + if (m_context == nullptr) { + // search for requested core profile version if (supports_core_profile) { // disable wxWidgets logging to avoid showing the log dialog in case the following code fails generating a valid gl context wxLogNull logNo; wxGLContextAttrs attrs; #if ENABLE_OPENGL_DEBUG_OPTION - attrs.MajorVersion(required_opengl_version.first).MinorVersion(required_opengl_version.second).CoreProfile().ForwardCompatible(); + attrs.MajorVersion(gl_major).MinorVersion(gl_minor).CoreProfile().ForwardCompatible(); if (m_debug_enabled) attrs.DebugCtx(); attrs.EndList(); #else - attrs.MajorVersion(required_opengl_version.first).MinorVersion(required_opengl_version.second).CoreProfile().ForwardCompatible().EndList(); + attrs.MajorVersion(gl_major).MinorVersion(gl_minor).CoreProfile().ForwardCompatible().EndList(); #endif // ENABLE_OPENGL_DEBUG_OPTION m_context = new wxGLContext(&canvas, nullptr, &attrs); if (!m_context->IsOK()) { - BOOST_LOG_TRIVIAL(error) << "Unable to create context for required OpenGL " << required_opengl_version.first << "." << required_opengl_version.second; + BOOST_LOG_TRIVIAL(error) << "Unable to create context for required OpenGL " << gl_major << "." << gl_minor; delete m_context; m_context = nullptr; } else s_gl_info.set_core_profile(true); + } } - } - //else { - // // try to get the highest supported OpenGL version with core profile - // static const std::vector> valid_core_versions = { {4,6}, {4,5}, {4,4}, {4,3}, {4,2}, {4,1}, {4,0}, {3,3}, {3,2} }; - // // disable wxWidgets logging to avoid showing the log dialog in case the following code fails generating a valid gl context - // wxLogNull logNo; - // for (const auto& [major, minor] : valid_core_versions) { - // wxGLContextAttrs attrs; - // attrs.CoreProfile().ForwardCompatible().OGLVersion(major, minor).EndList(); - // m_context = new wxGLContext(&canvas, nullptr, &attrs); - // if (m_context->IsOK()) - // break; - // else { - // delete m_context; - // m_context = nullptr; - // } - // } - //} #if ENABLE_OPENGL_DEBUG_OPTION if (m_context == nullptr) {