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

This commit is contained in:
Enrico Turri 2018-06-25 15:24:58 +02:00
commit 7b0ba7a9d4
10 changed files with 113 additions and 32 deletions

View file

@ -1561,13 +1561,10 @@ bool GLCanvas3D::init(bool useVBOs, bool use_legacy_opengl)
return true;
}
bool GLCanvas3D::set_current()
bool GLCanvas3D::set_current(bool force)
{
if ((m_canvas != nullptr) && (m_context != nullptr))
{
m_canvas->SetCurrent(*m_context);
return true;
}
if ((force || m_active) && (m_canvas != nullptr) && (m_context != nullptr))
return m_canvas->SetCurrent(*m_context);
return false;
}
@ -1589,8 +1586,13 @@ unsigned int GLCanvas3D::get_volumes_count() const
void GLCanvas3D::reset_volumes()
{
if (set_current())
if (!m_volumes.empty())
{
// ensures this canvas is current
if ((m_canvas == nullptr) || !_3DScene::set_current(m_canvas, true))
return;
m_volumes.release_geometry();
m_volumes.clear();
m_dirty = true;
@ -1924,8 +1926,8 @@ void GLCanvas3D::render()
if (!_is_shown_on_screen())
return;
// ensures that the proper context is selected and that this canvas is initialized
if (!set_current() || !_3DScene::init(m_canvas))
// ensures this canvas is current and initialized
if (!_3DScene::set_current(m_canvas, false) || !_3DScene::init(m_canvas))
return;
if (m_force_zoom_to_bed_enabled)
@ -2006,6 +2008,11 @@ void GLCanvas3D::reload_scene(bool force)
return;
reset_volumes();
// ensures this canvas is current
if (!_3DScene::set_current(m_canvas, true))
return;
set_bed_shape(dynamic_cast<const ConfigOptionPoints*>(m_config->option("bed_shape"))->values);
if (!m_canvas->IsShown() && !force)
@ -2078,6 +2085,10 @@ void GLCanvas3D::reload_scene(bool force)
void GLCanvas3D::load_print_toolpaths()
{
// ensures this canvas is current
if (!_3DScene::set_current(m_canvas, true))
return;
if (m_print == nullptr)
return;
@ -2442,8 +2453,8 @@ void GLCanvas3D::load_gcode_preview(const GCodePreviewData& preview_data, const
{
if ((m_canvas != nullptr) && (m_print != nullptr))
{
// ensures that the proper context is selected
if (!set_current())
// ensures that this canvas is current
if (!_3DScene::set_current(m_canvas, false))
return;
if (m_volumes.empty())
@ -2772,7 +2783,11 @@ 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
@ -2868,7 +2883,11 @@ 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;
}
}
}
}
@ -3157,10 +3176,11 @@ void GLCanvas3D::_force_zoom_to_bed()
void GLCanvas3D::_resize(unsigned int w, unsigned int h)
{
if (m_context == nullptr)
if ((m_canvas == nullptr) && (m_context == nullptr))
return;
set_current();
// ensures that this canvas is current
_3DScene::set_current(m_canvas, false);
::glViewport(0, 0, w, h);
::glMatrixMode(GL_PROJECTION);
@ -3749,9 +3769,11 @@ void GLCanvas3D::_perform_layer_editing_action(wxMouseEvent* evt)
Pointf3 GLCanvas3D::_mouse_to_3d(const Point& mouse_pos, float* z)
{
if (!set_current())
if (m_canvas == nullptr)
return Pointf3(DBL_MAX, DBL_MAX, DBL_MAX);
_camera_tranform();
GLint viewport[4];
::glGetIntegerv(GL_VIEWPORT, viewport);
GLdouble modelview_matrix[16];