From 14f43453894b08e907155638a4ff8ace92f5fec5 Mon Sep 17 00:00:00 2001 From: enricoturri1966 Date: Thu, 3 Mar 2022 12:36:44 +0100 Subject: [PATCH] Tech ENABLE_GLBEGIN_GLEND_SHADERS_ATTRIBUTES - Use vertex attributes and matrices in shaders. Shader: gouraud_light - Thumbnails render --- src/slic3r/GUI/3DBed.cpp | 51 ++++++++++++++++++++-- src/slic3r/GUI/3DBed.hpp | 19 ++++++++ src/slic3r/GUI/3DScene.cpp | 43 +++++++++++++----- src/slic3r/GUI/3DScene.hpp | 5 +++ src/slic3r/GUI/GCodeViewer.cpp | 5 +++ src/slic3r/GUI/GLCanvas3D.cpp | 80 +++++++++++++++++++++++++++++++++- src/slic3r/GUI/GLCanvas3D.hpp | 5 +++ 7 files changed, 191 insertions(+), 17 deletions(-) diff --git a/src/slic3r/GUI/3DBed.cpp b/src/slic3r/GUI/3DBed.cpp index ddd56c7a2..e0f0bc024 100644 --- a/src/slic3r/GUI/3DBed.cpp +++ b/src/slic3r/GUI/3DBed.cpp @@ -270,6 +270,17 @@ Point Bed3D::point_projection(const Point& point) const return m_polygon.point_projection(point); } +#if ENABLE_GLBEGIN_GLEND_SHADERS_ATTRIBUTES +void Bed3D::render(GLCanvas3D& canvas, const Transform3d& view_matrix, const Transform3d& projection_matrix, bool bottom, float scale_factor, bool show_axes, bool show_texture) +{ + render_internal(canvas, view_matrix, projection_matrix, bottom, scale_factor, show_axes, show_texture, false); +} + +void Bed3D::render_for_picking(GLCanvas3D& canvas, const Transform3d& view_matrix, const Transform3d& projection_matrix, bool bottom, float scale_factor) +{ + render_internal(canvas, view_matrix, projection_matrix, bottom, scale_factor, false, false, true); +} +#else void Bed3D::render(GLCanvas3D& canvas, bool bottom, float scale_factor, bool show_axes, bool show_texture) { render_internal(canvas, bottom, scale_factor, show_axes, show_texture, false); @@ -279,9 +290,15 @@ void Bed3D::render_for_picking(GLCanvas3D& canvas, bool bottom, float scale_fact { render_internal(canvas, bottom, scale_factor, false, false, true); } +#endif // ENABLE_GLBEGIN_GLEND_SHADERS_ATTRIBUTES +#if ENABLE_GLBEGIN_GLEND_SHADERS_ATTRIBUTES +void Bed3D::render_internal(GLCanvas3D& canvas, const Transform3d& view_matrix, const Transform3d& projection_matrix, bool bottom, float scale_factor, + bool show_axes, bool show_texture, bool picking) +#else void Bed3D::render_internal(GLCanvas3D& canvas, bool bottom, float scale_factor, bool show_axes, bool show_texture, bool picking) +#endif // ENABLE_GLBEGIN_GLEND_SHADERS_ATTRIBUTES { m_scale_factor = scale_factor; @@ -298,9 +315,15 @@ void Bed3D::render_internal(GLCanvas3D& canvas, bool bottom, float scale_factor, switch (m_type) { +#if ENABLE_GLBEGIN_GLEND_SHADERS_ATTRIBUTES + case Type::System: { render_system(canvas, view_matrix, projection_matrix, bottom, show_texture); break; } + default: + case Type::Custom: { render_custom(canvas, view_matrix, projection_matrix, bottom, show_texture, picking); break; } +#else case Type::System: { render_system(canvas, bottom, show_texture); break; } default: case Type::Custom: { render_custom(canvas, bottom, show_texture, picking); break; } +#endif // ENABLE_GLBEGIN_GLEND_SHADERS_ATTRIBUTES } glsafe(::glDisable(GL_DEPTH_TEST)); @@ -492,6 +515,16 @@ void Bed3D::render_axes() m_axes.render(); } +#if ENABLE_GLBEGIN_GLEND_SHADERS_ATTRIBUTES +void Bed3D::render_system(GLCanvas3D& canvas, const Transform3d& view_matrix, const Transform3d& projection_matrix, bool bottom, bool show_texture) +{ + if (!bottom) + render_model(view_matrix, projection_matrix); + + if (show_texture) + render_texture(bottom, canvas); +} +#else void Bed3D::render_system(GLCanvas3D& canvas, bool bottom, bool show_texture) { if (!bottom) @@ -500,6 +533,7 @@ void Bed3D::render_system(GLCanvas3D& canvas, bool bottom, bool show_texture) if (show_texture) render_texture(bottom, canvas); } +#endif // ENABLE_GLBEGIN_GLEND_SHADERS_ATTRIBUTES void Bed3D::render_texture(bool bottom, GLCanvas3D& canvas) { @@ -661,7 +695,11 @@ void Bed3D::render_texture(bool bottom, GLCanvas3D& canvas) #endif // ENABLE_GLBEGIN_GLEND_REMOVAL } +#if ENABLE_GLBEGIN_GLEND_SHADERS_ATTRIBUTES +void Bed3D::render_model(const Transform3d& view_matrix, const Transform3d& projection_matrix) +#else void Bed3D::render_model() +#endif // ENABLE_GLBEGIN_GLEND_SHADERS_ATTRIBUTES { if (m_model_filename.empty()) return; @@ -690,10 +728,9 @@ void Bed3D::render_model() shader->start_using(); shader->set_uniform("emission_factor", 0.0f); #if ENABLE_GLBEGIN_GLEND_SHADERS_ATTRIBUTES - const Camera& camera = wxGetApp().plater()->get_camera(); - const Transform3d matrix = camera.get_view_matrix() * Geometry::assemble_transform(m_model_offset); + const Transform3d matrix = view_matrix * Geometry::assemble_transform(m_model_offset); shader->set_uniform("view_model_matrix", matrix); - shader->set_uniform("projection_matrix", camera.get_projection_matrix()); + shader->set_uniform("projection_matrix", projection_matrix); shader->set_uniform("normal_matrix", (Matrix3d)matrix.matrix().block(0, 0, 3, 3).inverse().transpose()); #else glsafe(::glPushMatrix()); @@ -708,7 +745,11 @@ void Bed3D::render_model() } } +#if ENABLE_GLBEGIN_GLEND_SHADERS_ATTRIBUTES +void Bed3D::render_custom(GLCanvas3D& canvas, const Transform3d& view_matrix, const Transform3d& projection_matrix, bool bottom, bool show_texture, bool picking) +#else void Bed3D::render_custom(GLCanvas3D& canvas, bool bottom, bool show_texture, bool picking) +#endif // ENABLE_GLBEGIN_GLEND_SHADERS_ATTRIBUTES { if (m_texture_filename.empty() && m_model_filename.empty()) { render_default(bottom, picking); @@ -716,7 +757,11 @@ void Bed3D::render_custom(GLCanvas3D& canvas, bool bottom, bool show_texture, bo } if (!bottom) +#if ENABLE_GLBEGIN_GLEND_SHADERS_ATTRIBUTES + render_model(view_matrix, projection_matrix); +#else render_model(); +#endif // ENABLE_GLBEGIN_GLEND_SHADERS_ATTRIBUTES if (show_texture) render_texture(bottom, canvas); diff --git a/src/slic3r/GUI/3DBed.hpp b/src/slic3r/GUI/3DBed.hpp index 350ae48f6..d5ce0c511 100644 --- a/src/slic3r/GUI/3DBed.hpp +++ b/src/slic3r/GUI/3DBed.hpp @@ -139,8 +139,13 @@ public: bool contains(const Point& point) const; Point point_projection(const Point& point) const; +#if ENABLE_GLBEGIN_GLEND_SHADERS_ATTRIBUTES + void render(GLCanvas3D& canvas, const Transform3d& view_matrix, const Transform3d& projection_matrix, bool bottom, float scale_factor, bool show_axes, bool show_texture); + void render_for_picking(GLCanvas3D& canvas, const Transform3d& view_matrix, const Transform3d& projection_matrix, bool bottom, float scale_factor); +#else void render(GLCanvas3D& canvas, bool bottom, float scale_factor, bool show_axes, bool show_texture); void render_for_picking(GLCanvas3D& canvas, bool bottom, float scale_factor); +#endif // ENABLE_GLBEGIN_GLEND_SHADERS_ATTRIBUTES private: // Calculate an extended bounding box from axes and current model for visualization purposes. @@ -153,13 +158,27 @@ private: void calc_gridlines(const ExPolygon& poly, const BoundingBox& bed_bbox); #endif // ENABLE_GLBEGIN_GLEND_REMOVAL static std::tuple detect_type(const Pointfs& shape); +#if ENABLE_GLBEGIN_GLEND_SHADERS_ATTRIBUTES + void render_internal(GLCanvas3D& canvas, const Transform3d& view_matrix, const Transform3d& projection_matrix, bool bottom, float scale_factor, + bool show_axes, bool show_texture, bool picking); +#else void render_internal(GLCanvas3D& canvas, bool bottom, float scale_factor, bool show_axes, bool show_texture, bool picking); +#endif // ENABLE_GLBEGIN_GLEND_SHADERS_ATTRIBUTES void render_axes(); +#if ENABLE_GLBEGIN_GLEND_SHADERS_ATTRIBUTES + void render_system(GLCanvas3D& canvas, const Transform3d& view_matrix, const Transform3d& projection_matrix, bool bottom, bool show_texture); +#else void render_system(GLCanvas3D& canvas, bool bottom, bool show_texture); +#endif // ENABLE_GLBEGIN_GLEND_SHADERS_ATTRIBUTES void render_texture(bool bottom, GLCanvas3D& canvas); +#if ENABLE_GLBEGIN_GLEND_SHADERS_ATTRIBUTES + void render_model(const Transform3d& view_matrix, const Transform3d& projection_matrix); + void render_custom(GLCanvas3D& canvas, const Transform3d& view_matrix, const Transform3d& projection_matrix, bool bottom, bool show_texture, bool picking); +#else void render_model(); void render_custom(GLCanvas3D& canvas, bool bottom, bool show_texture, bool picking); +#endif // ENABLE_GLBEGIN_GLEND_SHADERS_ATTRIBUTES void render_default(bool bottom, bool picking); #if !ENABLE_GLBEGIN_GLEND_REMOVAL void release_VBOs(); diff --git a/src/slic3r/GUI/3DScene.cpp b/src/slic3r/GUI/3DScene.cpp index dad2f5ade..330371e00 100644 --- a/src/slic3r/GUI/3DScene.cpp +++ b/src/slic3r/GUI/3DScene.cpp @@ -714,14 +714,7 @@ void GLVolume::render() glsafe(::glCullFace(GL_BACK)); #if ENABLE_GLBEGIN_GLEND_SHADERS_ATTRIBUTES bool use_attributes = boost::algorithm::iends_with(shader->get_name(), "_attr"); - if (use_attributes) { - const GUI::Camera& camera = GUI::wxGetApp().plater()->get_camera(); - const Transform3d matrix = camera.get_view_matrix() * world_matrix(); - shader->set_uniform("view_model_matrix", matrix); - shader->set_uniform("projection_matrix", camera.get_projection_matrix()); - shader->set_uniform("normal_matrix", (Matrix3d)matrix.matrix().block(0, 0, 3, 3).inverse().transpose()); - } - else { + if (!use_attributes) { #endif // ENABLE_GLBEGIN_GLEND_SHADERS_ATTRIBUTES glsafe(::glPushMatrix()); glsafe(::glMultMatrixd(world_matrix().data())); @@ -1083,7 +1076,12 @@ GLVolumeWithIdAndZList volumes_to_render(const GLVolumePtrs& volumes, GLVolumeCo return list; } +#if ENABLE_GLBEGIN_GLEND_SHADERS_ATTRIBUTES +void GLVolumeCollection::render(GLVolumeCollection::ERenderType type, bool disable_cullface, const Transform3d& view_matrix, const Transform3d& projection_matrix, + std::function filter_func) const +#else void GLVolumeCollection::render(GLVolumeCollection::ERenderType type, bool disable_cullface, const Transform3d& view_matrix, std::function filter_func) const +#endif // ENABLE_GLBEGIN_GLEND_SHADERS_ATTRIBUTES { GLVolumeWithIdAndZList to_render = volumes_to_render(volumes, type, view_matrix, filter_func); if (to_render.empty()) @@ -1097,6 +1095,7 @@ void GLVolumeCollection::render(GLVolumeCollection::ERenderType type, bool disab #if ENABLE_GLBEGIN_GLEND_SHADERS_ATTRIBUTES GLShaderProgram* sink_shader = GUI::wxGetApp().get_shader("flat_attr"); GLShaderProgram* edges_shader = GUI::wxGetApp().get_shader("flat_attr"); + bool use_attributes = boost::algorithm::iends_with(shader->get_name(), "_attr"); #else GLShaderProgram* sink_shader = GUI::wxGetApp().get_shader("flat"); GLShaderProgram* edges_shader = GUI::wxGetApp().get_shader("flat"); @@ -1139,8 +1138,14 @@ void GLVolumeCollection::render(GLVolumeCollection::ERenderType type, bool disab shader->start_using(); #endif // ENABLE_GLBEGIN_GLEND_REMOVAL - glsafe(::glEnableClientState(GL_VERTEX_ARRAY)); - glsafe(::glEnableClientState(GL_NORMAL_ARRAY)); +#if ENABLE_GLBEGIN_GLEND_SHADERS_ATTRIBUTES + if (!use_attributes) { +#endif // ENABLE_GLBEGIN_GLEND_SHADERS_ATTRIBUTES + glsafe(::glEnableClientState(GL_VERTEX_ARRAY)); + glsafe(::glEnableClientState(GL_NORMAL_ARRAY)); +#if ENABLE_GLBEGIN_GLEND_SHADERS_ATTRIBUTES + } +#endif // ENABLE_GLBEGIN_GLEND_SHADERS_ATTRIBUTES #if ENABLE_GLINDEXEDVERTEXARRAY_REMOVAL if (!volume.first->model.is_initialized()) @@ -1168,6 +1173,14 @@ void GLVolumeCollection::render(GLVolumeCollection::ERenderType type, bool disab #if ENABLE_GLINDEXEDVERTEXARRAY_REMOVAL volume.first->model.set_color(volume.first->render_color); #endif // ENABLE_GLINDEXEDVERTEXARRAY_REMOVAL +#if ENABLE_GLBEGIN_GLEND_SHADERS_ATTRIBUTES + if (use_attributes) { + const Transform3d matrix = view_matrix * volume.first->world_matrix(); + shader->set_uniform("view_model_matrix", matrix); + shader->set_uniform("projection_matrix", projection_matrix); + shader->set_uniform("normal_matrix", (Matrix3d)matrix.matrix().block(0, 0, 3, 3).inverse().transpose()); + } +#endif // ENABLE_GLBEGIN_GLEND_SHADERS_ATTRIBUTES volume.first->render(); #if ENABLE_ENVIRONMENT_MAP @@ -1178,8 +1191,14 @@ void GLVolumeCollection::render(GLVolumeCollection::ERenderType type, bool disab glsafe(::glBindBuffer(GL_ARRAY_BUFFER, 0)); glsafe(::glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0)); - glsafe(::glDisableClientState(GL_VERTEX_ARRAY)); - glsafe(::glDisableClientState(GL_NORMAL_ARRAY)); +#if ENABLE_GLBEGIN_GLEND_SHADERS_ATTRIBUTES + if (!use_attributes) { +#endif // ENABLE_GLBEGIN_GLEND_SHADERS_ATTRIBUTES + glsafe(::glDisableClientState(GL_VERTEX_ARRAY)); + glsafe(::glDisableClientState(GL_NORMAL_ARRAY)); +#if ENABLE_GLBEGIN_GLEND_SHADERS_ATTRIBUTES + } +#endif // ENABLE_GLBEGIN_GLEND_SHADERS_ATTRIBUTES } if (m_show_sinking_contours) { diff --git a/src/slic3r/GUI/3DScene.hpp b/src/slic3r/GUI/3DScene.hpp index ed2aa804e..83ff907c2 100644 --- a/src/slic3r/GUI/3DScene.hpp +++ b/src/slic3r/GUI/3DScene.hpp @@ -687,7 +687,12 @@ public: #endif // ENABLE_GLINDEXEDVERTEXARRAY_REMOVAL // Render the volumes by OpenGL. +#if ENABLE_GLBEGIN_GLEND_SHADERS_ATTRIBUTES + void render(ERenderType type, bool disable_cullface, const Transform3d& view_matrix, const Transform3d& projection_matrix, + std::function filter_func = std::function()) const; +#else void render(ERenderType type, bool disable_cullface, const Transform3d& view_matrix, std::function filter_func = std::function()) const; +#endif // ENABLE_GLBEGIN_GLEND_SHADERS_ATTRIBUTES #if !ENABLE_GLINDEXEDVERTEXARRAY_REMOVAL // Finalize the initialization of the geometry & indices, diff --git a/src/slic3r/GUI/GCodeViewer.cpp b/src/slic3r/GUI/GCodeViewer.cpp index 86da8cf9a..a2c846ddc 100644 --- a/src/slic3r/GUI/GCodeViewer.cpp +++ b/src/slic3r/GUI/GCodeViewer.cpp @@ -3256,7 +3256,12 @@ void GCodeViewer::render_shells() // glsafe(::glDepthMask(GL_FALSE)); shader->start_using(); +#if ENABLE_GLBEGIN_GLEND_SHADERS_ATTRIBUTES + const Camera& camera = wxGetApp().plater()->get_camera(); + m_shells.volumes.render(GLVolumeCollection::ERenderType::Transparent, true, camera.get_view_matrix(), camera.get_projection_matrix()); +#else m_shells.volumes.render(GLVolumeCollection::ERenderType::Transparent, true, wxGetApp().plater()->get_camera().get_view_matrix()); +#endif // ENABLE_GLBEGIN_GLEND_SHADERS_ATTRIBUTES shader->stop_using(); // glsafe(::glDepthMask(GL_TRUE)); diff --git a/src/slic3r/GUI/GLCanvas3D.cpp b/src/slic3r/GUI/GLCanvas3D.cpp index 10deca2b4..ab750cee4 100644 --- a/src/slic3r/GUI/GLCanvas3D.cpp +++ b/src/slic3r/GUI/GLCanvas3D.cpp @@ -1645,7 +1645,11 @@ void GLCanvas3D::render() _render_gcode(); _render_sla_slices(); _render_selection(); +#if ENABLE_GLBEGIN_GLEND_SHADERS_ATTRIBUTES + _render_bed(camera.get_view_matrix(), camera.get_projection_matrix(), !camera.is_looking_downward(), true); +#else _render_bed(!camera.is_looking_downward(), true); +#endif // ENABLE_GLBEGIN_GLEND_SHADERS_ATTRIBUTES _render_objects(GLVolumeCollection::ERenderType::Transparent); _render_sequential_clearance(); @@ -4413,6 +4417,10 @@ void GLCanvas3D::_render_thumbnail_internal(ThumbnailData& thumbnail_data, const camera.zoom_to_box(volumes_box); camera.apply_view_matrix(); +#if ENABLE_GLBEGIN_GLEND_SHADERS_ATTRIBUTES + const Transform3d& view_matrix = camera.get_view_matrix(); +#endif // ENABLE_GLBEGIN_GLEND_SHADERS_ATTRIBUTES + double near_z = -1.0; double far_z = -1.0; @@ -4420,14 +4428,22 @@ void GLCanvas3D::_render_thumbnail_internal(ThumbnailData& thumbnail_data, const // extends the near and far z of the frustrum to avoid the bed being clipped // box in eye space - BoundingBoxf3 t_bed_box = m_bed.extended_bounding_box().transformed(camera.get_view_matrix()); +#if ENABLE_GLBEGIN_GLEND_SHADERS_ATTRIBUTES + const BoundingBoxf3 t_bed_box = m_bed.extended_bounding_box().transformed(view_matrix); +#else + const BoundingBoxf3 t_bed_box = m_bed.extended_bounding_box().transformed(camera.get_view_matrix()); +#endif // ENABLE_GLBEGIN_GLEND_SHADERS_ATTRIBUTES near_z = -t_bed_box.max.z(); far_z = -t_bed_box.min.z(); } camera.apply_projection(volumes_box, near_z, far_z); +#if ENABLE_GLBEGIN_GLEND_SHADERS_ATTRIBUTES + GLShaderProgram* shader = wxGetApp().get_shader("gouraud_light_attr"); +#else GLShaderProgram* shader = wxGetApp().get_shader("gouraud_light"); +#endif // ENABLE_GLBEGIN_GLEND_SHADERS_ATTRIBUTES if (shader == nullptr) return; @@ -4440,6 +4456,10 @@ void GLCanvas3D::_render_thumbnail_internal(ThumbnailData& thumbnail_data, const shader->start_using(); shader->set_uniform("emission_factor", 0.0f); +#if ENABLE_GLBEGIN_GLEND_SHADERS_ATTRIBUTES + const Transform3d& projection_matrix = camera.get_projection_matrix(); +#endif // ENABLE_GLBEGIN_GLEND_SHADERS_ATTRIBUTES + for (GLVolume* vol : visible_volumes) { #if ENABLE_GLINDEXEDVERTEXARRAY_REMOVAL vol->model.set_color((vol->printable && !vol->is_outside) ? (current_printer_technology() == ptSLA ? vol->color : ColorRGBA::ORANGE()) : ColorRGBA::GRAY()); @@ -4447,8 +4467,14 @@ void GLCanvas3D::_render_thumbnail_internal(ThumbnailData& thumbnail_data, const shader->set_uniform("uniform_color", (vol->printable && !vol->is_outside) ? (current_printer_technology() == ptSLA ? vol->color : ColorRGBA::ORANGE()) : ColorRGBA::GRAY()); #endif // ENABLE_GLINDEXEDVERTEXARRAY_REMOVAL // the volume may have been deactivated by an active gizmo - bool is_active = vol->is_active; + const bool is_active = vol->is_active; vol->is_active = true; +#if ENABLE_GLBEGIN_GLEND_SHADERS_ATTRIBUTES + const Transform3d matrix = view_matrix * vol->world_matrix(); + shader->set_uniform("view_model_matrix", matrix); + shader->set_uniform("projection_matrix", projection_matrix); + shader->set_uniform("normal_matrix", (Matrix3d)matrix.matrix().block(0, 0, 3, 3).inverse().transpose()); +#endif // ENABLE_GLBEGIN_GLEND_SHADERS_ATTRIBUTES vol->render(); vol->is_active = is_active; } @@ -4458,7 +4484,11 @@ void GLCanvas3D::_render_thumbnail_internal(ThumbnailData& thumbnail_data, const glsafe(::glDisable(GL_DEPTH_TEST)); if (thumbnail_params.show_bed) +#if ENABLE_GLBEGIN_GLEND_SHADERS_ATTRIBUTES + _render_bed(view_matrix, projection_matrix, !camera.is_looking_downward(), false); +#else _render_bed(!camera.is_looking_downward(), false); +#endif // ENABLE_GLBEGIN_GLEND_SHADERS_ATTRIBUTES // restore background color if (thumbnail_params.transparent_background) @@ -5180,7 +5210,12 @@ void GLCanvas3D::_picking_pass() if (m_camera_clipping_plane.is_active()) ::glDisable(GL_CLIP_PLANE0); +#if ENABLE_GLBEGIN_GLEND_SHADERS_ATTRIBUTES + const Camera& camera = wxGetApp().plater()->get_camera(); + _render_bed_for_picking(camera.get_view_matrix(), camera.get_projection_matrix(), !camera.is_looking_downward()); +#else _render_bed_for_picking(!wxGetApp().plater()->get_camera().is_looking_downward()); +#endif // ENABLE_GLBEGIN_GLEND_SHADERS_ATTRIBUTES m_gizmos.render_current_gizmo_for_picking_pass(); @@ -5236,7 +5271,12 @@ void GLCanvas3D::_rectangular_selection_picking_pass() glsafe(::glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)); _render_volumes_for_picking(); +#if ENABLE_GLBEGIN_GLEND_SHADERS_ATTRIBUTES + const Camera& camera = wxGetApp().plater()->get_camera(); + _render_bed_for_picking(camera.get_view_matrix(), camera.get_projection_matrix(), !camera.is_looking_downward()); +#else _render_bed_for_picking(!wxGetApp().plater()->get_camera().is_looking_downward()); +#endif // ENABLE_GLBEGIN_GLEND_SHADERS_ATTRIBUTES if (m_multisample_allowed) glsafe(::glEnable(GL_MULTISAMPLE)); @@ -5370,7 +5410,11 @@ void GLCanvas3D::_render_background() glsafe(::glPopMatrix()); } +#if ENABLE_GLBEGIN_GLEND_SHADERS_ATTRIBUTES +void GLCanvas3D::_render_bed(const Transform3d& view_matrix, const Transform3d& projection_matrix, bool bottom, bool show_axes) +#else void GLCanvas3D::_render_bed(bool bottom, bool show_axes) +#endif // ENABLE_GLBEGIN_GLEND_SHADERS_ATTRIBUTES { float scale_factor = 1.0; #if ENABLE_RETINA_GL @@ -5384,17 +5428,29 @@ void GLCanvas3D::_render_bed(bool bottom, bool show_axes) && m_gizmos.get_current_type() != GLGizmosManager::Seam && m_gizmos.get_current_type() != GLGizmosManager::MmuSegmentation); +#if ENABLE_GLBEGIN_GLEND_SHADERS_ATTRIBUTES + m_bed.render(*this, view_matrix, projection_matrix, bottom, scale_factor, show_axes, show_texture); +#else m_bed.render(*this, bottom, scale_factor, show_axes, show_texture); +#endif // ENABLE_GLBEGIN_GLEND_SHADERS_ATTRIBUTES } +#if ENABLE_GLBEGIN_GLEND_SHADERS_ATTRIBUTES +void GLCanvas3D::_render_bed_for_picking(const Transform3d& view_matrix, const Transform3d& projection_matrix, bool bottom) +#else void GLCanvas3D::_render_bed_for_picking(bool bottom) +#endif // ENABLE_GLBEGIN_GLEND_SHADERS_ATTRIBUTES { float scale_factor = 1.0; #if ENABLE_RETINA_GL scale_factor = m_retina_helper->get_scale_factor(); #endif // ENABLE_RETINA_GL +#if ENABLE_GLBEGIN_GLEND_SHADERS_ATTRIBUTES + m_bed.render_for_picking(*this, view_matrix, projection_matrix, bottom, scale_factor); +#else m_bed.render_for_picking(*this, bottom, scale_factor); +#endif // ENABLE_GLBEGIN_GLEND_SHADERS_ATTRIBUTES } void GLCanvas3D::_render_objects(GLVolumeCollection::ERenderType type) @@ -5462,18 +5518,33 @@ void GLCanvas3D::_render_objects(GLVolumeCollection::ERenderType type) { if (m_picking_enabled && !m_gizmos.is_dragging() && m_layers_editing.is_enabled() && (m_layers_editing.last_object_id != -1) && (m_layers_editing.object_max_z() > 0.0f)) { int object_id = m_layers_editing.last_object_id; +#if ENABLE_GLBEGIN_GLEND_SHADERS_ATTRIBUTES + const Camera& camera = wxGetApp().plater()->get_camera(); + m_volumes.render(type, false, camera.get_view_matrix(), camera.get_projection_matrix(), [object_id](const GLVolume& volume) { + // Which volume to paint without the layer height profile shader? + return volume.is_active && (volume.is_modifier || volume.composite_id.object_id != object_id); + }); +#else m_volumes.render(type, false, wxGetApp().plater()->get_camera().get_view_matrix(), [object_id](const GLVolume& volume) { // Which volume to paint without the layer height profile shader? return volume.is_active && (volume.is_modifier || volume.composite_id.object_id != object_id); }); +#endif // ENABLE_GLBEGIN_GLEND_SHADERS_ATTRIBUTES // Let LayersEditing handle rendering of the active object using the layer height profile shader. m_layers_editing.render_volumes(*this, m_volumes); } else { // do not cull backfaces to show broken geometry, if any +#if ENABLE_GLBEGIN_GLEND_SHADERS_ATTRIBUTES + const Camera& camera = wxGetApp().plater()->get_camera(); + m_volumes.render(type, m_picking_enabled, camera.get_view_matrix(), camera.get_projection_matrix(), [this](const GLVolume& volume) { + return (m_render_sla_auxiliaries || volume.composite_id.volume_id >= 0); + }); +#else m_volumes.render(type, m_picking_enabled, wxGetApp().plater()->get_camera().get_view_matrix(), [this](const GLVolume& volume) { return (m_render_sla_auxiliaries || volume.composite_id.volume_id >= 0); }); +#endif // ENABLE_GLBEGIN_GLEND_SHADERS_ATTRIBUTES } // In case a painting gizmo is open, it should render the painted triangles @@ -5492,7 +5563,12 @@ void GLCanvas3D::_render_objects(GLVolumeCollection::ERenderType type) } case GLVolumeCollection::ERenderType::Transparent: { +#if ENABLE_GLBEGIN_GLEND_SHADERS_ATTRIBUTES + const Camera& camera = wxGetApp().plater()->get_camera(); + m_volumes.render(type, false, camera.get_view_matrix(), camera.get_projection_matrix()); +#else m_volumes.render(type, false, wxGetApp().plater()->get_camera().get_view_matrix()); +#endif // ENABLE_GLBEGIN_GLEND_SHADERS_ATTRIBUTES break; } } diff --git a/src/slic3r/GUI/GLCanvas3D.hpp b/src/slic3r/GUI/GLCanvas3D.hpp index 1f230bc9c..a1dd21316 100644 --- a/src/slic3r/GUI/GLCanvas3D.hpp +++ b/src/slic3r/GUI/GLCanvas3D.hpp @@ -944,8 +944,13 @@ private: void _picking_pass(); void _rectangular_selection_picking_pass(); void _render_background(); +#if ENABLE_GLBEGIN_GLEND_SHADERS_ATTRIBUTES + void _render_bed(const Transform3d& view_matrix, const Transform3d& projection_matrix, bool bottom, bool show_axes); + void _render_bed_for_picking(const Transform3d& view_matrix, const Transform3d& projection_matrix, bool bottom); +#else void _render_bed(bool bottom, bool show_axes); void _render_bed_for_picking(bool bottom); +#endif // ENABLE_GLBEGIN_GLEND_SHADERS_ATTRIBUTES void _render_objects(GLVolumeCollection::ERenderType type); void _render_gcode(); #if ENABLE_SHOW_TOOLPATHS_COG