Merge branch 'lm_et_spe2092_271' into master_27x

This commit is contained in:
Lukas Matena 2024-01-22 12:18:06 +01:00
commit 7096abe2f1
9 changed files with 82 additions and 109 deletions

View File

@ -170,10 +170,9 @@ int CLI::run(int argc, char **argv)
#ifdef SLIC3R_GUI #ifdef SLIC3R_GUI
#if ENABLE_GL_CORE_PROFILE #if ENABLE_GL_CORE_PROFILE
std::pair<int, int> opengl_version = { 0, 0 }; std::pair<int, int> opengl_version = { 0, 0 };
#if ENABLE_OPENGL_DEBUG_OPTION bool opengl_debug = false;
bool opengl_debug = false; bool opengl_compatibility_profile = false;
#endif // ENABLE_OPENGL_DEBUG_OPTION
// search for special keys into command line parameters // search for special keys into command line parameters
auto it = std::find(m_actions.begin(), m_actions.end(), "gcodeviewer"); auto it = std::find(m_actions.begin(), m_actions.end(), "gcodeviewer");
@ -185,30 +184,32 @@ int CLI::run(int argc, char **argv)
it = std::find(m_actions.begin(), m_actions.end(), "opengl-version"); it = std::find(m_actions.begin(), m_actions.end(), "opengl-version");
if (it != m_actions.end()) { if (it != m_actions.end()) {
std::string opengl_version_str = m_config.opt_string("opengl-version"); const Semver opengl_minimum = Semver(3,2,0);
if (std::find(Slic3r::GUI::OpenGLVersions::core_str.begin(), Slic3r::GUI::OpenGLVersions::core_str.end(), opengl_version_str) == Slic3r::GUI::OpenGLVersions::core_str.end()) { const std::string opengl_version_str = m_config.opt_string("opengl-version");
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::optional<Semver> semver = Semver::parse(opengl_version_str);
boost::nowide::cerr << "Found invalid OpenGL version: " << opengl_version_str << std::endl; if (semver.has_value() && (*semver) >= opengl_minimum ) {
opengl_version_str.clear(); opengl_version.first = semver->maj();
} opengl_version.second = semver->min();
} } else
boost::nowide::cerr << "Required OpenGL version " << opengl_version_str << " is invalid. Must be greater than or equal to " << opengl_minimum.to_string() << std::endl;
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.second = std::stoi(tokens[1].c_str());
}
start_gui = true; start_gui = true;
m_actions.erase(it); m_actions.erase(it);
} }
it = std::find(m_actions.begin(), m_actions.end(), "opengl-compatibility");
if (it != m_actions.end()) {
start_gui = true;
opengl_compatibility_profile = true;
// reset version as compatibility profile always take the highest version
// supported by the graphic card
opengl_version = std::make_pair(0, 0);
m_actions.erase(it);
}
it = std::find(m_actions.begin(), m_actions.end(), "opengl-debug"); it = std::find(m_actions.begin(), m_actions.end(), "opengl-debug");
if (it != m_actions.end()) { if (it != m_actions.end()) {
start_gui = true; start_gui = true;
#if ENABLE_OPENGL_DEBUG_OPTION
opengl_debug = true; opengl_debug = true;
#endif // ENABLE_OPENGL_DEBUG_OPTION
m_actions.erase(it); m_actions.erase(it);
} }
#else #else
@ -224,7 +225,7 @@ int CLI::run(int argc, char **argv)
#endif // ENABLE_GL_CORE_PROFILE #endif // ENABLE_GL_CORE_PROFILE
#else // SLIC3R_GUI #else // SLIC3R_GUI
// If there is no GUI, we shall ignore the parameters. Remove them from the list. // If there is no GUI, we shall ignore the parameters. Remove them from the list.
for (const std::string& s : { "opengl-version", "opengl-debug", "gcodeviewer" }) { for (const std::string& s : { "opengl-version", "opengl-compatibility", "opengl-debug", "gcodeviewer" }) {
auto it = std::find(m_actions.cbegin(), m_actions.cend(), s); auto it = std::find(m_actions.cbegin(), m_actions.cend(), s);
if (it != m_actions.end()) { if (it != m_actions.end()) {
boost::nowide::cerr << "Parameter '" << s << "' is ignored, this PrusaSlicer build is CLI only." << std::endl; boost::nowide::cerr << "Parameter '" << s << "' is ignored, this PrusaSlicer build is CLI only." << std::endl;
@ -714,10 +715,9 @@ int CLI::run(int argc, char **argv)
params.download_url = download_url; params.download_url = download_url;
params.delete_after_load = delete_after_load; params.delete_after_load = delete_after_load;
#if ENABLE_GL_CORE_PROFILE #if ENABLE_GL_CORE_PROFILE
#if ENABLE_OPENGL_DEBUG_OPTION
params.opengl_version = opengl_version; params.opengl_version = opengl_version;
params.opengl_debug = opengl_debug; params.opengl_debug = opengl_debug;
#endif // ENABLE_OPENGL_DEBUG_OPTION params.opengl_compatibiity_profile = opengl_compatibility_profile;
#endif // ENABLE_GL_CORE_PROFILE #endif // ENABLE_GL_CORE_PROFILE
return Slic3r::GUI::GUI_Run(params); return Slic3r::GUI::GUI_Run(params);
#else // SLIC3R_GUI #else // SLIC3R_GUI

View File

@ -266,7 +266,7 @@ int wmain(int argc, wchar_t **argv)
// In that case, use Mesa. // In that case, use Mesa.
(::GetSystemMetrics(SM_REMOTESESSION) && !force_hw) || (::GetSystemMetrics(SM_REMOTESESSION) && !force_hw) ||
// Try to load the default OpenGL driver and test its context version. // Try to load the default OpenGL driver and test its context version.
! opengl_version_check.load_opengl_dll() || ! opengl_version_check.is_version_greater_or_equal_to(2, 0); ! opengl_version_check.load_opengl_dll() || ! opengl_version_check.is_version_greater_or_equal_to(3, 2);
#endif /* SLIC3R_GUI */ #endif /* SLIC3R_GUI */
wchar_t path_to_exe[MAX_PATH + 1] = { 0 }; wchar_t path_to_exe[MAX_PATH + 1] = { 0 };

View File

@ -4889,9 +4889,15 @@ CLIActionsConfigDef::CLIActionsConfigDef()
def->cli = "opengl-version"; def->cli = "opengl-version";
def->set_default_value(new ConfigOptionString()); def->set_default_value(new ConfigOptionString());
def = this->add("opengl-compatibility", coBool);
def->label = L("OpenGL compatibility profile");
def->tooltip = L("Enable OpenGL compatibility profile");
def->cli = "opengl-compatibility";
def->set_default_value(new ConfigOptionBool(false));
def = this->add("opengl-debug", coBool); def = this->add("opengl-debug", coBool);
def->label = L("OpenGL debug output"); def->label = L("OpenGL debug output");
def->tooltip = L("Activate OpenGL debug output on graphic cards which support it"); def->tooltip = L("Activate OpenGL debug output on graphic cards which support it (OpenGL 4.3 or higher)");
def->cli = "opengl-debug"; def->cli = "opengl-debug";
def->set_default_value(new ConfigOptionBool(false)); def->set_default_value(new ConfigOptionBool(false));
#endif // ENABLE_GL_CORE_PROFILE #endif // ENABLE_GL_CORE_PROFILE

View File

@ -55,8 +55,6 @@
#define ENABLE_OPENGL_ES 0 #define ENABLE_OPENGL_ES 0
// Enable OpenGL core profile context (tested against Mesa 20.1.8 on Windows) // Enable OpenGL core profile context (tested against Mesa 20.1.8 on Windows)
#define ENABLE_GL_CORE_PROFILE (1 && !ENABLE_OPENGL_ES) #define ENABLE_GL_CORE_PROFILE (1 && !ENABLE_OPENGL_ES)
// Enable OpenGL debug messages using debug context
#define ENABLE_OPENGL_DEBUG_OPTION (1 && ENABLE_GL_CORE_PROFILE)
// Enable imgui dialog which allows to set the parameters used to export binarized gcode // Enable imgui dialog which allows to set the parameters used to export binarized gcode
#define ENABLE_BINARIZED_GCODE_DEBUG_WINDOW 0 #define ENABLE_BINARIZED_GCODE_DEBUG_WINDOW 0

View File

@ -889,12 +889,8 @@ std::string GUI_App::get_gl_info(bool for_github)
wxGLContext* GUI_App::init_glcontext(wxGLCanvas& canvas) wxGLContext* GUI_App::init_glcontext(wxGLCanvas& canvas)
{ {
#if ENABLE_GL_CORE_PROFILE #if ENABLE_GL_CORE_PROFILE
#if ENABLE_OPENGL_DEBUG_OPTION
return m_opengl_mgr.init_glcontext(canvas, init_params != nullptr ? init_params->opengl_version : std::make_pair(0, 0), return m_opengl_mgr.init_glcontext(canvas, init_params != nullptr ? init_params->opengl_version : std::make_pair(0, 0),
init_params != nullptr ? init_params->opengl_debug : false); init_params != nullptr ? init_params->opengl_compatibiity_profile : false, init_params != nullptr ? init_params->opengl_debug : false);
#else
return m_opengl_mgr.init_glcontext(canvas, init_params != nullptr ? init_params->opengl_version : std::make_pair(0, 0));
#endif // ENABLE_OPENGL_DEBUG_OPTION
#else #else
return m_opengl_mgr.init_glcontext(canvas); return m_opengl_mgr.init_glcontext(canvas);
#endif // ENABLE_GL_CORE_PROFILE #endif // ENABLE_GL_CORE_PROFILE

View File

@ -30,11 +30,7 @@
namespace Slic3r { namespace Slic3r {
namespace GUI { 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::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 &params) int GUI_Run(GUI_InitParams &params)
{ {

View File

@ -14,11 +14,7 @@ namespace GUI {
struct OpenGLVersions 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>> core;
static const std::vector<std::pair<int, int>> precore;
}; };
struct GUI_InitParams struct GUI_InitParams
@ -33,15 +29,14 @@ struct GUI_InitParams
DynamicPrintConfig extra_config; DynamicPrintConfig extra_config;
std::vector<std::string> input_files; std::vector<std::string> input_files;
bool start_as_gcodeviewer; bool start_as_gcodeviewer;
bool start_downloader; bool start_downloader;
bool delete_after_load; bool delete_after_load;
std::string download_url; std::string download_url;
#if ENABLE_GL_CORE_PROFILE #if ENABLE_GL_CORE_PROFILE
std::pair<int, int> opengl_version; std::pair<int, int> opengl_version;
#if ENABLE_OPENGL_DEBUG_OPTION bool opengl_debug;
bool opengl_debug; bool opengl_compatibiity_profile;
#endif // ENABLE_OPENGL_DEBUG_OPTION
#endif // ENABLE_GL_CORE_PROFILE #endif // ENABLE_GL_CORE_PROFILE
}; };

View File

@ -127,6 +127,10 @@ void OpenGLManager::GLInfo::detect() const
float* max_anisotropy = const_cast<float*>(&m_max_anisotropy); float* max_anisotropy = const_cast<float*>(&m_max_anisotropy);
glsafe(::glGetFloatv(GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, max_anisotropy)); glsafe(::glGetFloatv(GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, max_anisotropy));
} }
if (!GLEW_ARB_compatibility)
*const_cast<bool*>(&m_core_profile) = true;
*const_cast<bool*>(&m_detected) = true; *const_cast<bool*>(&m_detected) = true;
} }
@ -197,7 +201,7 @@ std::string OpenGLManager::GLInfo::to_string(bool for_github) const
std::string line_end = format_as_html ? "<br>" : "\n"; std::string line_end = format_as_html ? "<br>" : "\n";
out << h2_start << "OpenGL installation" << h2_end << line_end; out << h2_start << "OpenGL installation" << h2_end << line_end;
out << b_start << "GL version: " << b_end << m_version << line_end; out << b_start << "GL version: " << b_end << m_version << " (" << m_version_string << ")" << line_end;
#if ENABLE_GL_CORE_PROFILE #if ENABLE_GL_CORE_PROFILE
out << b_start << "Profile: " << b_end << (is_core_profile() ? "Core" : "Compatibility") << line_end; out << b_start << "Profile: " << b_end << (is_core_profile() ? "Core" : "Compatibility") << line_end;
#endif // ENABLE_GL_CORE_PROFILE #endif // ENABLE_GL_CORE_PROFILE
@ -287,14 +291,14 @@ OpenGLManager::~OpenGLManager()
#endif //__APPLE__ #endif //__APPLE__
} }
#if ENABLE_OPENGL_DEBUG_OPTION #if ENABLE_GL_CORE_PROFILE
#ifdef _WIN32 #ifdef _WIN32
static void APIENTRY CustomGLDebugOutput(GLenum source, GLenum type, unsigned int id, GLenum severity, GLsizei length, const char* message, const void* userParam) static void APIENTRY CustomGLDebugOutput(GLenum source, GLenum type, unsigned int id, GLenum severity, GLsizei length, const char* message, const void* userParam)
#else #else
static void CustomGLDebugOutput(GLenum source, GLenum type, unsigned int id, GLenum severity, GLsizei length, const char* message, const void* userParam) static void CustomGLDebugOutput(GLenum source, GLenum type, unsigned int id, GLenum severity, GLsizei length, const char* message, const void* userParam)
#endif // _WIN32 #endif // _WIN32
{ {
if (severity == GL_DEBUG_SEVERITY_NOTIFICATION) if (severity != GL_DEBUG_SEVERITY_HIGH)
return; return;
std::string out = "OpenGL DEBUG message ["; std::string out = "OpenGL DEBUG message [";
@ -331,7 +335,7 @@ static void CustomGLDebugOutput(GLenum source, GLenum type, unsigned int id, GLe
out += "]:\n"; out += "]:\n";
std::cout << out << "(" << id << "): " << message << "\n\n"; std::cout << out << "(" << id << "): " << message << "\n\n";
} }
#endif // ENABLE_OPENGL_DEBUG_OPTION #endif // ENABLE_GL_CORE_PROFILE
bool OpenGLManager::init_gl() bool OpenGLManager::init_gl()
{ {
@ -369,7 +373,7 @@ bool OpenGLManager::init_gl()
#if ENABLE_OPENGL_ES #if ENABLE_OPENGL_ES
bool valid_version = s_gl_info.is_version_greater_or_equal_to(2, 0); bool valid_version = s_gl_info.is_version_greater_or_equal_to(2, 0);
#elif ENABLE_GL_CORE_PROFILE #elif ENABLE_GL_CORE_PROFILE
bool valid_version = s_gl_info.is_core_profile() ? s_gl_info.is_version_greater_or_equal_to(3, 2) : s_gl_info.is_version_greater_or_equal_to(2, 0); const bool valid_version = s_gl_info.is_version_greater_or_equal_to(3, 2);
#else #else
bool valid_version = s_gl_info.is_version_greater_or_equal_to(2, 0); bool valid_version = s_gl_info.is_version_greater_or_equal_to(2, 0);
#endif // ENABLE_OPENGL_ES #endif // ENABLE_OPENGL_ES
@ -379,16 +383,16 @@ bool OpenGLManager::init_gl()
wxString message = format_wxstr( wxString message = format_wxstr(
#if ENABLE_OPENGL_ES #if ENABLE_OPENGL_ES
_L("PrusaSlicer requires OpenGL ES 2.0 capable graphics driver to run correctly, \n" _L("PrusaSlicer requires OpenGL ES 2.0 capable graphics driver to run correctly, \n"
"while OpenGL version %s, render %s, vendor %s was detected."), s_gl_info.get_version_string(), s_gl_info.get_renderer(), s_gl_info.get_vendor()); "while OpenGL version %s, render %s, vendor %s was detected."), s_gl_info.get_version_string(), s_gl_info.get_renderer(), s_gl_info.get_vendor());
#elif ENABLE_GL_CORE_PROFILE #elif ENABLE_GL_CORE_PROFILE
_L("PrusaSlicer requires OpenGL %s capable graphics driver to run correctly, \n" _L("PrusaSlicer requires OpenGL 3.2 capable graphics driver to run correctly,\n"
"while OpenGL version %s, render %s, vendor %s was detected."), (s_gl_info.is_core_profile() ? "3.3" : "2.0"), s_gl_info.get_version_string(), s_gl_info.get_renderer(), s_gl_info.get_vendor()); "while OpenGL version %s, render %s, vendor %s was detected."), s_gl_info.get_version_string(), s_gl_info.get_renderer(), s_gl_info.get_vendor());
#else #else
_L("PrusaSlicer requires OpenGL 2.0 capable graphics driver to run correctly, \n" _L("PrusaSlicer requires OpenGL 2.0 capable graphics driver to run correctly, \n"
"while OpenGL version %s, render %s, vendor %s was detected."), s_gl_info.get_version_string(), s_gl_info.get_renderer(), s_gl_info.get_vendor()); "while OpenGL version %s, render %s, vendor %s was detected."), s_gl_info.get_version_string(), s_gl_info.get_renderer(), s_gl_info.get_vendor());
#endif // ENABLE_OPENGL_ES #endif // ENABLE_OPENGL_ES
message += "\n"; message += "\n";
message += _L("You may need to update your graphics card driver."); message += _L("You may need to update your graphics card driver.");
#ifdef _WIN32 #ifdef _WIN32
message += "\n"; message += "\n";
message += _L("As a workaround, you may run PrusaSlicer with a software rendered 3D graphics by running prusa-slicer.exe with the --sw-renderer parameter."); message += _L("As a workaround, you may run PrusaSlicer with a software rendered 3D graphics by running prusa-slicer.exe with the --sw-renderer parameter.");
@ -403,14 +407,15 @@ bool OpenGLManager::init_gl()
wxString message = format_wxstr(_L("Unable to load the following shaders:\n%s"), error); wxString message = format_wxstr(_L("Unable to load the following shaders:\n%s"), error);
wxMessageBox(message, wxString("PrusaSlicer - ") + _L("Error loading shaders"), wxOK | wxICON_ERROR); wxMessageBox(message, wxString("PrusaSlicer - ") + _L("Error loading shaders"), wxOK | wxICON_ERROR);
} }
#if ENABLE_OPENGL_DEBUG_OPTION #if ENABLE_GL_CORE_PROFILE
if (m_debug_enabled && GLEW_KHR_debug) { if (m_debug_enabled && s_gl_info.is_version_greater_or_equal_to(4, 3) && GLEW_KHR_debug) {
::glEnable(GL_DEBUG_OUTPUT); ::glEnable(GL_DEBUG_OUTPUT);
::glEnable(GL_DEBUG_OUTPUT_SYNCHRONOUS); ::glEnable(GL_DEBUG_OUTPUT_SYNCHRONOUS);
::glDebugMessageCallback(CustomGLDebugOutput, nullptr); ::glDebugMessageCallback(CustomGLDebugOutput, nullptr);
::glDebugMessageControl(GL_DONT_CARE, GL_DONT_CARE, GL_DONT_CARE, 0, nullptr, GL_TRUE); ::glDebugMessageControl(GL_DONT_CARE, GL_DONT_CARE, GL_DONT_CARE, 0, nullptr, GL_TRUE);
std::cout << "Enabled OpenGL debug output\n";
} }
#endif // ENABLE_OPENGL_DEBUG_OPTION #endif // ENABLE_GL_CORE_PROFILE
} }
#ifdef _WIN32 #ifdef _WIN32
@ -437,11 +442,8 @@ bool OpenGLManager::init_gl()
} }
#if ENABLE_GL_CORE_PROFILE #if ENABLE_GL_CORE_PROFILE
#if ENABLE_OPENGL_DEBUG_OPTION wxGLContext* OpenGLManager::init_glcontext(wxGLCanvas& canvas, const std::pair<int, int>& required_opengl_version, bool enable_compatibility_profile,
wxGLContext* OpenGLManager::init_glcontext(wxGLCanvas& canvas, const std::pair<int, int>& required_opengl_version, bool enable_debug) bool enable_debug)
#else
wxGLContext* OpenGLManager::init_glcontext(wxGLCanvas& canvas, const std::pair<int, int>& required_opengl_version)
#endif // ENABLE_OPENGL_DEBUG_OPTION
#else #else
wxGLContext* OpenGLManager::init_glcontext(wxGLCanvas& canvas) wxGLContext* OpenGLManager::init_glcontext(wxGLCanvas& canvas)
#endif // ENABLE_GL_CORE_PROFILE #endif // ENABLE_GL_CORE_PROFILE
@ -452,33 +454,25 @@ wxGLContext* OpenGLManager::init_glcontext(wxGLCanvas& canvas)
attrs.PlatformDefaults().ES2().MajorVersion(2).EndList(); attrs.PlatformDefaults().ES2().MajorVersion(2).EndList();
m_context = new wxGLContext(&canvas, nullptr, &attrs); m_context = new wxGLContext(&canvas, nullptr, &attrs);
#elif ENABLE_GL_CORE_PROFILE #elif ENABLE_GL_CORE_PROFILE
#if ENABLE_OPENGL_DEBUG_OPTION
m_debug_enabled = enable_debug; m_debug_enabled = enable_debug;
#endif // ENABLE_OPENGL_DEBUG_OPTION
const int gl_major = required_opengl_version.first; const int gl_major = required_opengl_version.first;
const int gl_minor = required_opengl_version.second; const int gl_minor = required_opengl_version.second;
const bool supports_core_profile = (gl_major < 3) ? false : (gl_major > 3) ? true : gl_minor >= 2; const bool supports_core_profile = (gl_major < 3) ? false : (gl_major > 3) ? true : gl_minor >= 2;
if (gl_major == 0) { if (gl_major == 0 && !enable_compatibility_profile) {
// search for highest supported core profile version // 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 // disable wxWidgets logging to avoid showing the log dialog in case the following code fails generating a valid gl context
wxLogNull logNo; wxLogNull logNo;
for (auto v = OpenGLVersions::core.rbegin(); v != OpenGLVersions::core.rend(); ++v) { for (auto v = OpenGLVersions::core.rbegin(); v != OpenGLVersions::core.rend(); ++v) {
wxGLContextAttrs attrs; wxGLContextAttrs attrs;
#if ENABLE_OPENGL_DEBUG_OPTION
attrs.PlatformDefaults().MajorVersion(v->first).MinorVersion(v->second).CoreProfile().ForwardCompatible(); attrs.PlatformDefaults().MajorVersion(v->first).MinorVersion(v->second).CoreProfile().ForwardCompatible();
if (m_debug_enabled) if (m_debug_enabled)
attrs.DebugCtx(); attrs.DebugCtx();
attrs.EndList(); attrs.EndList();
#else
attrs.PlatformDefaults().MajorVersion(gl_major).MinorVersion(gl_minor).CoreProfile().ForwardCompatible().EndList();
#endif // ENABLE_OPENGL_DEBUG_OPTION
m_context = new wxGLContext(&canvas, nullptr, &attrs); m_context = new wxGLContext(&canvas, nullptr, &attrs);
if (m_context->IsOK()) { if (m_context->IsOK())
s_gl_info.set_core_profile(true);
break; break;
}
else { else {
delete m_context; delete m_context;
m_context = nullptr; m_context = nullptr;
@ -487,45 +481,41 @@ wxGLContext* OpenGLManager::init_glcontext(wxGLCanvas& canvas)
} }
if (m_context == nullptr) { if (m_context == nullptr) {
// search for requested core profile version // search for requested compatibility profile version
if (supports_core_profile) { if (enable_compatibility_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;
attrs.PlatformDefaults().CompatibilityProfile();
if (m_debug_enabled)
attrs.DebugCtx();
attrs.EndList();
m_context = new wxGLContext(&canvas, nullptr, &attrs);
if (!m_context->IsOK()) {
delete m_context;
m_context = nullptr;
}
}
// search for requested core profile version
else if (supports_core_profile) {
// disable wxWidgets logging to avoid showing the log dialog in case the following code fails generating a valid gl context // disable wxWidgets logging to avoid showing the log dialog in case the following code fails generating a valid gl context
wxLogNull logNo; wxLogNull logNo;
wxGLContextAttrs attrs; wxGLContextAttrs attrs;
#if ENABLE_OPENGL_DEBUG_OPTION
attrs.PlatformDefaults().MajorVersion(gl_major).MinorVersion(gl_minor).CoreProfile().ForwardCompatible(); attrs.PlatformDefaults().MajorVersion(gl_major).MinorVersion(gl_minor).CoreProfile().ForwardCompatible();
if (m_debug_enabled) if (m_debug_enabled)
attrs.DebugCtx(); attrs.DebugCtx();
attrs.EndList(); attrs.EndList();
#else
attrs.PlatformDefaults().MajorVersion(gl_major).MinorVersion(gl_minor).CoreProfile().ForwardCompatible().EndList();
#endif // ENABLE_OPENGL_DEBUG_OPTION
m_context = new wxGLContext(&canvas, nullptr, &attrs); m_context = new wxGLContext(&canvas, nullptr, &attrs);
if (!m_context->IsOK()) { if (!m_context->IsOK()) {
BOOST_LOG_TRIVIAL(error) << "Unable to create context for required OpenGL " << gl_major << "." << gl_minor;
delete m_context; delete m_context;
m_context = nullptr; m_context = nullptr;
} }
else
s_gl_info.set_core_profile(true);
} }
} }
#if ENABLE_OPENGL_DEBUG_OPTION
if (m_context == nullptr) {
wxGLContextAttrs attrs;
attrs.PlatformDefaults();
if (m_debug_enabled)
attrs.DebugCtx();
attrs.EndList();
// if no valid context was created use the default one
m_context = new wxGLContext(&canvas, nullptr, &attrs);
}
#else
if (m_context == nullptr) if (m_context == nullptr)
// if no valid context was created use the default one // no valid context was created
m_context = new wxGLContext(&canvas); throw Slic3r::RuntimeError("Unable to create context for OpenGL.");
#endif // ENABLE_OPENGL_DEBUG_OPTION
#else #else
m_context = new wxGLContext(&canvas); m_context = new wxGLContext(&canvas);
#endif // ENABLE_OPENGL_ES #endif // ENABLE_OPENGL_ES

View File

@ -54,15 +54,13 @@ public:
const std::string& get_renderer() const; const std::string& get_renderer() const;
bool is_core_profile() const { return m_core_profile; } bool is_core_profile() const { return m_core_profile; }
void set_core_profile(bool value) { m_core_profile = value; }
bool is_mesa() const; bool is_mesa() const;
bool is_es() const { bool is_es() const {
return
#if ENABLE_OPENGL_ES #if ENABLE_OPENGL_ES
true; return true;
#else #else
false; return false;
#endif // ENABLE_OPENGL_ES #endif // ENABLE_OPENGL_ES
} }
@ -104,9 +102,7 @@ private:
bool m_gl_initialized{ false }; bool m_gl_initialized{ false };
wxGLContext* m_context{ nullptr }; wxGLContext* m_context{ nullptr };
#if ENABLE_OPENGL_DEBUG_OPTION
bool m_debug_enabled{ false }; bool m_debug_enabled{ false };
#endif // ENABLE_OPENGL_DEBUG_OPTION
GLShadersManager m_shaders_manager; GLShadersManager m_shaders_manager;
static GLInfo s_gl_info; static GLInfo s_gl_info;
#ifdef __APPLE__ #ifdef __APPLE__
@ -125,11 +121,7 @@ public:
bool init_gl(); bool init_gl();
#if ENABLE_GL_CORE_PROFILE #if ENABLE_GL_CORE_PROFILE
#if ENABLE_OPENGL_DEBUG_OPTION wxGLContext* init_glcontext(wxGLCanvas& canvas, const std::pair<int, int>& required_opengl_version, bool enable_compatibility_profile, bool enable_debug);
wxGLContext* init_glcontext(wxGLCanvas& canvas, const std::pair<int, int>& required_opengl_version, bool enable_debug);
#else
wxGLContext* init_glcontext(wxGLCanvas& canvas, const std::pair<int, int>& required_opengl_version);
#endif // ENABLE_OPENGL_DEBUG_OPTION
#else #else
wxGLContext* init_glcontext(wxGLCanvas& canvas); wxGLContext* init_glcontext(wxGLCanvas& canvas);
#endif // ENABLE_GL_CORE_PROFILE #endif // ENABLE_GL_CORE_PROFILE