diff --git a/src/slic3r/GUI/Gizmos/GLGizmoMmuSegmentation.cpp b/src/slic3r/GUI/Gizmos/GLGizmoMmuSegmentation.cpp index e52267841e..1313b33bd2 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmoMmuSegmentation.cpp +++ b/src/slic3r/GUI/Gizmos/GLGizmoMmuSegmentation.cpp @@ -918,19 +918,27 @@ void GLMmSegmentationGizmo3DScene::render(size_t triangle_indices_idx) const assert(this->vertices_VBO_id != 0); assert(this->triangle_indices_VBO_ids[triangle_indices_idx] != 0); + GLShaderProgram* shader = wxGetApp().get_current_shader(); + if (shader == nullptr) + return; + glsafe(::glBindBuffer(GL_ARRAY_BUFFER, this->vertices_VBO_id)); - glsafe(::glVertexPointer(3, GL_FLOAT, 3 * sizeof(float), (const void*)(0 * sizeof(float)))); - - glsafe(::glEnableClientState(GL_VERTEX_ARRAY)); - - // Render using the Vertex Buffer Objects. - if (this->triangle_indices_sizes[triangle_indices_idx] > 0) { - glsafe(::glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, this->triangle_indices_VBO_ids[triangle_indices_idx])); - glsafe(::glDrawElements(GL_TRIANGLES, GLsizei(this->triangle_indices_sizes[triangle_indices_idx]), GL_UNSIGNED_INT, nullptr)); - glsafe(glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0)); + const GLint position_id = shader->get_attrib_location("v_position"); + if (position_id != -1) { + glsafe(::glVertexAttribPointer(position_id, 3, GL_FLOAT, GL_FALSE, 3 * sizeof(float), (GLvoid*)0)); + glsafe(::glEnableVertexAttribArray(position_id)); } - glsafe(::glDisableClientState(GL_VERTEX_ARRAY)); + // Render using the Vertex Buffer Objects. + if (this->triangle_indices_VBO_ids[triangle_indices_idx] != 0 && + this->triangle_indices_sizes[triangle_indices_idx] > 0) { + glsafe(::glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, this->triangle_indices_VBO_ids[triangle_indices_idx])); + glsafe(::glDrawElements(GL_TRIANGLES, GLsizei(this->triangle_indices_sizes[triangle_indices_idx]), GL_UNSIGNED_INT, nullptr)); + glsafe(::glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0)); + } + + if (position_id != -1) + glsafe(::glDisableVertexAttribArray(position_id)); glsafe(::glBindBuffer(GL_ARRAY_BUFFER, 0)); } diff --git a/src/slic3r/GUI/Gizmos/GLGizmoPainterBase.cpp b/src/slic3r/GUI/Gizmos/GLGizmoPainterBase.cpp index 7d83f38cce..296506cad6 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmoPainterBase.cpp +++ b/src/slic3r/GUI/Gizmos/GLGizmoPainterBase.cpp @@ -1179,20 +1179,6 @@ void TriangleSelectorPatch::render(ImGuiWrapper* imgui, const Transform3d& matri if (!shader) return; assert(shader->get_name() == "gouraud_attr" || shader->get_name() == "mm_gouraud_attr"); - GLint position_id = -1; - GLint barycentric_id = -1; - if (wxGetApp().plater()->is_wireframe_enabled()) { - position_id = shader->get_attrib_location("v_position"); - barycentric_id = shader->get_attrib_location("v_barycentric"); - if (m_need_wireframe && wxGetApp().plater()->is_show_wireframe()) { - //BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << boost::format(", show_wireframe on"); - shader->set_uniform("show_wireframe", true); - } - else { - //BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << boost::format(", show_wireframe off"); - shader->set_uniform("show_wireframe", false); - } - } for (size_t buffer_idx = 0; buffer_idx < m_triangle_patches.size(); ++buffer_idx) { if (this->has_VBOs(buffer_idx)) { @@ -1210,9 +1196,7 @@ void TriangleSelectorPatch::render(ImGuiWrapper* imgui, const Transform3d& matri //to make black not too hard too see ColorRGBA new_color = adjust_color_for_rendering(color); shader->set_uniform("uniform_color", new_color); - //shader->set_uniform("uniform_color", color); - //BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << boost::format(", buffer_idx %1%: new_color[%2%, %3%, %4%, %5%]")%buffer_idx%new_color[0]%new_color[1]%new_color[2]%new_color[3]; - this->render(buffer_idx, (int)position_id, (int)barycentric_id); + this->render(buffer_idx); } } @@ -1443,7 +1427,7 @@ void TriangleSelectorPatch::update_render_data() //BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << boost::format(", exit"); } -void TriangleSelectorPatch::render(int triangle_indices_idx, int position_id, int barycentric_id) +void TriangleSelectorPatch::render(int triangle_indices_idx) { assert(triangle_indices_idx < this->m_triangle_indices_VBO_ids.size()); assert(this->m_triangle_patches.size() == this->m_triangle_indices_VBO_ids.size()); @@ -1452,28 +1436,17 @@ void TriangleSelectorPatch::render(int triangle_indices_idx, int position_id, in assert(this->m_vertices_VBO_ids[triangle_indices_idx] != 0); assert(this->m_triangle_indices_VBO_ids[triangle_indices_idx] != 0); - //glsafe(::glBindBuffer(GL_ARRAY_BUFFER, this->m_vertices_VBO_id)); - //glsafe(::glVertexPointer(3, GL_FLOAT, 3 * sizeof(float), (const void*)(0 * sizeof(float)))); - if (this->m_triangle_indices_sizes[triangle_indices_idx] > 0) { - glsafe(::glBindBuffer(GL_ARRAY_BUFFER, this->m_vertices_VBO_ids[triangle_indices_idx])); - if (position_id != -1) { - glsafe(::glEnableVertexAttribArray((GLint)position_id)); - glsafe(::glVertexAttribPointer((GLint)position_id, 3, GL_FLOAT, GL_FALSE, 6*sizeof(float), nullptr)); - } - else { - glsafe(::glVertexPointer(3, GL_FLOAT, 3 * sizeof(float), nullptr)); - } + GLShaderProgram *shader = wxGetApp().get_current_shader(); + if (shader == nullptr) + return; - if (barycentric_id != -1) { - glsafe(::glEnableVertexAttribArray((GLint)barycentric_id)); - glsafe(::glVertexAttribPointer((GLint)barycentric_id, 3, GL_FLOAT, GL_FALSE, 6*sizeof(float), (GLvoid*)(intptr_t)(3 * sizeof(float)))); - } - //glsafe(::glVertexPointer(3, GL_FLOAT, 3 * sizeof(float), nullptr)); - //BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << boost::format(", Line %1%: triangle_indices_idx %2%, bind vertex vbo, buffer id %3%")%__LINE__%triangle_indices_idx%this->m_vertices_VBO_ids[triangle_indices_idx]; + glsafe(::glBindBuffer(GL_ARRAY_BUFFER, this->m_vertices_VBO_ids[triangle_indices_idx])); + const GLint position_id = shader->get_attrib_location("v_position"); + if (position_id != -1) { + glsafe(::glVertexAttribPointer((GLint) position_id, 3, GL_FLOAT, GL_FALSE, 3 * sizeof(float), nullptr)); + glsafe(::glEnableVertexAttribArray((GLint)position_id)); } - glsafe(::glEnableClientState(GL_VERTEX_ARRAY)); - // Render using the Vertex Buffer Objects. if (this->m_triangle_indices_sizes[triangle_indices_idx] > 0) { glsafe(::glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, this->m_triangle_indices_VBO_ids[triangle_indices_idx])); @@ -1482,14 +1455,10 @@ void TriangleSelectorPatch::render(int triangle_indices_idx, int position_id, in //BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << boost::format(", Line %1%: triangle_indices_idx %2%, bind indices vbo, buffer id %3%")%__LINE__%triangle_indices_idx%this->m_triangle_indices_VBO_ids[triangle_indices_idx]; } - glsafe(::glDisableClientState(GL_VERTEX_ARRAY)); - if ((this->m_triangle_indices_sizes[triangle_indices_idx] > 0)&&(position_id != -1)) + if (position_id != -1) glsafe(::glDisableVertexAttribArray(position_id)); - if ((this->m_triangle_indices_sizes[triangle_indices_idx] > 0)&&(barycentric_id != -1)) - glsafe(::glDisableVertexAttribArray((GLint)barycentric_id)); - if (this->m_triangle_indices_sizes[triangle_indices_idx] > 0) - glsafe(::glBindBuffer(GL_ARRAY_BUFFER, 0)); + glsafe(::glBindBuffer(GL_ARRAY_BUFFER, 0)); } void TriangleSelectorPatch::release_geometry() diff --git a/src/slic3r/GUI/Gizmos/GLGizmoPainterBase.hpp b/src/slic3r/GUI/Gizmos/GLGizmoPainterBase.hpp index 0582e7aa77..afba98fd7e 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmoPainterBase.hpp +++ b/src/slic3r/GUI/Gizmos/GLGizmoPainterBase.hpp @@ -35,7 +35,7 @@ public: virtual ~TriangleSelectorGUI() = default; virtual void render(ImGuiWrapper* imgui, const Transform3d& matrix); - void render(const Transform3d& matrix) { this->render(nullptr, matrix); } + //void render(const Transform3d& matrix) { this->render(nullptr, matrix); } void set_wireframe_needed(bool need_wireframe) { m_need_wireframe = need_wireframe; } bool get_wireframe_needed() { return m_need_wireframe; } @@ -170,7 +170,7 @@ protected: private: void update_render_data(); - void render(int buffer_idx, int position_id = -1, int barycentric_id = -1); + void render(int buffer_idx); };