From 0f035d0bae758338a46951b26f089b611f6c3bac Mon Sep 17 00:00:00 2001 From: Enrico Turri Date: Mon, 21 May 2018 15:24:52 +0200 Subject: [PATCH] Background rendering moved to c++ --- lib/Slic3r/GUI/3DScene.pm | 69 +++++++++++++------------ xs/src/slic3r/GUI/3DScene.cpp | 5 ++ xs/src/slic3r/GUI/3DScene.hpp | 1 + xs/src/slic3r/GUI/GLCanvas3D.cpp | 50 +++++++++++++++--- xs/src/slic3r/GUI/GLCanvas3D.hpp | 8 ++- xs/src/slic3r/GUI/GLCanvas3DManager.cpp | 7 +++ xs/src/slic3r/GUI/GLCanvas3DManager.hpp | 1 + xs/xsp/GUI_3DScene.xsp | 6 +++ 8 files changed, 105 insertions(+), 42 deletions(-) diff --git a/lib/Slic3r/GUI/3DScene.pm b/lib/Slic3r/GUI/3DScene.pm index 31982f6a9..dcd8e3110 100644 --- a/lib/Slic3r/GUI/3DScene.pm +++ b/lib/Slic3r/GUI/3DScene.pm @@ -46,7 +46,6 @@ __PACKAGE__->mk_accessors( qw(_quat init on_move on_model_update volumes - background _mouse_pos _hover_volume_idx @@ -183,7 +182,9 @@ sub new { #============================================================================================================================== $self->{can_multisample} = $can_multisample; - $self->background(1); +#============================================================================================================================== +# $self->background(1); +#============================================================================================================================== $self->_quat((0, 0, 0, 1)); #============================================================================================================================== # $self->_stheta(45); @@ -1491,38 +1492,40 @@ sub Render { } } - # draw fixed background - if ($self->background) { - glDisable(GL_LIGHTING); - glPushMatrix(); - glLoadIdentity(); - - glMatrixMode(GL_PROJECTION); - glPushMatrix(); - glLoadIdentity(); - - # Draws a bluish bottom to top gradient over the complete screen. - glDisable(GL_DEPTH_TEST); - glBegin(GL_QUADS); - glColor3f(0.0,0.0,0.0); - glVertex3f(-1.0,-1.0, 1.0); - glVertex3f( 1.0,-1.0, 1.0); - glColor3f(10/255,98/255,144/255); - glVertex3f( 1.0, 1.0, 1.0); - glVertex3f(-1.0, 1.0, 1.0); - glEnd(); - glPopMatrix(); - glEnable(GL_DEPTH_TEST); - - glMatrixMode(GL_MODELVIEW); - glPopMatrix(); - glEnable(GL_LIGHTING); - } - - # draw ground and axes - glDisable(GL_LIGHTING); - #============================================================================================================================== + Slic3r::GUI::_3DScene::render_background($self); + +# # draw fixed background +# if ($self->background) { +# glDisable(GL_LIGHTING); +# glPushMatrix(); +# glLoadIdentity(); +# +# glMatrixMode(GL_PROJECTION); +# glPushMatrix(); +# glLoadIdentity(); +# +# # Draws a bluish bottom to top gradient over the complete screen. +# glDisable(GL_DEPTH_TEST); +# glBegin(GL_QUADS); +# glColor3f(0.0,0.0,0.0); +# glVertex3f(-1.0,-1.0, 1.0); +# glVertex3f( 1.0,-1.0, 1.0); +# glColor3f(10/255,98/255,144/255); +# glVertex3f( 1.0, 1.0, 1.0); +# glVertex3f(-1.0, 1.0, 1.0); +# glEnd(); +# glPopMatrix(); +# glEnable(GL_DEPTH_TEST); +# +# glMatrixMode(GL_MODELVIEW); +# glPopMatrix(); +# glEnable(GL_LIGHTING); +# } +# +# # draw ground and axes +# glDisable(GL_LIGHTING); +# # # draw ground # my $ground_z = GROUND_Z; #============================================================================================================================== diff --git a/xs/src/slic3r/GUI/3DScene.cpp b/xs/src/slic3r/GUI/3DScene.cpp index 87a3c9aad..40e6f1851 100644 --- a/xs/src/slic3r/GUI/3DScene.cpp +++ b/xs/src/slic3r/GUI/3DScene.cpp @@ -1923,6 +1923,11 @@ void _3DScene::select_view(wxGLCanvas* canvas, const std::string& direction) s_canvas_mgr.select_view(canvas, direction); } +void _3DScene::render_background(wxGLCanvas* canvas) +{ + s_canvas_mgr.render_background(canvas); +} + void _3DScene::render_bed(wxGLCanvas* canvas) { s_canvas_mgr.render_bed(canvas); diff --git a/xs/src/slic3r/GUI/3DScene.hpp b/xs/src/slic3r/GUI/3DScene.hpp index a3d976018..22b869563 100644 --- a/xs/src/slic3r/GUI/3DScene.hpp +++ b/xs/src/slic3r/GUI/3DScene.hpp @@ -597,6 +597,7 @@ public: static void zoom_to_volumes(wxGLCanvas* canvas); static void select_view(wxGLCanvas* canvas, const std::string& direction); + static void render_background(wxGLCanvas* canvas); static void render_bed(wxGLCanvas* canvas); static void render_axes(wxGLCanvas* canvas); static void render_cutting_plane(wxGLCanvas* canvas); diff --git a/xs/src/slic3r/GUI/GLCanvas3D.cpp b/xs/src/slic3r/GUI/GLCanvas3D.cpp index fce045906..f55563f7a 100644 --- a/xs/src/slic3r/GUI/GLCanvas3D.cpp +++ b/xs/src/slic3r/GUI/GLCanvas3D.cpp @@ -208,6 +208,7 @@ void GLCanvas3D::Bed::render() unsigned int triangles_vcount = m_triangles.get_data_size() / 3; if (triangles_vcount > 0) { + ::glDisable(GL_LIGHTING); ::glDisable(GL_DEPTH_TEST); ::glEnable(GL_BLEND); @@ -312,6 +313,7 @@ void GLCanvas3D::Axes::set_length(float length) void GLCanvas3D::Axes::render() { + ::glDisable(GL_LIGHTING); // disable depth testing so that axes are not covered by ground ::glDisable(GL_DEPTH_TEST); ::glLineWidth(2.0f); @@ -350,12 +352,18 @@ bool GLCanvas3D::CuttingPlane::set(float z, const ExPolygons& polygons) return m_lines.set_from_lines(lines, m_z); } -void GLCanvas3D::CuttingPlane::render_plane(const BoundingBoxf3& bb) +void GLCanvas3D::CuttingPlane::render(const BoundingBoxf3& bb) +{ + ::glDisable(GL_LIGHTING); + _render_plane(bb); + _render_contour(); +} + +void GLCanvas3D::CuttingPlane::_render_plane(const BoundingBoxf3& bb) { if (m_z >= 0.0f) { ::glDisable(GL_CULL_FACE); - ::glDisable(GL_LIGHTING); ::glEnable(GL_BLEND); ::glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); @@ -378,7 +386,7 @@ void GLCanvas3D::CuttingPlane::render_plane(const BoundingBoxf3& bb) } } -void GLCanvas3D::CuttingPlane::render_contour() +void GLCanvas3D::CuttingPlane::_render_contour() { ::glEnableClientState(GL_VERTEX_ARRAY); @@ -737,22 +745,50 @@ void GLCanvas3D::select_view(const std::string& direction) } } +void GLCanvas3D::render_background() +{ + static const float COLOR[3] = { 10.0f / 255.0f, 98.0f / 255.0f, 144.0f / 255.0f }; + + ::glDisable(GL_LIGHTING); + + ::glPushMatrix(); + ::glLoadIdentity(); + ::glMatrixMode(GL_PROJECTION); + ::glPushMatrix(); + ::glLoadIdentity(); + + // Draws a bluish bottom to top gradient over the complete screen. + ::glDisable(GL_DEPTH_TEST); + + ::glBegin(GL_QUADS); + ::glColor3f(0.0f, 0.0f, 0.0f); + ::glVertex3f(-1.0f, -1.0f, 1.0f); + ::glVertex3f(1.0f, -1.0f, 1.0f); + ::glColor3f(COLOR[0], COLOR[1], COLOR[2]); + ::glVertex3f(1.0f, 1.0f, 1.0f); + ::glVertex3f(-1.0f, 1.0f, 1.0f); + ::glEnd(); + + ::glEnable(GL_DEPTH_TEST); + + ::glPopMatrix(); + ::glMatrixMode(GL_MODELVIEW); + ::glPopMatrix(); +} + void GLCanvas3D::render_bed() { - ::glDisable(GL_LIGHTING); m_bed.render(); } void GLCanvas3D::render_axes() { - ::glDisable(GL_LIGHTING); m_axes.render(); } void GLCanvas3D::render_cutting_plane() { - m_cutting_plane.render_plane(volumes_bounding_box()); - m_cutting_plane.render_contour(); + m_cutting_plane.render(volumes_bounding_box()); } void GLCanvas3D::render_warning_texture() diff --git a/xs/src/slic3r/GUI/GLCanvas3D.hpp b/xs/src/slic3r/GUI/GLCanvas3D.hpp index e1ce33fad..de244511a 100644 --- a/xs/src/slic3r/GUI/GLCanvas3D.hpp +++ b/xs/src/slic3r/GUI/GLCanvas3D.hpp @@ -124,8 +124,11 @@ public: bool set(float z, const ExPolygons& polygons); - void render_plane(const BoundingBoxf3& bb); - void render_contour(); + void render(const BoundingBoxf3& bb); + + private: + void _render_plane(const BoundingBoxf3& bb); + void _render_contour(); }; class LayersEditing @@ -222,6 +225,7 @@ public: void zoom_to_volumes(); void select_view(const std::string& direction); + void render_background(); void render_bed(); void render_axes(); void render_cutting_plane(); diff --git a/xs/src/slic3r/GUI/GLCanvas3DManager.cpp b/xs/src/slic3r/GUI/GLCanvas3DManager.cpp index 7647e3525..4ff07b782 100644 --- a/xs/src/slic3r/GUI/GLCanvas3DManager.cpp +++ b/xs/src/slic3r/GUI/GLCanvas3DManager.cpp @@ -390,6 +390,13 @@ void GLCanvas3DManager::select_view(wxGLCanvas* canvas, const std::string& direc it->second->select_view(direction); } +void GLCanvas3DManager::render_background(wxGLCanvas* canvas) +{ + CanvasesMap::iterator it = _get_canvas(canvas); + if (it != m_canvases.end()) + it->second->render_background(); +} + void GLCanvas3DManager::render_bed(wxGLCanvas* canvas) { CanvasesMap::iterator it = _get_canvas(canvas); diff --git a/xs/src/slic3r/GUI/GLCanvas3DManager.hpp b/xs/src/slic3r/GUI/GLCanvas3DManager.hpp index d79152f43..f7293049e 100644 --- a/xs/src/slic3r/GUI/GLCanvas3DManager.hpp +++ b/xs/src/slic3r/GUI/GLCanvas3DManager.hpp @@ -107,6 +107,7 @@ public: void zoom_to_volumes(wxGLCanvas* canvas); void select_view(wxGLCanvas* canvas, const std::string& direction); + void render_background(wxGLCanvas* canvas); void render_bed(wxGLCanvas* canvas); void render_axes(wxGLCanvas* canvas); void render_cutting_plane(wxGLCanvas* canvas); diff --git a/xs/xsp/GUI_3DScene.xsp b/xs/xsp/GUI_3DScene.xsp index 32500b3eb..6fd23a2f0 100644 --- a/xs/xsp/GUI_3DScene.xsp +++ b/xs/xsp/GUI_3DScene.xsp @@ -444,6 +444,12 @@ select_view(canvas, direction) CODE: _3DScene::select_view((wxGLCanvas*)wxPli_sv_2_object(aTHX_ canvas, "Wx::GLCanvas"), direction); +void +render_background(canvas) + SV *canvas; + CODE: + _3DScene::render_background((wxGLCanvas*)wxPli_sv_2_object(aTHX_ canvas, "Wx::GLCanvas")); + void render_bed(canvas) SV *canvas;