Merge branch 'master' of https://github.com/prusa3d/Slic3r into opengl_to_cpp

This commit is contained in:
Enrico Turri 2018-06-27 13:52:57 +02:00
commit 48915a65fd
9 changed files with 29 additions and 126 deletions

View file

@ -1449,15 +1449,14 @@ GLGizmoBase* GLCanvas3D::Gizmos::_get_current() const
return (it != m_gizmos.end()) ? it->second : nullptr;
}
GLCanvas3D::GLCanvas3D(wxGLCanvas* canvas, wxGLContext* context)
GLCanvas3D::GLCanvas3D(wxGLCanvas* canvas)
: m_canvas(canvas)
, m_context(context)
, m_context(nullptr)
, m_timer(nullptr)
, m_config(nullptr)
, m_print(nullptr)
, m_model(nullptr)
, m_dirty(true)
, m_active(true)
, m_initialized(false)
, m_use_VBOs(false)
, m_force_zoom_to_bed_enabled(false)
@ -1475,7 +1474,10 @@ GLCanvas3D::GLCanvas3D(wxGLCanvas* canvas, wxGLContext* context)
, m_reload_delayed(false)
{
if (m_canvas != nullptr)
{
m_context = new wxGLContext(m_canvas);
m_timer = new wxTimer(m_canvas);
}
}
GLCanvas3D::~GLCanvas3D()
@ -1488,6 +1490,12 @@ GLCanvas3D::~GLCanvas3D()
m_timer = nullptr;
}
if (m_context != nullptr)
{
delete m_context;
m_context = nullptr;
}
_deregister_callbacks();
}
@ -1496,6 +1504,9 @@ bool GLCanvas3D::init(bool useVBOs, bool use_legacy_opengl)
if (m_initialized)
return true;
if ((m_canvas == nullptr) || (m_context == nullptr))
return false;
::glClearColor(1.0f, 1.0f, 1.0f, 1.0f);
::glClearDepth(1.0f);
@ -1561,19 +1572,14 @@ bool GLCanvas3D::init(bool useVBOs, bool use_legacy_opengl)
return true;
}
bool GLCanvas3D::set_current(bool force)
bool GLCanvas3D::set_current()
{
if ((force || m_active) && (m_canvas != nullptr) && (m_context != nullptr))
if ((m_canvas != nullptr) && (m_context != nullptr))
return m_canvas->SetCurrent(*m_context);
return false;
}
void GLCanvas3D::set_active(bool active)
{
m_active = active;
}
void GLCanvas3D::set_as_dirty()
{
m_dirty = true;
@ -1590,7 +1596,7 @@ void GLCanvas3D::reset_volumes()
if (!m_volumes.empty())
{
// ensures this canvas is current
if ((m_canvas == nullptr) || !_3DScene::set_current(m_canvas, true))
if (!set_current())
return;
m_volumes.release_geometry();
@ -1696,6 +1702,8 @@ void GLCanvas3D::set_bed_shape(const Pointfs& shape)
// Set the origin and size for painting of the coordinate system axes.
m_axes.origin = Pointf3(0.0, 0.0, (coordf_t)GROUND_Z);
set_axes_length(0.3f * (float)m_bed.get_bounding_box().max_size());
m_dirty = true;
}
void GLCanvas3D::set_auto_bed_shape()
@ -1927,7 +1935,7 @@ void GLCanvas3D::render()
return;
// ensures this canvas is current and initialized
if (!_3DScene::set_current(m_canvas, false) || !_3DScene::init(m_canvas))
if (!set_current() || !_3DScene::init(m_canvas))
return;
if (m_force_zoom_to_bed_enabled)
@ -2010,7 +2018,7 @@ void GLCanvas3D::reload_scene(bool force)
reset_volumes();
// ensures this canvas is current
if (!_3DScene::set_current(m_canvas, true))
if (!set_current())
return;
set_bed_shape(dynamic_cast<const ConfigOptionPoints*>(m_config->option("bed_shape"))->values);
@ -2086,7 +2094,7 @@ void GLCanvas3D::reload_scene(bool force)
void GLCanvas3D::load_print_toolpaths()
{
// ensures this canvas is current
if (!_3DScene::set_current(m_canvas, true))
if (!set_current())
return;
if (m_print == nullptr)
@ -2454,7 +2462,7 @@ void GLCanvas3D::load_gcode_preview(const GCodePreviewData& preview_data, const
if ((m_canvas != nullptr) && (m_print != nullptr))
{
// ensures that this canvas is current
if (!_3DScene::set_current(m_canvas, true))
if (!set_current())
return;
if (m_volumes.empty())
@ -2783,11 +2791,7 @@ void GLCanvas3D::on_mouse(wxMouseEvent& evt)
#endif
}
else if (evt.LeftDClick() && (m_hover_volume_id != -1))
{
m_active = false;
m_on_double_click_callback.call();
m_active = true;
}
else if (evt.LeftDown() || evt.RightDown())
{
// If user pressed left or right button we first check whether this happened
@ -2883,11 +2887,7 @@ void GLCanvas3D::on_mouse(wxMouseEvent& evt)
{
// if right clicking on volume, propagate event through callback
if (m_volumes.volumes[volume_idx]->hover)
{
m_active = false;
m_on_right_click_callback.call(pos.x, pos.y);
m_active = true;
}
}
}
}
@ -3165,7 +3165,7 @@ Point GLCanvas3D::get_local_mouse_position() const
bool GLCanvas3D::_is_shown_on_screen() const
{
return (m_canvas != nullptr) ? m_active && m_canvas->IsShownOnScreen() : false;
return (m_canvas != nullptr) ? m_canvas->IsShownOnScreen() : false;
}
void GLCanvas3D::_force_zoom_to_bed()
@ -3180,7 +3180,7 @@ void GLCanvas3D::_resize(unsigned int w, unsigned int h)
return;
// ensures that this canvas is current
_3DScene::set_current(m_canvas, false);
set_current();
::glViewport(0, 0, w, h);
::glMatrixMode(GL_PROJECTION);