Tech ENABLE_GL_CORE_PROFILE - Command line option '--opengl-core=M.m' renamed as '--opengl-version=M.m'
use case 1 - the option is not added to the command line - PrusaSlicer defaults to the highest available core profile OpenGL version use case 2 - the option specify an OpenGL version which supports core profile - PrusaSlicer select the required OpenGL version, if available use case 3 - the option specify an OpenGL version which does not support core profile - PrusaSlicer defaults to the highest available compatibility profile OpenGL version use case 4 - the option contains invalid OpenGL version - PrusaSlicer defaults to the highest available core profile OpenGL version
This commit is contained in:
parent
da0a5b5cfb
commit
8db552ce26
5 changed files with 66 additions and 35 deletions
|
@ -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<std::string> 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<std::string> 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;
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -26,6 +26,12 @@
|
|||
namespace Slic3r {
|
||||
namespace GUI {
|
||||
|
||||
const std::vector<std::string> OpenGLVersions::core_str = { "3.2", "3.3", "4.0", "4.1", "4.2", "4.3", "4.4", "4.5", "4.6" };
|
||||
const std::vector<std::string> OpenGLVersions::precore_str = { "2.0", "2.1", "3.0", "3.1" };
|
||||
|
||||
const std::vector<std::pair<int, int>> OpenGLVersions::core = { {3,2}, {3,3}, {4,0}, {4,1}, {4,2}, {4,3}, {4,4}, {4,5}, {4,6} };
|
||||
const std::vector<std::pair<int, int>> OpenGLVersions::precore = { {2,0}, {2,1}, {3,0}, {3,1} };
|
||||
|
||||
int GUI_Run(GUI_InitParams ¶ms)
|
||||
{
|
||||
#if __APPLE__
|
||||
|
|
|
@ -8,6 +8,15 @@ namespace Slic3r {
|
|||
|
||||
namespace GUI {
|
||||
|
||||
struct OpenGLVersions
|
||||
{
|
||||
static const std::vector<std::string> core_str;
|
||||
static const std::vector<std::string> precore_str;
|
||||
|
||||
static const std::vector<std::pair<int, int>> core;
|
||||
static const std::vector<std::pair<int, int>> precore;
|
||||
};
|
||||
|
||||
struct GUI_InitParams
|
||||
{
|
||||
int argc;
|
||||
|
|
|
@ -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<std::pair<int, int>> 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) {
|
||||
|
|
Loading…
Reference in a new issue