From 97b7ef7dc0e3d5185eae67edc2d14236a8b659a1 Mon Sep 17 00:00:00 2001 From: Lukas Matena Date: Fri, 12 Mar 2021 10:29:17 +0100 Subject: [PATCH] Removed GLU calls from all the gizmos --- src/libslic3r/TriangleMesh.cpp | 27 +++++ src/libslic3r/TriangleMesh.hpp | 4 +- src/slic3r/GUI/Gizmos/GLGizmoBase.cpp | 70 +++--------- src/slic3r/GUI/Gizmos/GLGizmoBase.hpp | 7 +- src/slic3r/GUI/Gizmos/GLGizmoHollow.cpp | 51 +++------ src/slic3r/GUI/Gizmos/GLGizmoHollow.hpp | 6 +- src/slic3r/GUI/Gizmos/GLGizmoMove.cpp | 20 +--- src/slic3r/GUI/Gizmos/GLGizmoMove.hpp | 4 +- src/slic3r/GUI/Gizmos/GLGizmoRotate.cpp | 20 +--- src/slic3r/GUI/Gizmos/GLGizmoRotate.hpp | 4 +- src/slic3r/GUI/Gizmos/GLGizmoSlaSupports.cpp | 112 +++++++++---------- src/slic3r/GUI/Gizmos/GLGizmoSlaSupports.hpp | 4 +- 12 files changed, 129 insertions(+), 200 deletions(-) diff --git a/src/libslic3r/TriangleMesh.cpp b/src/libslic3r/TriangleMesh.cpp index fba1429ea..99f2c9641 100644 --- a/src/libslic3r/TriangleMesh.cpp +++ b/src/libslic3r/TriangleMesh.cpp @@ -1014,6 +1014,33 @@ TriangleMesh make_cylinder(double r, double h, double fa) return mesh; } + +TriangleMesh make_cone(double r, double h, double fa) +{ + Pointf3s vertices; + std::vector facets; + vertices.reserve(3+size_t(2*PI/fa)); + vertices.reserve(3+2*size_t(2*PI/fa)); + + vertices = { Vec3d::Zero(), Vec3d(0., 0., h) }; // base center and top vertex + size_t i = 0; + for (double angle=0; angle<2*PI; angle+=fa) { + vertices.emplace_back(r*std::cos(angle), r*std::sin(angle), 0.); + if (angle > 0.) { + facets.emplace_back(0, i+2, i+1); + facets.emplace_back(1, i+1, i+2); + } + ++i; + } + facets.emplace_back(0, 2, i+1); // close the shape + facets.emplace_back(1, i+1, 2); + + TriangleMesh mesh(std::move(vertices), std::move(facets)); + mesh.repair(); + return mesh; +} + + // Generates mesh for a sphere centered about the origin, using the generated angle // to determine the granularity. // Default angle is 1 degree. diff --git a/src/libslic3r/TriangleMesh.hpp b/src/libslic3r/TriangleMesh.hpp index 49b11465e..24447d896 100644 --- a/src/libslic3r/TriangleMesh.hpp +++ b/src/libslic3r/TriangleMesh.hpp @@ -122,10 +122,8 @@ Polygon its_convex_hull_2d_above(const indexed_triangle_set &its, const Matrix3f Polygon its_convex_hull_2d_above(const indexed_triangle_set &its, const Transform3f &t, const float z); TriangleMesh make_cube(double x, double y, double z); - -// Generate a TriangleMesh of a cylinder TriangleMesh make_cylinder(double r, double h, double fa=(2*PI/360)); - +TriangleMesh make_cone(double r, double h, double fa=(2*PI/360)); TriangleMesh make_sphere(double rho, double fa=(2*PI/360)); } diff --git a/src/slic3r/GUI/Gizmos/GLGizmoBase.cpp b/src/slic3r/GUI/Gizmos/GLGizmoBase.cpp index 9bc34f990..ca9b2408c 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmoBase.cpp +++ b/src/slic3r/GUI/Gizmos/GLGizmoBase.cpp @@ -13,6 +13,10 @@ namespace GUI { const float GLGizmoBase::Grabber::SizeFactor = 0.05f; const float GLGizmoBase::Grabber::MinHalfSize = 1.5f; const float GLGizmoBase::Grabber::DraggingScaleFactor = 1.25f; +GLModel GLGizmoBase::Grabber::VBOCube; +GLModel GLGizmoBase::VBOCone; +GLModel GLGizmoBase::VBOCylinder; +GLModel GLGizmoBase::VBOSphere; GLGizmoBase::Grabber::Grabber() : center(Vec3d::Zero()) @@ -24,6 +28,9 @@ GLGizmoBase::Grabber::Grabber() color[1] = 1.0f; color[2] = 1.0f; color[3] = 1.0f; + TriangleMesh cube = make_cube(1., 1., 1.); + cube.translate(Vec3f(-0.5, -0.5, -0.5)); + VBOCube.init_from(cube); } void GLGizmoBase::Grabber::render(bool hover, float size) const @@ -54,7 +61,7 @@ float GLGizmoBase::Grabber::get_dragging_half_size(float size) const void GLGizmoBase::Grabber::render(float size, const float* render_color, bool use_lighting) const { - float half_size = dragging ? get_dragging_half_size(size) : get_half_size(size); + float fullsize = 2 * (dragging ? get_dragging_half_size(size) : get_half_size(size)); if (use_lighting) glsafe(::glEnable(GL_LIGHTING)); @@ -63,71 +70,17 @@ void GLGizmoBase::Grabber::render(float size, const float* render_color, bool us glsafe(::glPushMatrix()); glsafe(::glTranslated(center(0), center(1), center(2))); - glsafe(::glRotated(Geometry::rad2deg(angles(2)), 0.0, 0.0, 1.0)); glsafe(::glRotated(Geometry::rad2deg(angles(1)), 0.0, 1.0, 0.0)); glsafe(::glRotated(Geometry::rad2deg(angles(0)), 1.0, 0.0, 0.0)); - - // face min x - glsafe(::glPushMatrix()); - glsafe(::glTranslatef(-(GLfloat)half_size, 0.0f, 0.0f)); - glsafe(::glRotatef(-90.0f, 0.0f, 1.0f, 0.0f)); - render_face(half_size); - glsafe(::glPopMatrix()); - - // face max x - glsafe(::glPushMatrix()); - glsafe(::glTranslatef((GLfloat)half_size, 0.0f, 0.0f)); - glsafe(::glRotatef(90.0f, 0.0f, 1.0f, 0.0f)); - render_face(half_size); - glsafe(::glPopMatrix()); - - // face min y - glsafe(::glPushMatrix()); - glsafe(::glTranslatef(0.0f, -(GLfloat)half_size, 0.0f)); - glsafe(::glRotatef(90.0f, 1.0f, 0.0f, 0.0f)); - render_face(half_size); - glsafe(::glPopMatrix()); - - // face max y - glsafe(::glPushMatrix()); - glsafe(::glTranslatef(0.0f, (GLfloat)half_size, 0.0f)); - glsafe(::glRotatef(-90.0f, 1.0f, 0.0f, 0.0f)); - render_face(half_size); - glsafe(::glPopMatrix()); - - // face min z - glsafe(::glPushMatrix()); - glsafe(::glTranslatef(0.0f, 0.0f, -(GLfloat)half_size)); - glsafe(::glRotatef(180.0f, 1.0f, 0.0f, 0.0f)); - render_face(half_size); - glsafe(::glPopMatrix()); - - // face max z - glsafe(::glPushMatrix()); - glsafe(::glTranslatef(0.0f, 0.0f, (GLfloat)half_size)); - render_face(half_size); - glsafe(::glPopMatrix()); - + glsafe(::glScaled(fullsize, fullsize, fullsize)); + VBOCube.render(); glsafe(::glPopMatrix()); if (use_lighting) glsafe(::glDisable(GL_LIGHTING)); } -void GLGizmoBase::Grabber::render_face(float half_size) const -{ - ::glBegin(GL_TRIANGLES); - ::glNormal3f(0.0f, 0.0f, 1.0f); - ::glVertex3f(-(GLfloat)half_size, -(GLfloat)half_size, 0.0f); - ::glVertex3f((GLfloat)half_size, -(GLfloat)half_size, 0.0f); - ::glVertex3f((GLfloat)half_size, (GLfloat)half_size, 0.0f); - ::glVertex3f((GLfloat)half_size, (GLfloat)half_size, 0.0f); - ::glVertex3f(-(GLfloat)half_size, (GLfloat)half_size, 0.0f); - ::glVertex3f(-(GLfloat)half_size, -(GLfloat)half_size, 0.0f); - glsafe(::glEnd()); -} - GLGizmoBase::GLGizmoBase(GLCanvas3D& parent, const std::string& icon_filename, unsigned int sprite_id) : m_parent(parent) @@ -144,6 +97,9 @@ GLGizmoBase::GLGizmoBase(GLCanvas3D& parent, const std::string& icon_filename, u ::memcpy((void*)m_base_color, (const void*)DEFAULT_BASE_COLOR, 4 * sizeof(float)); ::memcpy((void*)m_drag_color, (const void*)DEFAULT_DRAG_COLOR, 4 * sizeof(float)); ::memcpy((void*)m_highlight_color, (const void*)DEFAULT_HIGHLIGHT_COLOR, 4 * sizeof(float)); + VBOCone.init_from(make_cone(1., 1., 2*PI/24)); + VBOSphere.init_from(make_sphere(1., (2*M_PI)/24.)); + VBOCylinder.init_from(make_cylinder(1., 1., 2*PI/24.)); } void GLGizmoBase::set_hover_id(int id) diff --git a/src/slic3r/GUI/Gizmos/GLGizmoBase.hpp b/src/slic3r/GUI/Gizmos/GLGizmoBase.hpp index 44f0a6972..b49619470 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmoBase.hpp +++ b/src/slic3r/GUI/Gizmos/GLGizmoBase.hpp @@ -4,6 +4,7 @@ #include "libslic3r/Point.hpp" #include "slic3r/GUI/I18N.hpp" +#include "slic3r/GUI/GLModel.hpp" #include @@ -47,6 +48,8 @@ protected: static const float SizeFactor; static const float MinHalfSize; static const float DraggingScaleFactor; + static GLModel VBOCube; + static GLModel VBOCone; Vec3d center; Vec3d angles; @@ -64,7 +67,6 @@ protected: private: void render(float size, const float* render_color, bool use_lighting) const; - void render_face(float half_size) const; }; public: @@ -103,6 +105,9 @@ protected: bool m_first_input_window_render; mutable std::string m_tooltip; CommonGizmosDataPool* m_c; + static GLModel VBOCone; + static GLModel VBOCylinder; + static GLModel VBOSphere; public: GLGizmoBase(GLCanvas3D& parent, diff --git a/src/slic3r/GUI/Gizmos/GLGizmoHollow.cpp b/src/slic3r/GUI/Gizmos/GLGizmoHollow.cpp index 9db50e6f1..515e0ea76 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmoHollow.cpp +++ b/src/slic3r/GUI/Gizmos/GLGizmoHollow.cpp @@ -19,20 +19,10 @@ namespace GUI { GLGizmoHollow::GLGizmoHollow(GLCanvas3D& parent, const std::string& icon_filename, unsigned int sprite_id) : GLGizmoBase(parent, icon_filename, sprite_id) - , m_quadric(nullptr) { - m_quadric = ::gluNewQuadric(); - if (m_quadric != nullptr) - // using GLU_FILL does not work when the instance's transformation - // contains mirroring (normals are reverted) - ::gluQuadricDrawStyle(m_quadric, GLU_FILL); + m_vbo_cylinder.init_from(make_cylinder(1., 1.)); } -GLGizmoHollow::~GLGizmoHollow() -{ - if (m_quadric != nullptr) - ::gluDeleteQuadric(m_quadric); -} bool GLGizmoHollow::on_init() { @@ -87,7 +77,7 @@ void GLGizmoHollow::on_render() const glsafe(::glEnable(GL_BLEND)); glsafe(::glEnable(GL_DEPTH_TEST)); - if (m_quadric != nullptr && selection.is_from_single_instance()) + if (selection.is_from_single_instance()) render_points(selection, false); m_selection_rectangle.render(m_parent); @@ -111,8 +101,10 @@ void GLGizmoHollow::on_render_for_picking() const void GLGizmoHollow::render_points(const Selection& selection, bool picking) const { - if (!picking) - glsafe(::glEnable(GL_LIGHTING)); + GLShaderProgram* shader = picking ? nullptr : wxGetApp().get_shader("gouraud_light"); + if (shader) + shader->start_using(); + ScopeGuard guard([shader]() { if (shader) shader->stop_using(); }); const GLVolume* vol = selection.get_volume(*selection.get_volume_idxs().begin()); const Transform3d& instance_scaling_matrix_inverse = vol->get_instance_transformation().get_matrix(true, true, false, true).inverse(); @@ -150,16 +142,17 @@ void GLGizmoHollow::render_points(const Selection& selection, bool picking) cons } else { // neigher hover nor picking - render_color[0] = point_selected ? 1.0f : 0.7f; - render_color[1] = point_selected ? 0.3f : 0.7f; - render_color[2] = point_selected ? 0.3f : 0.7f; + render_color[0] = point_selected ? 1.0f : 1.f; + render_color[1] = point_selected ? 0.3f : 1.f; + render_color[2] = point_selected ? 0.3f : 1.f; render_color[3] = 0.5f; } } - glsafe(::glColor4fv(render_color.data())); - float render_color_emissive[4] = { 0.5f * render_color[0], 0.5f * render_color[1], 0.5f * render_color[2], 1.f}; - glsafe(::glMaterialfv(GL_FRONT, GL_EMISSION, render_color_emissive)); + if (shader && ! picking) + shader->set_uniform("uniform_color", render_color); + else // picking + glsafe(::glColor4fv(render_color.data())); // Inverse matrix of the instance scaling is applied so that the mark does not scale with the object. glsafe(::glPushMatrix()); @@ -176,12 +169,8 @@ void GLGizmoHollow::render_points(const Selection& selection, bool picking) cons glsafe(::glRotated(aa.angle() * (180. / M_PI), aa.axis()(0), aa.axis()(1), aa.axis()(2))); glsafe(::glPushMatrix()); glsafe(::glTranslated(0., 0., -drain_hole.height)); - ::gluCylinder(m_quadric, drain_hole.radius, drain_hole.radius, drain_hole.height + sla::HoleStickOutLength, 24, 1); - glsafe(::glTranslated(0., 0., drain_hole.height + sla::HoleStickOutLength)); - ::gluDisk(m_quadric, 0.0, drain_hole.radius, 24, 1); - glsafe(::glTranslated(0., 0., -drain_hole.height - sla::HoleStickOutLength)); - glsafe(::glRotatef(180.f, 1.f, 0.f, 0.f)); - ::gluDisk(m_quadric, 0.0, drain_hole.radius, 24, 1); + glsafe(::glScaled(drain_hole.radius, drain_hole.radius, drain_hole.height + sla::HoleStickOutLength)); + m_vbo_cylinder.render(); glsafe(::glPopMatrix()); if (vol->is_left_handed()) @@ -189,14 +178,8 @@ void GLGizmoHollow::render_points(const Selection& selection, bool picking) cons glsafe(::glPopMatrix()); } - { - // Reset emissive component to zero (the default value) - float render_color_emissive[4] = { 0.f, 0.f, 0.f, 1.f }; - glsafe(::glMaterialfv(GL_FRONT, GL_EMISSION, render_color_emissive)); - } - - if (!picking) - glsafe(::glDisable(GL_LIGHTING)); + //if (!picking) + // glsafe(::glDisable(GL_LIGHTING)); glsafe(::glPopMatrix()); } diff --git a/src/slic3r/GUI/Gizmos/GLGizmoHollow.hpp b/src/slic3r/GUI/Gizmos/GLGizmoHollow.hpp index 5d34f04d6..1bcf1713e 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmoHollow.hpp +++ b/src/slic3r/GUI/Gizmos/GLGizmoHollow.hpp @@ -25,12 +25,10 @@ class GLGizmoHollow : public GLGizmoBase private: bool unproject_on_mesh(const Vec2d& mouse_pos, std::pair& pos_and_normal); - GLUquadricObj* m_quadric; - public: GLGizmoHollow(GLCanvas3D& parent, const std::string& icon_filename, unsigned int sprite_id); - ~GLGizmoHollow() override; + virtual ~GLGizmoHollow() = default; void set_sla_support_data(ModelObject* model_object, const Selection& selection); bool gizmo_event(SLAGizmoEventType action, const Vec2d& mouse_position, bool shift_down, bool alt_down, bool control_down); void delete_selected_points(); @@ -50,7 +48,7 @@ private: ObjectID m_old_mo_id = -1; - // bool m_show_supports = true; + GLModel m_vbo_cylinder; float m_new_hole_radius = 2.f; // Size of a new hole. float m_new_hole_height = 6.f; mutable std::vector m_selected; // which holes are currently selected diff --git a/src/slic3r/GUI/Gizmos/GLGizmoMove.cpp b/src/slic3r/GUI/Gizmos/GLGizmoMove.cpp index f349776ab..0b65982b7 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmoMove.cpp +++ b/src/slic3r/GUI/Gizmos/GLGizmoMove.cpp @@ -18,17 +18,8 @@ GLGizmoMove3D::GLGizmoMove3D(GLCanvas3D& parent, const std::string& icon_filenam , m_starting_drag_position(Vec3d::Zero()) , m_starting_box_center(Vec3d::Zero()) , m_starting_box_bottom_center(Vec3d::Zero()) - , m_quadric(nullptr) { - m_quadric = ::gluNewQuadric(); - if (m_quadric != nullptr) - ::gluQuadricDrawStyle(m_quadric, GLU_FILL); -} - -GLGizmoMove3D::~GLGizmoMove3D() -{ - if (m_quadric != nullptr) - ::gluDeleteQuadric(m_quadric); + m_vbo_cone.init_from(make_cone(1., 1., 2*PI/36)); } std::string GLGizmoMove3D::get_tooltip() const @@ -200,9 +191,6 @@ double GLGizmoMove3D::calc_projection(const UpdateData& data) const void GLGizmoMove3D::render_grabber_extension(Axis axis, const BoundingBoxf3& box, bool picking) const { - if (m_quadric == nullptr) - return; - float mean_size = (float)((box.size()(0) + box.size()(1) + box.size()(2)) / 3.0); double size = m_dragging ? (double)m_grabbers[axis].get_dragging_half_size(mean_size) : (double)m_grabbers[axis].get_half_size(mean_size); @@ -228,10 +216,8 @@ void GLGizmoMove3D::render_grabber_extension(Axis axis, const BoundingBoxf3& box glsafe(::glRotated(-90.0, 1.0, 0.0, 0.0)); glsafe(::glTranslated(0.0, 0.0, 2.0 * size)); - ::gluQuadricOrientation(m_quadric, GLU_OUTSIDE); - ::gluCylinder(m_quadric, 0.75 * size, 0.0, 3.0 * size, 36, 1); - ::gluQuadricOrientation(m_quadric, GLU_INSIDE); - ::gluDisk(m_quadric, 0.0, 0.75 * size, 36, 1); + glsafe(::glScaled(0.75 * size, 0.75 * size, 3.0 * size)); + m_vbo_cone.render(); glsafe(::glPopMatrix()); if (!picking) diff --git a/src/slic3r/GUI/Gizmos/GLGizmoMove.hpp b/src/slic3r/GUI/Gizmos/GLGizmoMove.hpp index 20aa9f56c..9a86852d6 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmoMove.hpp +++ b/src/slic3r/GUI/Gizmos/GLGizmoMove.hpp @@ -19,11 +19,11 @@ class GLGizmoMove3D : public GLGizmoBase Vec3d m_starting_box_center; Vec3d m_starting_box_bottom_center; - GLUquadricObj* m_quadric; + GLModel m_vbo_cone; public: GLGizmoMove3D(GLCanvas3D& parent, const std::string& icon_filename, unsigned int sprite_id); - virtual ~GLGizmoMove3D(); + virtual ~GLGizmoMove3D() = default; double get_snap_step(double step) const { return m_snap_step; } void set_snap_step(double step) { m_snap_step = step; } diff --git a/src/slic3r/GUI/Gizmos/GLGizmoRotate.cpp b/src/slic3r/GUI/Gizmos/GLGizmoRotate.cpp index 6b6905e4d..eceeb5e87 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmoRotate.cpp +++ b/src/slic3r/GUI/Gizmos/GLGizmoRotate.cpp @@ -38,9 +38,6 @@ GLGizmoRotate::GLGizmoRotate(GLCanvas3D& parent, GLGizmoRotate::Axis axis) , m_snap_fine_in_radius(0.0f) , m_snap_fine_out_radius(0.0f) { - m_quadric = ::gluNewQuadric(); - if (m_quadric != nullptr) - ::gluQuadricDrawStyle(m_quadric, GLU_FILL); } GLGizmoRotate::GLGizmoRotate(const GLGizmoRotate& other) @@ -60,11 +57,6 @@ GLGizmoRotate::GLGizmoRotate(const GLGizmoRotate& other) ::gluQuadricDrawStyle(m_quadric, GLU_FILL); } -GLGizmoRotate::~GLGizmoRotate() -{ - if (m_quadric != nullptr) - ::gluDeleteQuadric(m_quadric); -} void GLGizmoRotate::set_angle(double angle) { @@ -361,20 +353,16 @@ void GLGizmoRotate::render_grabber_extension(const BoundingBoxf3& box, bool pick glsafe(::glRotated(Geometry::rad2deg(m_angle), 0.0, 0.0, 1.0)); glsafe(::glRotated(90.0, 1.0, 0.0, 0.0)); glsafe(::glTranslated(0.0, 0.0, 2.0 * size)); - ::gluQuadricOrientation(m_quadric, GLU_OUTSIDE); - ::gluCylinder(m_quadric, 0.75 * size, 0.0, 3.0 * size, 36, 1); - ::gluQuadricOrientation(m_quadric, GLU_INSIDE); - ::gluDisk(m_quadric, 0.0, 0.75 * size, 36, 1); + glsafe(::glScaled(0.75 * size, 0.75 * size, 3.0 * size)); + VBOCone.render(); glsafe(::glPopMatrix()); glsafe(::glPushMatrix()); glsafe(::glTranslated(m_grabbers[0].center(0), m_grabbers[0].center(1), m_grabbers[0].center(2))); glsafe(::glRotated(Geometry::rad2deg(m_angle), 0.0, 0.0, 1.0)); glsafe(::glRotated(-90.0, 1.0, 0.0, 0.0)); glsafe(::glTranslated(0.0, 0.0, 2.0 * size)); - ::gluQuadricOrientation(m_quadric, GLU_OUTSIDE); - ::gluCylinder(m_quadric, 0.75 * size, 0.0, 3.0 * size, 36, 1); - ::gluQuadricOrientation(m_quadric, GLU_INSIDE); - ::gluDisk(m_quadric, 0.0, 0.75 * size, 36, 1); + glsafe(::glScaled(0.75 * size, 0.75 * size, 3.0 * size)); + VBOCone.render(); glsafe(::glPopMatrix()); if (!picking) diff --git a/src/slic3r/GUI/Gizmos/GLGizmoRotate.hpp b/src/slic3r/GUI/Gizmos/GLGizmoRotate.hpp index c18d0eefd..88a5ba169 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmoRotate.hpp +++ b/src/slic3r/GUI/Gizmos/GLGizmoRotate.hpp @@ -32,8 +32,6 @@ private: Axis m_axis; double m_angle; - GLUquadricObj* m_quadric; - mutable Vec3d m_center; mutable float m_radius; @@ -45,7 +43,7 @@ private: public: GLGizmoRotate(GLCanvas3D& parent, Axis axis); GLGizmoRotate(const GLGizmoRotate& other); - virtual ~GLGizmoRotate(); + virtual ~GLGizmoRotate() = default; double get_angle() const { return m_angle; } void set_angle(double angle); diff --git a/src/slic3r/GUI/Gizmos/GLGizmoSlaSupports.cpp b/src/slic3r/GUI/Gizmos/GLGizmoSlaSupports.cpp index 7ff274aac..ac63d6b72 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmoSlaSupports.cpp +++ b/src/slic3r/GUI/Gizmos/GLGizmoSlaSupports.cpp @@ -26,20 +26,9 @@ namespace GUI { GLGizmoSlaSupports::GLGizmoSlaSupports(GLCanvas3D& parent, const std::string& icon_filename, unsigned int sprite_id) : GLGizmoBase(parent, icon_filename, sprite_id) - , m_quadric(nullptr) -{ - m_quadric = ::gluNewQuadric(); - if (m_quadric != nullptr) - // using GLU_FILL does not work when the instance's transformation - // contains mirroring (normals are reverted) - ::gluQuadricDrawStyle(m_quadric, GLU_FILL); +{ } -GLGizmoSlaSupports::~GLGizmoSlaSupports() -{ - if (m_quadric != nullptr) - ::gluDeleteQuadric(m_quadric); -} bool GLGizmoSlaSupports::on_init() { @@ -100,7 +89,7 @@ void GLGizmoSlaSupports::on_render() const glsafe(::glEnable(GL_BLEND)); glsafe(::glEnable(GL_DEPTH_TEST)); - if (m_quadric != nullptr && selection.is_from_single_instance()) + if (selection.is_from_single_instance()) render_points(selection, false); m_selection_rectangle.render(m_parent); @@ -114,14 +103,25 @@ void GLGizmoSlaSupports::on_render() const void GLGizmoSlaSupports::on_render_for_picking() const { const Selection& selection = m_parent.get_selection(); - glsafe(::glEnable(GL_DEPTH_TEST)); + //glsafe(::glEnable(GL_DEPTH_TEST)); render_points(selection, true); } void GLGizmoSlaSupports::render_points(const Selection& selection, bool picking) const { - if (!picking) - glsafe(::glEnable(GL_LIGHTING)); + size_t cache_size = m_editing_mode ? m_editing_cache.size() : m_normal_cache.size(); + + bool has_points = (cache_size != 0); + bool has_holes = (! m_c->hollowed_mesh()->get_hollowed_mesh() + && ! m_c->selection_info()->model_object()->sla_drain_holes.empty()); + + if (! has_points && ! has_holes) + return; + + GLShaderProgram* shader = picking ? nullptr : wxGetApp().get_shader("gouraud_light"); + if (shader) + shader->start_using(); + ScopeGuard guard([shader]() { if (shader) shader->stop_using(); }); const GLVolume* vol = selection.get_volume(*selection.get_volume_idxs().begin()); const Transform3d& instance_scaling_matrix_inverse = vol->get_instance_transformation().get_matrix(true, true, false, true).inverse(); @@ -132,8 +132,7 @@ void GLGizmoSlaSupports::render_points(const Selection& selection, bool picking) glsafe(::glTranslated(0.0, 0.0, z_shift)); glsafe(::glMultMatrixd(instance_matrix.data())); - float render_color[4]; - size_t cache_size = m_editing_mode ? m_editing_cache.size() : m_normal_cache.size(); + std::array render_color; for (size_t i = 0; i < cache_size; ++i) { const sla::SupportPoint& support_point = m_editing_mode ? m_editing_cache[i].support_point : m_normal_cache[i]; @@ -143,34 +142,31 @@ void GLGizmoSlaSupports::render_points(const Selection& selection, bool picking) continue; // First decide about the color of the point. - if (picking) { - std::array color = picking_color_component(i); - render_color[0] = color[0]; - render_color[1] = color[1]; - render_color[2] = color[2]; - render_color[3] = color[3]; - } + if (picking) + render_color = picking_color_component(i); else { - render_color[3] = 1.f; - if ((size_t(m_hover_id) == i && m_editing_mode)) { // ignore hover state unless editing mode is active - render_color[0] = 0.f; - render_color[1] = 1.0f; - render_color[2] = 1.0f; - } + if ((size_t(m_hover_id) == i && m_editing_mode)) // ignore hover state unless editing mode is active + render_color = { 0.f, 1.f, 1.f, 1.f }; else { // neigher hover nor picking bool supports_new_island = m_lock_unique_islands && support_point.is_new_island; if (m_editing_mode) { - render_color[0] = point_selected ? 1.0f : (supports_new_island ? 0.3f : 0.7f); - render_color[1] = point_selected ? 0.3f : (supports_new_island ? 0.3f : 0.7f); - render_color[2] = point_selected ? 0.3f : (supports_new_island ? 1.0f : 0.7f); + if (point_selected) + render_color = { 1.f, 0.3f, 0.3f, 1.f}; + else + if (supports_new_island) + render_color = { 0.3f, 0.3f, 1.f, 1.f }; + else + render_color = { 0.7f, 0.7f, 0.7f, 1.f }; } else - for (unsigned char i=0; i<3; ++i) render_color[i] = 0.5f; + render_color = { 0.5f, 0.5f, 0.5f, 1.f }; } } - glsafe(::glColor4fv(render_color)); - float render_color_emissive[4] = { 0.5f * render_color[0], 0.5f * render_color[1], 0.5f * render_color[2], 1.f}; - glsafe(::glMaterialfv(GL_FRONT, GL_EMISSION, render_color_emissive)); + if (shader && ! picking) + shader->set_uniform("uniform_color", render_color); + else // picking + glsafe(::glColor4fv(render_color.data())); + // Inverse matrix of the instance scaling is applied so that the mark does not scale with the object. glsafe(::glPushMatrix()); @@ -195,33 +191,36 @@ void GLGizmoSlaSupports::render_points(const Selection& selection, bool picking) const double cone_radius = 0.25; // mm const double cone_height = 0.75; glsafe(::glPushMatrix()); - glsafe(::glTranslatef(0.f, 0.f, support_point.head_front_radius * RenderPointScale)); - ::gluCylinder(m_quadric, 0., cone_radius, cone_height, 24, 1); + glsafe(::glTranslatef(0.f, 0.f, cone_height + support_point.head_front_radius * RenderPointScale)); + glsafe(::glPushMatrix()); + glsafe(::glRotated(180., 1., 0., 0.)); + glsafe(::glScaled(cone_radius, cone_radius, cone_height)); + VBOCone.render(); + glsafe(::glPopMatrix()); glsafe(::glTranslatef(0.f, 0.f, cone_height)); - ::gluDisk(m_quadric, 0.0, cone_radius, 24, 1); glsafe(::glPopMatrix()); } - ::gluSphere(m_quadric, (double)support_point.head_front_radius * RenderPointScale, 24, 12); + + glsafe(::glPushMatrix()); + double radius = (double)support_point.head_front_radius * RenderPointScale; + glsafe(::glScaled(radius, radius, radius)); + VBOSphere.render(); + glsafe(::glPopMatrix()); + if (vol->is_left_handed()) glFrontFace(GL_CCW); glsafe(::glPopMatrix()); } - { - // Reset emissive component to zero (the default value) - float render_color_emissive[4] = { 0.f, 0.f, 0.f, 1.f }; - glsafe(::glMaterialfv(GL_FRONT, GL_EMISSION, render_color_emissive)); - } - // Now render the drain holes: - //if (! m_c->has_drilled_mesh()) { - if (! m_c->hollowed_mesh()->get_hollowed_mesh()) { + if (has_holes && ! picking) { render_color[0] = 0.7f; render_color[1] = 0.7f; render_color[2] = 0.7f; render_color[3] = 0.7f; - glsafe(::glColor4fv(render_color)); + if (shader) + shader->set_uniform("uniform_color", render_color); for (const sla::DrainHole& drain_hole : m_c->selection_info()->model_object()->sla_drain_holes) { if (is_mesh_point_clipped(drain_hole.pos.cast())) continue; @@ -242,12 +241,8 @@ void GLGizmoSlaSupports::render_points(const Selection& selection, bool picking) glsafe(::glRotated(aa.angle() * (180. / M_PI), aa.axis()(0), aa.axis()(1), aa.axis()(2))); glsafe(::glPushMatrix()); glsafe(::glTranslated(0., 0., -drain_hole.height)); - ::gluCylinder(m_quadric, drain_hole.radius, drain_hole.radius, drain_hole.height + sla::HoleStickOutLength, 24, 1); - glsafe(::glTranslated(0., 0., drain_hole.height + sla::HoleStickOutLength)); - ::gluDisk(m_quadric, 0.0, drain_hole.radius, 24, 1); - glsafe(::glTranslated(0., 0., -drain_hole.height - sla::HoleStickOutLength)); - glsafe(::glRotatef(180.f, 1.f, 0.f, 0.f)); - ::gluDisk(m_quadric, 0.0, drain_hole.radius, 24, 1); + glsafe(::glScaled(drain_hole.radius, drain_hole.radius, drain_hole.height + sla::HoleStickOutLength)); + VBOCylinder.render(); glsafe(::glPopMatrix()); if (vol->is_left_handed()) @@ -256,9 +251,6 @@ void GLGizmoSlaSupports::render_points(const Selection& selection, bool picking) } } - if (!picking) - glsafe(::glDisable(GL_LIGHTING)); - glsafe(::glPopMatrix()); } diff --git a/src/slic3r/GUI/Gizmos/GLGizmoSlaSupports.hpp b/src/slic3r/GUI/Gizmos/GLGizmoSlaSupports.hpp index f9cf2f935..1859dbfd1 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmoSlaSupports.hpp +++ b/src/slic3r/GUI/Gizmos/GLGizmoSlaSupports.hpp @@ -27,8 +27,6 @@ private: const float RenderPointScale = 1.f; - GLUquadricObj* m_quadric; - class CacheEntry { public: CacheEntry() : @@ -58,7 +56,7 @@ private: public: GLGizmoSlaSupports(GLCanvas3D& parent, const std::string& icon_filename, unsigned int sprite_id); - ~GLGizmoSlaSupports() override; + virtual ~GLGizmoSlaSupports() = default; void set_sla_support_data(ModelObject* model_object, const Selection& selection); bool gizmo_event(SLAGizmoEventType action, const Vec2d& mouse_position, bool shift_down, bool alt_down, bool control_down); void delete_selected_points(bool force = false);