mirror of
https://github.com/SoftFever/OrcaSlicer.git
synced 2025-07-11 16:57:53 -06:00
GLCanvas3DManager moved from being a static member of _3DScene to be a normal member of GUI_App
This commit is contained in:
parent
47604b6326
commit
0b629eb905
24 changed files with 738 additions and 24 deletions
|
@ -1,3 +1,4 @@
|
|||
#include "libslic3r/libslic3r.h"
|
||||
#include "GLCanvas3DManager.hpp"
|
||||
#include "../../slic3r/GUI/GUI.hpp"
|
||||
#include "../../slic3r/GUI/AppConfig.hpp"
|
||||
|
@ -23,6 +24,7 @@
|
|||
namespace Slic3r {
|
||||
namespace GUI {
|
||||
|
||||
#if !ENABLE_NON_STATIC_CANVAS_MANAGER
|
||||
GLCanvas3DManager::GLInfo::GLInfo()
|
||||
: m_detected(false)
|
||||
, m_version("")
|
||||
|
@ -33,6 +35,7 @@ GLCanvas3DManager::GLInfo::GLInfo()
|
|||
, m_max_anisotropy(0.0f)
|
||||
{
|
||||
}
|
||||
#endif // !ENABLE_NON_STATIC_CANVAS_MANAGER
|
||||
|
||||
const std::string& GLCanvas3DManager::GLInfo::get_version() const
|
||||
{
|
||||
|
@ -188,22 +191,35 @@ std::string GLCanvas3DManager::GLInfo::to_string(bool format_as_html, bool exten
|
|||
return out.str();
|
||||
}
|
||||
|
||||
GLCanvas3DManager::EMultisampleState GLCanvas3DManager::s_multisample = GLCanvas3DManager::MS_Unknown;
|
||||
bool GLCanvas3DManager::s_compressed_textures_supported = false;
|
||||
GLCanvas3DManager::EFramebufferType GLCanvas3DManager::s_framebuffers_type = GLCanvas3DManager::FB_None;
|
||||
GLCanvas3DManager::GLInfo GLCanvas3DManager::s_gl_info;
|
||||
bool GLCanvas3DManager::s_compressed_textures_supported = false;
|
||||
#if ENABLE_NON_STATIC_CANVAS_MANAGER
|
||||
GLCanvas3DManager::EMultisampleState GLCanvas3DManager::s_multisample = GLCanvas3DManager::EMultisampleState::Unknown;
|
||||
GLCanvas3DManager::EFramebufferType GLCanvas3DManager::s_framebuffers_type = GLCanvas3DManager::EFramebufferType::None;
|
||||
#else
|
||||
GLCanvas3DManager::EMultisampleState GLCanvas3DManager::s_multisample = GLCanvas3DManager::MS_Unknown;
|
||||
GLCanvas3DManager::EFramebufferType GLCanvas3DManager::s_framebuffers_type = GLCanvas3DManager::FB_None;
|
||||
#endif // ENABLE_NON_STATIC_CANVAS_MANAGER
|
||||
|
||||
#if !ENABLE_NON_STATIC_CANVAS_MANAGER
|
||||
GLCanvas3DManager::GLCanvas3DManager()
|
||||
: m_context(nullptr)
|
||||
, m_gl_initialized(false)
|
||||
{
|
||||
}
|
||||
#endif // !ENABLE_NON_STATIC_CANVAS_MANAGER
|
||||
|
||||
GLCanvas3DManager::~GLCanvas3DManager()
|
||||
{
|
||||
this->destroy();
|
||||
#if ENABLE_NON_STATIC_CANVAS_MANAGER
|
||||
if (m_context != nullptr)
|
||||
delete m_context;
|
||||
#else
|
||||
this->destroy();
|
||||
#endif // ENABLE_NON_STATIC_CANVAS_MANAGER
|
||||
}
|
||||
|
||||
#if !ENABLE_NON_STATIC_CANVAS_MANAGER
|
||||
bool GLCanvas3DManager::add(wxGLCanvas* canvas, Bed3D& bed, Camera& camera, GLToolbar& view_toolbar)
|
||||
{
|
||||
if (canvas == nullptr)
|
||||
|
@ -255,28 +271,50 @@ void GLCanvas3DManager::remove_all()
|
|||
m_canvases.clear();
|
||||
}
|
||||
|
||||
unsigned int GLCanvas3DManager::count() const
|
||||
size_t GLCanvas3DManager::count() const
|
||||
{
|
||||
return (unsigned int)m_canvases.size();
|
||||
return m_canvases.size();
|
||||
}
|
||||
#endif // !ENABLE_NON_STATIC_CANVAS_MANAGER
|
||||
|
||||
#if ENABLE_NON_STATIC_CANVAS_MANAGER
|
||||
bool GLCanvas3DManager::init_gl()
|
||||
#else
|
||||
void GLCanvas3DManager::init_gl()
|
||||
#endif // ENABLE_NON_STATIC_CANVAS_MANAGER
|
||||
{
|
||||
if (!m_gl_initialized)
|
||||
{
|
||||
#if ENABLE_NON_STATIC_CANVAS_MANAGER
|
||||
if (glewInit() != GLEW_OK)
|
||||
{
|
||||
BOOST_LOG_TRIVIAL(error) << "Unable to init glew library";
|
||||
return false;
|
||||
}
|
||||
#else
|
||||
glewInit();
|
||||
#endif // ENABLE_NON_STATIC_CANVAS_MANAGER
|
||||
m_gl_initialized = true;
|
||||
if (GLEW_EXT_texture_compression_s3tc)
|
||||
s_compressed_textures_supported = true;
|
||||
else
|
||||
s_compressed_textures_supported = false;
|
||||
|
||||
#if ENABLE_NON_STATIC_CANVAS_MANAGER
|
||||
if (GLEW_ARB_framebuffer_object)
|
||||
s_framebuffers_type = EFramebufferType::Arb;
|
||||
else if (GLEW_EXT_framebuffer_object)
|
||||
s_framebuffers_type = EFramebufferType::Ext;
|
||||
else
|
||||
s_framebuffers_type = EFramebufferType::None;
|
||||
#else
|
||||
if (GLEW_ARB_framebuffer_object)
|
||||
s_framebuffers_type = FB_Arb;
|
||||
else if (GLEW_EXT_framebuffer_object)
|
||||
s_framebuffers_type = FB_Ext;
|
||||
else
|
||||
s_framebuffers_type = FB_None;
|
||||
#endif // ENABLE_NON_STATIC_CANVAS_MANAGER
|
||||
|
||||
if (! s_gl_info.is_version_greater_or_equal_to(2, 0)) {
|
||||
// Complain about the OpenGL version.
|
||||
|
@ -292,8 +330,21 @@ void GLCanvas3DManager::init_gl()
|
|||
wxMessageBox(message, wxString("PrusaSlicer - ") + _(L("Unsupported OpenGL version")), wxOK | wxICON_ERROR);
|
||||
}
|
||||
}
|
||||
|
||||
#if ENABLE_NON_STATIC_CANVAS_MANAGER
|
||||
return true;
|
||||
#endif // ENABLE_NON_STATIC_CANVAS_MANAGER
|
||||
}
|
||||
|
||||
#if ENABLE_NON_STATIC_CANVAS_MANAGER
|
||||
wxGLContext* GLCanvas3DManager::init_glcontext(wxGLCanvas& canvas)
|
||||
{
|
||||
if (m_context == nullptr)
|
||||
m_context = new wxGLContext(&canvas);
|
||||
|
||||
return m_context;
|
||||
}
|
||||
#else
|
||||
bool GLCanvas3DManager::init(wxGLCanvas* canvas)
|
||||
{
|
||||
CanvasesMap::const_iterator it = do_get_canvas(canvas);
|
||||
|
@ -311,14 +362,21 @@ void GLCanvas3DManager::destroy()
|
|||
m_context = nullptr;
|
||||
}
|
||||
}
|
||||
#endif // ENABLE_NON_STATIC_CANVAS_MANAGER
|
||||
|
||||
#if !ENABLE_NON_STATIC_CANVAS_MANAGER
|
||||
GLCanvas3D* GLCanvas3DManager::get_canvas(wxGLCanvas* canvas)
|
||||
{
|
||||
CanvasesMap::const_iterator it = do_get_canvas(canvas);
|
||||
return (it != m_canvases.end()) ? it->second : nullptr;
|
||||
}
|
||||
#endif // !ENABLE_NON_STATIC_CANVAS_MANAGER
|
||||
|
||||
#if ENABLE_NON_STATIC_CANVAS_MANAGER
|
||||
wxGLCanvas* GLCanvas3DManager::create_wxglcanvas(wxWindow& parent)
|
||||
#else
|
||||
wxGLCanvas* GLCanvas3DManager::create_wxglcanvas(wxWindow *parent)
|
||||
#endif // ENABLE_NON_STATIC_CANVAS_MANAGER
|
||||
{
|
||||
int attribList[] = {
|
||||
WX_GL_RGBA,
|
||||
|
@ -336,7 +394,11 @@ wxGLCanvas* GLCanvas3DManager::create_wxglcanvas(wxWindow *parent)
|
|||
0
|
||||
};
|
||||
|
||||
#if ENABLE_NON_STATIC_CANVAS_MANAGER
|
||||
if (s_multisample == EMultisampleState::Unknown)
|
||||
#else
|
||||
if (s_multisample == MS_Unknown)
|
||||
#endif // ENABLE_NON_STATIC_CANVAS_MANAGER
|
||||
{
|
||||
detect_multisample(attribList);
|
||||
// // debug output
|
||||
|
@ -346,9 +408,14 @@ wxGLCanvas* GLCanvas3DManager::create_wxglcanvas(wxWindow *parent)
|
|||
if (! can_multisample())
|
||||
attribList[12] = 0;
|
||||
|
||||
#if ENABLE_NON_STATIC_CANVAS_MANAGER
|
||||
return new wxGLCanvas(&parent, wxID_ANY, attribList, wxDefaultPosition, wxDefaultSize, wxWANTS_CHARS);
|
||||
#else
|
||||
return new wxGLCanvas(parent, wxID_ANY, attribList, wxDefaultPosition, wxDefaultSize, wxWANTS_CHARS);
|
||||
#endif // ENABLE_NON_STATIC_CANVAS_MANAGER
|
||||
}
|
||||
|
||||
#if !ENABLE_NON_STATIC_CANVAS_MANAGER
|
||||
GLCanvas3DManager::CanvasesMap::iterator GLCanvas3DManager::do_get_canvas(wxGLCanvas* canvas)
|
||||
{
|
||||
return (canvas == nullptr) ? m_canvases.end() : m_canvases.find(canvas);
|
||||
|
@ -366,12 +433,17 @@ bool GLCanvas3DManager::init(GLCanvas3D& canvas)
|
|||
|
||||
return canvas.init();
|
||||
}
|
||||
#endif // !ENABLE_NON_STATIC_CANVAS_MANAGER
|
||||
|
||||
void GLCanvas3DManager::detect_multisample(int* attribList)
|
||||
{
|
||||
int wxVersion = wxMAJOR_VERSION * 10000 + wxMINOR_VERSION * 100 + wxRELEASE_NUMBER;
|
||||
bool enable_multisample = wxVersion >= 30003;
|
||||
#if ENABLE_NON_STATIC_CANVAS_MANAGER
|
||||
s_multisample = (enable_multisample && wxGLCanvas::IsDisplaySupported(attribList)) ? EMultisampleState::Enabled : EMultisampleState::Disabled;
|
||||
#else
|
||||
s_multisample = (enable_multisample && wxGLCanvas::IsDisplaySupported(attribList)) ? MS_Enabled : MS_Disabled;
|
||||
#endif // ENABLE_NON_STATIC_CANVAS_MANAGER
|
||||
// Alternative method: it was working on previous version of wxWidgets but not with the latest, at least on Windows
|
||||
// s_multisample = enable_multisample && wxGLCanvas::IsExtensionSupported("WGL_ARB_multisample");
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue