ENH: CLI: don't popup dialog when loading shader failed

STUDIO-2855(github issue-1703)

Change-Id: I46476e94951aa2337fee3439159e777773366c59
This commit is contained in:
lane.wei 2023-05-04 15:56:16 +08:00 committed by Lane.Wei
parent 8dae5b6980
commit 33ae019a95
3 changed files with 20 additions and 15 deletions

View File

@ -2329,7 +2329,7 @@ int CLI::run(int argc, char **argv)
//opengl manager related logic //opengl manager related logic
{ {
Slic3r::GUI::OpenGLManager opengl_mgr; Slic3r::GUI::OpenGLManager opengl_mgr;
bool opengl_valid = opengl_mgr.init_gl(); bool opengl_valid = opengl_mgr.init_gl(false);
if (!opengl_valid) { if (!opengl_valid) {
BOOST_LOG_TRIVIAL(error) << "init opengl failed! skip thumbnail generating" << std::endl; BOOST_LOG_TRIVIAL(error) << "init opengl failed! skip thumbnail generating" << std::endl;
} }

View File

@ -233,7 +233,7 @@ OpenGLManager::~OpenGLManager()
#endif //__APPLE__ #endif //__APPLE__
} }
bool OpenGLManager::init_gl() bool OpenGLManager::init_gl(bool popup_error)
{ {
if (!m_gl_initialized) { if (!m_gl_initialized) {
GLenum result = glewInit(); GLenum result = glewInit();
@ -263,23 +263,28 @@ bool OpenGLManager::init_gl()
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);
if (!valid_version) { if (!valid_version) {
BOOST_LOG_TRIVIAL(warning) << "Found opengl version <= 2.0"<< std::endl; BOOST_LOG_TRIVIAL(error) << "Found opengl version <= 2.0"<< std::endl;
// Complain about the OpenGL version. // Complain about the OpenGL version.
wxString message = from_u8((boost::format( if (popup_error) {
_utf8(L("The application cannot run normally because OpenGL version is lower than 2.0.\n")))).str()); wxString message = from_u8((boost::format(
message += "\n"; _utf8(L("The application cannot run normally because OpenGL version is lower than 2.0.\n")))).str());
message += _L("Please upgrade your graphics card driver."); message += "\n";
wxMessageBox(message, _L("Unsupported OpenGL version"), wxOK | wxICON_ERROR); message += _L("Please upgrade your graphics card driver.");
wxMessageBox(message, _L("Unsupported OpenGL version"), wxOK | wxICON_ERROR);
}
} }
if (valid_version) if (valid_version)
{ {
// load shaders // load shaders
auto [result, error] = m_shaders_manager.init(); auto [result, error] = m_shaders_manager.init();
if (!result) { if (!result) {
wxString message = from_u8((boost::format( BOOST_LOG_TRIVIAL(error) << "Unable to load shaders: "<<error<< std::endl;
_utf8(L("Unable to load shaders:\n%s"))) % error).str()); if (popup_error) {
wxMessageBox(message, _L("Error loading shaders"), wxOK | wxICON_ERROR); wxString message = from_u8((boost::format(
_utf8(L("Unable to load shaders:\n%s"))) % error).str());
wxMessageBox(message, _L("Error loading shaders"), wxOK | wxICON_ERROR);
}
} }
} }

View File

@ -54,7 +54,7 @@ public:
void detect() const; void detect() const;
}; };
#ifdef __APPLE__ #ifdef __APPLE__
// Part of hack to remove crash when closing the application on OSX 10.9.5 when building against newer wxWidgets // Part of hack to remove crash when closing the application on OSX 10.9.5 when building against newer wxWidgets
struct OSInfo struct OSInfo
{ {
@ -76,7 +76,7 @@ private:
wxGLContext* m_context{ nullptr }; wxGLContext* m_context{ nullptr };
GLShadersManager m_shaders_manager; GLShadersManager m_shaders_manager;
static GLInfo s_gl_info; static GLInfo s_gl_info;
#ifdef __APPLE__ #ifdef __APPLE__
// Part of hack to remove crash when closing the application on OSX 10.9.5 when building against newer wxWidgets // Part of hack to remove crash when closing the application on OSX 10.9.5 when building against newer wxWidgets
static OSInfo s_os_info; static OSInfo s_os_info;
#endif //__APPLE__ #endif //__APPLE__
@ -89,7 +89,7 @@ public:
OpenGLManager() = default; OpenGLManager() = default;
~OpenGLManager(); ~OpenGLManager();
bool init_gl(); bool init_gl(bool popup_error = true);
wxGLContext* init_glcontext(wxGLCanvas& canvas); wxGLContext* init_glcontext(wxGLCanvas& canvas);
GLShaderProgram* get_shader(const std::string& shader_name) { return m_shaders_manager.get_shader(shader_name); } GLShaderProgram* get_shader(const std::string& shader_name) { return m_shaders_manager.get_shader(shader_name); }