From 5b1c9a34d6e849f0ff0b9e47b124033cebea902c Mon Sep 17 00:00:00 2001 From: enricoturri1966 Date: Mon, 28 Feb 2022 12:05:08 +0100 Subject: [PATCH] Tech ENABLE_GLBEGIN_GLEND_SHADERS_ATTRIBUTES - Use vertex attributes and matrices in shaders. Shader: flat - Volumes picking pass --- src/libslic3r/Technologies.hpp | 2 +- src/slic3r/GUI/3DScene.cpp | 23 ++++++++++++++++++++--- src/slic3r/GUI/GLCanvas3D.cpp | 12 ++++++++++++ src/slic3r/GUI/GLModel.cpp | 1 - 4 files changed, 33 insertions(+), 5 deletions(-) diff --git a/src/libslic3r/Technologies.hpp b/src/libslic3r/Technologies.hpp index ac4dace80..88ca57178 100644 --- a/src/libslic3r/Technologies.hpp +++ b/src/libslic3r/Technologies.hpp @@ -71,7 +71,7 @@ // Enable replace GLIndexedVertexArray with GLModel #define ENABLE_GLINDEXEDVERTEXARRAY_REMOVAL (1 && ENABLE_GLBEGIN_GLEND_REMOVAL) // Enable using vertex attributes and matrices in shaders -#define ENABLE_GLBEGIN_GLEND_SHADERS_ATTRIBUTES (1 && ENABLE_GLBEGIN_GLEND_REMOVAL) +#define ENABLE_GLBEGIN_GLEND_SHADERS_ATTRIBUTES (1 && ENABLE_GLINDEXEDVERTEXARRAY_REMOVAL) // Enable show non-manifold edges #define ENABLE_SHOW_NON_MANIFOLD_EDGES (1 && ENABLE_2_5_0_ALPHA1) // Enable rework of Reload from disk command diff --git a/src/slic3r/GUI/3DScene.cpp b/src/slic3r/GUI/3DScene.cpp index 91c82de3f..8093cb0de 100644 --- a/src/slic3r/GUI/3DScene.cpp +++ b/src/slic3r/GUI/3DScene.cpp @@ -703,11 +703,24 @@ void GLVolume::render() if (!is_active) return; +#if ENABLE_GLBEGIN_GLEND_SHADERS_ATTRIBUTES + GLShaderProgram* shader = GUI::wxGetApp().get_current_shader(); + if (shader == nullptr) + return; +#endif // ENABLE_GLBEGIN_GLEND_SHADERS_ATTRIBUTES + if (this->is_left_handed()) glFrontFace(GL_CW); glsafe(::glCullFace(GL_BACK)); - glsafe(::glPushMatrix()); - glsafe(::glMultMatrixd(world_matrix().data())); +#if ENABLE_GLBEGIN_GLEND_SHADERS_ATTRIBUTES + bool use_attributes = boost::algorithm::iends_with(shader->get_name(), "_attr"); + if (!use_attributes) { +#endif // ENABLE_GLBEGIN_GLEND_SHADERS_ATTRIBUTES + glsafe(::glPushMatrix()); + glsafe(::glMultMatrixd(world_matrix().data())); +#if ENABLE_GLBEGIN_GLEND_SHADERS_ATTRIBUTES + } +#endif // ENABLE_GLBEGIN_GLEND_SHADERS_ATTRIBUTES #if ENABLE_GLINDEXEDVERTEXARRAY_REMOVAL if (tverts_range == std::make_pair(0, -1)) @@ -718,7 +731,11 @@ void GLVolume::render() this->indexed_vertex_array.render(this->tverts_range, this->qverts_range); #endif // ENABLE_GLINDEXEDVERTEXARRAY_REMOVAL - glsafe(::glPopMatrix()); +#if ENABLE_GLBEGIN_GLEND_SHADERS_ATTRIBUTES + if (!use_attributes) +#endif // ENABLE_GLBEGIN_GLEND_SHADERS_ATTRIBUTES + glsafe(::glPopMatrix()); + if (this->is_left_handed()) glFrontFace(GL_CCW); } diff --git a/src/slic3r/GUI/GLCanvas3D.cpp b/src/slic3r/GUI/GLCanvas3D.cpp index 1b15deb42..4279df64f 100644 --- a/src/slic3r/GUI/GLCanvas3D.cpp +++ b/src/slic3r/GUI/GLCanvas3D.cpp @@ -5612,7 +5612,11 @@ void GLCanvas3D::_render_overlays() void GLCanvas3D::_render_volumes_for_picking() const { #if ENABLE_GLINDEXEDVERTEXARRAY_REMOVAL +#if ENABLE_GLBEGIN_GLEND_SHADERS_ATTRIBUTES + GLShaderProgram* shader = wxGetApp().get_shader("flat_attr"); +#else GLShaderProgram* shader = wxGetApp().get_shader("flat"); +#endif // ENABLE_GLBEGIN_GLEND_SHADERS_ATTRIBUTES if (shader == nullptr) return; #endif // ENABLE_GLINDEXEDVERTEXARRAY_REMOVAL @@ -5620,8 +5624,10 @@ void GLCanvas3D::_render_volumes_for_picking() const // do not cull backfaces to show broken geometry, if any glsafe(::glDisable(GL_CULL_FACE)); +#if !ENABLE_GLBEGIN_GLEND_SHADERS_ATTRIBUTES glsafe(::glEnableClientState(GL_VERTEX_ARRAY)); glsafe(::glEnableClientState(GL_NORMAL_ARRAY)); +#endif // !ENABLE_GLBEGIN_GLEND_SHADERS_ATTRIBUTES const Transform3d& view_matrix = wxGetApp().plater()->get_camera().get_view_matrix(); for (size_t type = 0; type < 2; ++ type) { @@ -5638,6 +5644,10 @@ void GLCanvas3D::_render_volumes_for_picking() const #else glsafe(::glColor4fv(picking_decode(id).data())); #endif // ENABLE_GLINDEXEDVERTEXARRAY_REMOVAL +#if ENABLE_GLBEGIN_GLEND_SHADERS_ATTRIBUTES + const Transform3d matrix = wxGetApp().plater()->get_camera().get_projection_view_matrix() * volume.first->world_matrix(); + shader->set_uniform("projection_view_model_matrix", matrix); +#endif // ENABLE_GLBEGIN_GLEND_SHADERS_ATTRIBUTES volume.first->render(); #if ENABLE_GLINDEXEDVERTEXARRAY_REMOVAL shader->stop_using(); @@ -5645,8 +5655,10 @@ void GLCanvas3D::_render_volumes_for_picking() const } } +#if !ENABLE_GLBEGIN_GLEND_SHADERS_ATTRIBUTES glsafe(::glDisableClientState(GL_NORMAL_ARRAY)); glsafe(::glDisableClientState(GL_VERTEX_ARRAY)); +#endif // !ENABLE_GLBEGIN_GLEND_SHADERS_ATTRIBUTES glsafe(::glEnable(GL_CULL_FACE)); } diff --git a/src/slic3r/GUI/GLModel.cpp b/src/slic3r/GUI/GLModel.cpp index 6eeeda7d9..c32a4e26a 100644 --- a/src/slic3r/GUI/GLModel.cpp +++ b/src/slic3r/GUI/GLModel.cpp @@ -960,7 +960,6 @@ void GLModel::render(const std::pair& range) return; GLShaderProgram* shader = wxGetApp().get_current_shader(); - if (shader == nullptr) return;