This commit is contained in:
YuSanka 2020-05-06 15:15:31 +02:00
commit d7b12c6e19
9 changed files with 58 additions and 76 deletions

View File

@ -27,8 +27,8 @@ set(SLIC3R_GUI_SOURCES
GUI/GLShader.hpp GUI/GLShader.hpp
GUI/GLCanvas3D.hpp GUI/GLCanvas3D.hpp
GUI/GLCanvas3D.cpp GUI/GLCanvas3D.cpp
GUI/GLCanvas3DManager.hpp GUI/OpenGLManager.hpp
GUI/GLCanvas3DManager.cpp GUI/OpenGLManager.cpp
GUI/Selection.hpp GUI/Selection.hpp
GUI/Selection.cpp GUI/Selection.cpp
GUI/Gizmos/GLGizmosManager.cpp GUI/Gizmos/GLGizmosManager.cpp

View File

@ -410,7 +410,7 @@ void Bed3D::render_texture(bool bottom, GLCanvas3D& canvas) const
if (boost::algorithm::iends_with(m_texture_filename, ".svg")) if (boost::algorithm::iends_with(m_texture_filename, ".svg"))
{ {
// use higher resolution images if graphic card and opengl version allow // use higher resolution images if graphic card and opengl version allow
GLint max_tex_size = GLCanvas3DManager::get_gl_info().get_max_tex_size(); GLint max_tex_size = OpenGLManager::get_gl_info().get_max_tex_size();
if ((m_temp_texture.get_id() == 0) || (m_temp_texture.get_source() != m_texture_filename)) if ((m_temp_texture.get_id() == 0) || (m_temp_texture.get_source() != m_texture_filename))
{ {
// generate a temporary lower resolution texture to show while no main texture levels have been compressed // generate a temporary lower resolution texture to show while no main texture levels have been compressed

View File

@ -19,7 +19,7 @@
#include "slic3r/GUI/PresetBundle.hpp" #include "slic3r/GUI/PresetBundle.hpp"
#include "slic3r/GUI/Tab.hpp" #include "slic3r/GUI/Tab.hpp"
#include "slic3r/GUI/GUI_Preview.hpp" #include "slic3r/GUI/GUI_Preview.hpp"
#include "slic3r/GUI/GLCanvas3DManager.hpp" #include "slic3r/GUI/OpenGLManager.hpp"
#include "slic3r/GUI/3DBed.hpp" #include "slic3r/GUI/3DBed.hpp"
#include "slic3r/GUI/Camera.hpp" #include "slic3r/GUI/Camera.hpp"
@ -2070,10 +2070,10 @@ void GLCanvas3D::render()
ImGui::Separator(); ImGui::Separator();
imgui.text("Compressed textures: "); imgui.text("Compressed textures: ");
ImGui::SameLine(); ImGui::SameLine();
imgui.text(GLCanvas3DManager::are_compressed_textures_supported() ? "supported" : "not supported"); imgui.text(OpenGLManager::are_compressed_textures_supported() ? "supported" : "not supported");
imgui.text("Max texture size: "); imgui.text("Max texture size: ");
ImGui::SameLine(); ImGui::SameLine();
imgui.text(std::to_string(GLCanvas3DManager::get_gl_info().get_max_tex_size())); imgui.text(std::to_string(OpenGLManager::get_gl_info().get_max_tex_size()));
imgui.end(); imgui.end();
#endif // ENABLE_RENDER_STATISTICS #endif // ENABLE_RENDER_STATISTICS
@ -2150,10 +2150,10 @@ void GLCanvas3D::render()
void GLCanvas3D::render_thumbnail(ThumbnailData& thumbnail_data, unsigned int w, unsigned int h, bool printable_only, bool parts_only, bool show_bed, bool transparent_background) const void GLCanvas3D::render_thumbnail(ThumbnailData& thumbnail_data, unsigned int w, unsigned int h, bool printable_only, bool parts_only, bool show_bed, bool transparent_background) const
{ {
switch (GLCanvas3DManager::get_framebuffers_type()) switch (OpenGLManager::get_framebuffers_type())
{ {
case GLCanvas3DManager::EFramebufferType::Arb: { _render_thumbnail_framebuffer(thumbnail_data, w, h, printable_only, parts_only, show_bed, transparent_background); break; } case OpenGLManager::EFramebufferType::Arb: { _render_thumbnail_framebuffer(thumbnail_data, w, h, printable_only, parts_only, show_bed, transparent_background); break; }
case GLCanvas3DManager::EFramebufferType::Ext: { _render_thumbnail_framebuffer_ext(thumbnail_data, w, h, printable_only, parts_only, show_bed, transparent_background); break; } case OpenGLManager::EFramebufferType::Ext: { _render_thumbnail_framebuffer_ext(thumbnail_data, w, h, printable_only, parts_only, show_bed, transparent_background); break; }
default: { _render_thumbnail_legacy(thumbnail_data, w, h, printable_only, parts_only, show_bed, transparent_background); break; } default: { _render_thumbnail_legacy(thumbnail_data, w, h, printable_only, parts_only, show_bed, transparent_background); break; }
} }
} }

View File

@ -2,7 +2,7 @@
#include "GLTexture.hpp" #include "GLTexture.hpp"
#include "3DScene.hpp" #include "3DScene.hpp"
#include "GLCanvas3DManager.hpp" #include "OpenGLManager.hpp"
#include <GL/glew.h> #include <GL/glew.h>
@ -441,7 +441,7 @@ bool GLTexture::load_from_png(const std::string& filename, bool use_mipmaps, ECo
if (apply_anisotropy) if (apply_anisotropy)
{ {
GLfloat max_anisotropy = GLCanvas3DManager::get_gl_info().get_max_anisotropy(); GLfloat max_anisotropy = OpenGLManager::get_gl_info().get_max_anisotropy();
if (max_anisotropy > 1.0f) if (max_anisotropy > 1.0f)
glsafe(::glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY_EXT, max_anisotropy)); glsafe(::glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY_EXT, max_anisotropy));
} }
@ -590,7 +590,7 @@ bool GLTexture::load_from_svg(const std::string& filename, bool use_mipmaps, boo
if (apply_anisotropy) if (apply_anisotropy)
{ {
GLfloat max_anisotropy = GLCanvas3DManager::get_gl_info().get_max_anisotropy(); GLfloat max_anisotropy = OpenGLManager::get_gl_info().get_max_anisotropy();
if (max_anisotropy > 1.0f) if (max_anisotropy > 1.0f)
glsafe(::glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY_EXT, max_anisotropy)); glsafe(::glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY_EXT, max_anisotropy));
} }

View File

@ -285,17 +285,17 @@ GUI_App::~GUI_App()
std::string GUI_App::get_gl_info(bool format_as_html, bool extensions) std::string GUI_App::get_gl_info(bool format_as_html, bool extensions)
{ {
return GLCanvas3DManager::get_gl_info().to_string(format_as_html, extensions); return OpenGLManager::get_gl_info().to_string(format_as_html, extensions);
} }
wxGLContext* GUI_App::init_glcontext(wxGLCanvas& canvas) wxGLContext* GUI_App::init_glcontext(wxGLCanvas& canvas)
{ {
return m_canvas_mgr.init_glcontext(canvas); return m_opengl_mgr.init_glcontext(canvas);
} }
bool GUI_App::init_opengl() bool GUI_App::init_opengl()
{ {
return m_canvas_mgr.init_gl(); return m_opengl_mgr.init_gl();
} }
void GUI_App::init_app_config() void GUI_App::init_app_config()
@ -322,6 +322,7 @@ void GUI_App::init_app_config()
app_config->load(); app_config->load();
} }
} }
bool GUI_App::OnInit() bool GUI_App::OnInit()
{ {
try { try {

View File

@ -7,7 +7,7 @@
#include "MainFrame.hpp" #include "MainFrame.hpp"
#include "ImGuiWrapper.hpp" #include "ImGuiWrapper.hpp"
#include "ConfigWizard.hpp" #include "ConfigWizard.hpp"
#include "GLCanvas3DManager.hpp" #include "OpenGLManager.hpp"
#include <wx/app.h> #include <wx/app.h>
#include <wx/colour.h> #include <wx/colour.h>
@ -98,7 +98,7 @@ class GUI_App : public wxApp
// Best translation language, provided by Windows or OSX, owned by wxWidgets. // Best translation language, provided by Windows or OSX, owned by wxWidgets.
const wxLanguageInfo *m_language_info_best = nullptr; const wxLanguageInfo *m_language_info_best = nullptr;
GLCanvas3DManager m_canvas_mgr; OpenGLManager m_opengl_mgr;
std::unique_ptr<RemovableDriveManager> m_removable_drive_manager; std::unique_ptr<RemovableDriveManager> m_removable_drive_manager;

View File

@ -7,7 +7,7 @@
#include "AppConfig.hpp" #include "AppConfig.hpp"
#include "3DScene.hpp" #include "3DScene.hpp"
#include "BackgroundSlicingProcess.hpp" #include "BackgroundSlicingProcess.hpp"
#include "GLCanvas3DManager.hpp" #include "OpenGLManager.hpp"
#include "GLCanvas3D.hpp" #include "GLCanvas3D.hpp"
#include "PresetBundle.hpp" #include "PresetBundle.hpp"
#include "DoubleSlider.hpp" #include "DoubleSlider.hpp"
@ -48,7 +48,7 @@ bool View3D::init(wxWindow* parent, Model* model, DynamicPrintConfig* config, Ba
if (!Create(parent, wxID_ANY, wxDefaultPosition, wxDefaultSize, 0 /* disable wxTAB_TRAVERSAL */)) if (!Create(parent, wxID_ANY, wxDefaultPosition, wxDefaultSize, 0 /* disable wxTAB_TRAVERSAL */))
return false; return false;
m_canvas_widget = GLCanvas3DManager::create_wxglcanvas(*this); m_canvas_widget = OpenGLManager::create_wxglcanvas(*this);
if (m_canvas_widget == nullptr) if (m_canvas_widget == nullptr)
return false; return false;
@ -56,7 +56,7 @@ bool View3D::init(wxWindow* parent, Model* model, DynamicPrintConfig* config, Ba
m_canvas->set_context(wxGetApp().init_glcontext(*m_canvas_widget)); m_canvas->set_context(wxGetApp().init_glcontext(*m_canvas_widget));
m_canvas->bind_event_handlers(); m_canvas->bind_event_handlers();
m_canvas->allow_multisample(GLCanvas3DManager::can_multisample()); m_canvas->allow_multisample(OpenGLManager::can_multisample());
// XXX: If have OpenGL // XXX: If have OpenGL
m_canvas->enable_picking(true); m_canvas->enable_picking(true);
m_canvas->enable_moving(true); m_canvas->enable_moving(true);
@ -209,14 +209,14 @@ bool Preview::init(wxWindow* parent, Model* model)
if (!Create(parent, wxID_ANY, wxDefaultPosition, wxDefaultSize, 0 /* disable wxTAB_TRAVERSAL */)) if (!Create(parent, wxID_ANY, wxDefaultPosition, wxDefaultSize, 0 /* disable wxTAB_TRAVERSAL */))
return false; return false;
m_canvas_widget = GLCanvas3DManager::create_wxglcanvas(*this); m_canvas_widget = OpenGLManager::create_wxglcanvas(*this);
if (m_canvas_widget == nullptr) if (m_canvas_widget == nullptr)
return false; return false;
m_canvas = new GLCanvas3D(m_canvas_widget); m_canvas = new GLCanvas3D(m_canvas_widget);
m_canvas->set_context(wxGetApp().init_glcontext(*m_canvas_widget)); m_canvas->set_context(wxGetApp().init_glcontext(*m_canvas_widget));
m_canvas->bind_event_handlers(); m_canvas->bind_event_handlers();
m_canvas->allow_multisample(GLCanvas3DManager::can_multisample()); m_canvas->allow_multisample(OpenGLManager::can_multisample());
m_canvas->set_config(m_config); m_canvas->set_config(m_config);
m_canvas->set_model(model); m_canvas->set_model(model);
m_canvas->set_process(m_process); m_canvas->set_process(m_process);

View File

@ -1,21 +1,18 @@
#include "libslic3r/libslic3r.h" #include "libslic3r/libslic3r.h"
#include "GLCanvas3DManager.hpp" #include "OpenGLManager.hpp"
#include "../../slic3r/GUI/GUI.hpp"
#include "../../slic3r/GUI/AppConfig.hpp" #include "GUI.hpp"
#include "../../slic3r/GUI/GLCanvas3D.hpp" #include "I18N.hpp"
#include "3DScene.hpp"
#include <GL/glew.h> #include <GL/glew.h>
#include <boost/algorithm/string/split.hpp> #include <boost/algorithm/string/split.hpp>
#include <boost/algorithm/string/classification.hpp> #include <boost/algorithm/string/classification.hpp>
#include <boost/log/trivial.hpp> #include <boost/log/trivial.hpp>
#include <wx/glcanvas.h>
#include <wx/timer.h>
#include <wx/msgdlg.h>
#include <vector> #include <wx/glcanvas.h>
#include <string> #include <wx/msgdlg.h>
#include <iostream>
#if ENABLE_HACK_CLOSING_ON_OSX_10_9_5 #if ENABLE_HACK_CLOSING_ON_OSX_10_9_5
#ifdef __APPLE__ #ifdef __APPLE__
@ -31,7 +28,7 @@
namespace Slic3r { namespace Slic3r {
namespace GUI { namespace GUI {
const std::string& GLCanvas3DManager::GLInfo::get_version() const const std::string& OpenGLManager::GLInfo::get_version() const
{ {
if (!m_detected) if (!m_detected)
detect(); detect();
@ -39,7 +36,7 @@ const std::string& GLCanvas3DManager::GLInfo::get_version() const
return m_version; return m_version;
} }
const std::string& GLCanvas3DManager::GLInfo::get_glsl_version() const const std::string& OpenGLManager::GLInfo::get_glsl_version() const
{ {
if (!m_detected) if (!m_detected)
detect(); detect();
@ -47,7 +44,7 @@ const std::string& GLCanvas3DManager::GLInfo::get_glsl_version() const
return m_glsl_version; return m_glsl_version;
} }
const std::string& GLCanvas3DManager::GLInfo::get_vendor() const const std::string& OpenGLManager::GLInfo::get_vendor() const
{ {
if (!m_detected) if (!m_detected)
detect(); detect();
@ -55,7 +52,7 @@ const std::string& GLCanvas3DManager::GLInfo::get_vendor() const
return m_vendor; return m_vendor;
} }
const std::string& GLCanvas3DManager::GLInfo::get_renderer() const const std::string& OpenGLManager::GLInfo::get_renderer() const
{ {
if (!m_detected) if (!m_detected)
detect(); detect();
@ -63,7 +60,7 @@ const std::string& GLCanvas3DManager::GLInfo::get_renderer() const
return m_renderer; return m_renderer;
} }
int GLCanvas3DManager::GLInfo::get_max_tex_size() const int OpenGLManager::GLInfo::get_max_tex_size() const
{ {
if (!m_detected) if (!m_detected)
detect(); detect();
@ -78,7 +75,7 @@ int GLCanvas3DManager::GLInfo::get_max_tex_size() const
#endif // __APPLE__ #endif // __APPLE__
} }
float GLCanvas3DManager::GLInfo::get_max_anisotropy() const float OpenGLManager::GLInfo::get_max_anisotropy() const
{ {
if (!m_detected) if (!m_detected)
detect(); detect();
@ -86,7 +83,7 @@ float GLCanvas3DManager::GLInfo::get_max_anisotropy() const
return m_max_anisotropy; return m_max_anisotropy;
} }
void GLCanvas3DManager::GLInfo::detect() const void OpenGLManager::GLInfo::detect() const
{ {
const char* data = (const char*)::glGetString(GL_VERSION); const char* data = (const char*)::glGetString(GL_VERSION);
if (data != nullptr) if (data != nullptr)
@ -117,7 +114,7 @@ void GLCanvas3DManager::GLInfo::detect() const
m_detected = true; m_detected = true;
} }
bool GLCanvas3DManager::GLInfo::is_version_greater_or_equal_to(unsigned int major, unsigned int minor) const bool OpenGLManager::GLInfo::is_version_greater_or_equal_to(unsigned int major, unsigned int minor) const
{ {
if (!m_detected) if (!m_detected)
detect(); detect();
@ -148,7 +145,7 @@ bool GLCanvas3DManager::GLInfo::is_version_greater_or_equal_to(unsigned int majo
return gl_minor >= minor; return gl_minor >= minor;
} }
std::string GLCanvas3DManager::GLInfo::to_string(bool format_as_html, bool extensions) const std::string OpenGLManager::GLInfo::to_string(bool format_as_html, bool extensions) const
{ {
if (!m_detected) if (!m_detected)
detect(); detect();
@ -188,19 +185,19 @@ std::string GLCanvas3DManager::GLInfo::to_string(bool format_as_html, bool exten
return out.str(); return out.str();
} }
GLCanvas3DManager::GLInfo GLCanvas3DManager::s_gl_info; OpenGLManager::GLInfo OpenGLManager::s_gl_info;
bool GLCanvas3DManager::s_compressed_textures_supported = false; bool OpenGLManager::s_compressed_textures_supported = false;
GLCanvas3DManager::EMultisampleState GLCanvas3DManager::s_multisample = GLCanvas3DManager::EMultisampleState::Unknown; OpenGLManager::EMultisampleState OpenGLManager::s_multisample = OpenGLManager::EMultisampleState::Unknown;
GLCanvas3DManager::EFramebufferType GLCanvas3DManager::s_framebuffers_type = GLCanvas3DManager::EFramebufferType::Unknown; OpenGLManager::EFramebufferType OpenGLManager::s_framebuffers_type = OpenGLManager::EFramebufferType::Unknown;
#if ENABLE_HACK_CLOSING_ON_OSX_10_9_5 #if ENABLE_HACK_CLOSING_ON_OSX_10_9_5
#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
GLCanvas3DManager::OSInfo GLCanvas3DManager::s_os_info; OpenGLManager::OSInfo OpenGLManager::s_os_info;
#endif // __APPLE__ #endif // __APPLE__
#endif // ENABLE_HACK_CLOSING_ON_OSX_10_9_5 #endif // ENABLE_HACK_CLOSING_ON_OSX_10_9_5
GLCanvas3DManager::~GLCanvas3DManager() OpenGLManager::~OpenGLManager()
{ {
#if ENABLE_HACK_CLOSING_ON_OSX_10_9_5 #if ENABLE_HACK_CLOSING_ON_OSX_10_9_5
#ifdef __APPLE__ #ifdef __APPLE__
@ -221,7 +218,7 @@ GLCanvas3DManager::~GLCanvas3DManager()
#endif // ENABLE_HACK_CLOSING_ON_OSX_10_9_5 #endif // ENABLE_HACK_CLOSING_ON_OSX_10_9_5
} }
bool GLCanvas3DManager::init_gl() bool OpenGLManager::init_gl()
{ {
if (!m_gl_initialized) if (!m_gl_initialized)
{ {
@ -249,19 +246,19 @@ bool GLCanvas3DManager::init_gl()
_utf8(L("PrusaSlicer requires OpenGL 2.0 capable graphics driver to run correctly, \n" _utf8(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() % s_gl_info.get_renderer() % s_gl_info.get_vendor()).str()); "while OpenGL version %s, render %s, vendor %s was detected."))) % s_gl_info.get_version() % s_gl_info.get_renderer() % s_gl_info.get_vendor()).str());
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.");
#endif #endif
wxMessageBox(message, wxString("PrusaSlicer - ") + _(L("Unsupported OpenGL version")), wxOK | wxICON_ERROR); wxMessageBox(message, wxString("PrusaSlicer - ") + _L("Unsupported OpenGL version"), wxOK | wxICON_ERROR);
} }
} }
return true; return true;
} }
wxGLContext* GLCanvas3DManager::init_glcontext(wxGLCanvas& canvas) wxGLContext* OpenGLManager::init_glcontext(wxGLCanvas& canvas)
{ {
if (m_context == nullptr) if (m_context == nullptr)
{ {
@ -279,7 +276,7 @@ wxGLContext* GLCanvas3DManager::init_glcontext(wxGLCanvas& canvas)
return m_context; return m_context;
} }
wxGLCanvas* GLCanvas3DManager::create_wxglcanvas(wxWindow& parent) wxGLCanvas* OpenGLManager::create_wxglcanvas(wxWindow& parent)
{ {
int attribList[] = { int attribList[] = {
WX_GL_RGBA, WX_GL_RGBA,
@ -310,7 +307,7 @@ wxGLCanvas* GLCanvas3DManager::create_wxglcanvas(wxWindow& parent)
return new wxGLCanvas(&parent, wxID_ANY, attribList, wxDefaultPosition, wxDefaultSize, wxWANTS_CHARS); return new wxGLCanvas(&parent, wxID_ANY, attribList, wxDefaultPosition, wxDefaultSize, wxWANTS_CHARS);
} }
void GLCanvas3DManager::detect_multisample(int* attribList) void OpenGLManager::detect_multisample(int* attribList)
{ {
int wxVersion = wxMAJOR_VERSION * 10000 + wxMINOR_VERSION * 100 + wxRELEASE_NUMBER; int wxVersion = wxMAJOR_VERSION * 10000 + wxMINOR_VERSION * 100 + wxRELEASE_NUMBER;
bool enable_multisample = wxVersion >= 30003; bool enable_multisample = wxVersion >= 30003;

View File

@ -1,30 +1,14 @@
#ifndef slic3r_GLCanvas3DManager_hpp_ #ifndef slic3r_OpenGLManager_hpp_
#define slic3r_GLCanvas3DManager_hpp_ #define slic3r_OpenGLManager_hpp_
#include "libslic3r/BoundingBox.hpp"
#include <map>
#include <vector>
class wxWindow; class wxWindow;
class wxGLCanvas; class wxGLCanvas;
class wxGLContext; class wxGLContext;
namespace Slic3r { namespace Slic3r {
class BackgroundSlicingProcess;
class DynamicPrintConfig;
class Model;
class ExPolygon;
typedef std::vector<ExPolygon> ExPolygons;
class ModelObject;
class PrintObject;
namespace GUI { namespace GUI {
class GLCanvas3D; class OpenGLManager
class GLCanvas3DManager
{ {
public: public:
enum class EFramebufferType : unsigned char enum class EFramebufferType : unsigned char
@ -98,8 +82,8 @@ private:
static EFramebufferType s_framebuffers_type; static EFramebufferType s_framebuffers_type;
public: public:
GLCanvas3DManager() = default; OpenGLManager() = default;
~GLCanvas3DManager(); ~OpenGLManager();
bool init_gl(); bool init_gl();
@ -119,4 +103,4 @@ private:
} // namespace GUI } // namespace GUI
} // namespace Slic3r } // namespace Slic3r
#endif // slic3r_GLCanvas3DManager_hpp_ #endif // slic3r_OpenGLManager_hpp_