diff --git a/src/slic3r/GUI/3DScene.cpp b/src/slic3r/GUI/3DScene.cpp index 9269458df..725f5f889 100644 --- a/src/slic3r/GUI/3DScene.cpp +++ b/src/slic3r/GUI/3DScene.cpp @@ -714,15 +714,10 @@ void GLVolume::render() if (this->is_left_handed()) glFrontFace(GL_CW); glsafe(::glCullFace(GL_BACK)); -#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 +#if !ENABLE_GLBEGIN_GLEND_SHADERS_ATTRIBUTES glsafe(::glPushMatrix()); glsafe(::glMultMatrixd(world_matrix().data())); -#if ENABLE_GLBEGIN_GLEND_SHADERS_ATTRIBUTES - } -#endif // ENABLE_GLBEGIN_GLEND_SHADERS_ATTRIBUTES +#endif // !ENABLE_GLBEGIN_GLEND_SHADERS_ATTRIBUTES #if ENABLE_GLINDEXEDVERTEXARRAY_REMOVAL if (tverts_range == std::make_pair(0, -1)) @@ -733,10 +728,9 @@ void GLVolume::render() this->indexed_vertex_array.render(this->tverts_range, this->qverts_range); #endif // ENABLE_GLINDEXEDVERTEXARRAY_REMOVAL -#if ENABLE_GLBEGIN_GLEND_SHADERS_ATTRIBUTES - if (!use_attributes) -#endif // ENABLE_GLBEGIN_GLEND_SHADERS_ATTRIBUTES +#if !ENABLE_GLBEGIN_GLEND_SHADERS_ATTRIBUTES glsafe(::glPopMatrix()); +#endif // !ENABLE_GLBEGIN_GLEND_SHADERS_ATTRIBUTES if (this->is_left_handed()) glFrontFace(GL_CCW); diff --git a/src/slic3r/GUI/GCodeViewer.cpp b/src/slic3r/GUI/GCodeViewer.cpp index 2cfcaa71f..cfef613ae 100644 --- a/src/slic3r/GUI/GCodeViewer.cpp +++ b/src/slic3r/GUI/GCodeViewer.cpp @@ -3196,16 +3196,13 @@ void GCodeViewer::render_toolpaths() #if ENABLE_GLBEGIN_GLEND_SHADERS_ATTRIBUTES int position_id = -1; int normal_id = -1; - const bool use_attributes = boost::algorithm::iends_with(shader->get_name(), "_attr"); - if (use_attributes) { - const Transform3d& view_matrix = camera.get_view_matrix(); - shader->set_uniform("view_model_matrix", view_matrix); - shader->set_uniform("projection_matrix", camera.get_projection_matrix()); - shader->set_uniform("normal_matrix", (Matrix3d)view_matrix.matrix().block(0, 0, 3, 3).inverse().transpose()); + const Transform3d& view_matrix = camera.get_view_matrix(); + shader->set_uniform("view_model_matrix", view_matrix); + shader->set_uniform("projection_matrix", camera.get_projection_matrix()); + shader->set_uniform("normal_matrix", (Matrix3d)view_matrix.matrix().block(0, 0, 3, 3).inverse().transpose()); - position_id = shader->get_attrib_location("v_position"); - normal_id = shader->get_attrib_location("v_normal"); - } + position_id = shader->get_attrib_location("v_position"); + normal_id = shader->get_attrib_location("v_normal"); #endif // ENABLE_GLBEGIN_GLEND_SHADERS_ATTRIBUTES if (buffer.render_primitive_type == TBuffer::ERenderPrimitiveType::InstancedModel) { @@ -3246,34 +3243,24 @@ void GCodeViewer::render_toolpaths() glsafe(::glBindBuffer(GL_ARRAY_BUFFER, i_buffer.vbo)); #if ENABLE_GLBEGIN_GLEND_SHADERS_ATTRIBUTES - if (use_attributes) { - if (position_id != -1) { - glsafe(::glVertexAttribPointer(position_id, buffer.vertices.position_size_floats(), GL_FLOAT, GL_FALSE, buffer.vertices.vertex_size_bytes(), (const void*)buffer.vertices.position_offset_bytes())); - glsafe(::glEnableVertexAttribArray(position_id)); - } - } - else { -#endif // ENABLE_GLBEGIN_GLEND_SHADERS_ATTRIBUTES - glsafe(::glVertexPointer(buffer.vertices.position_size_floats(), GL_FLOAT, buffer.vertices.vertex_size_bytes(), (const void*)buffer.vertices.position_offset_bytes())); - glsafe(::glEnableClientState(GL_VERTEX_ARRAY)); -#if ENABLE_GLBEGIN_GLEND_SHADERS_ATTRIBUTES + if (position_id != -1) { + glsafe(::glVertexAttribPointer(position_id, buffer.vertices.position_size_floats(), GL_FLOAT, GL_FALSE, buffer.vertices.vertex_size_bytes(), (const void*)buffer.vertices.position_offset_bytes())); + glsafe(::glEnableVertexAttribArray(position_id)); } +#else + glsafe(::glVertexPointer(buffer.vertices.position_size_floats(), GL_FLOAT, buffer.vertices.vertex_size_bytes(), (const void*)buffer.vertices.position_offset_bytes())); + glsafe(::glEnableClientState(GL_VERTEX_ARRAY)); #endif // ENABLE_GLBEGIN_GLEND_SHADERS_ATTRIBUTES const bool has_normals = buffer.vertices.normal_size_floats() > 0; if (has_normals) { #if ENABLE_GLBEGIN_GLEND_SHADERS_ATTRIBUTES - if (use_attributes) { - if (normal_id != -1) { - glsafe(::glVertexAttribPointer(normal_id, buffer.vertices.normal_size_floats(), GL_FLOAT, GL_FALSE, buffer.vertices.vertex_size_bytes(), (const void*)buffer.vertices.normal_offset_bytes())); - glsafe(::glEnableVertexAttribArray(normal_id)); - } - } - else { -#endif // ENABLE_GLBEGIN_GLEND_SHADERS_ATTRIBUTES - glsafe(::glNormalPointer(GL_FLOAT, buffer.vertices.vertex_size_bytes(), (const void*)buffer.vertices.normal_offset_bytes())); - glsafe(::glEnableClientState(GL_NORMAL_ARRAY)); -#if ENABLE_GLBEGIN_GLEND_SHADERS_ATTRIBUTES + if (normal_id != -1) { + glsafe(::glVertexAttribPointer(normal_id, buffer.vertices.normal_size_floats(), GL_FLOAT, GL_FALSE, buffer.vertices.vertex_size_bytes(), (const void*)buffer.vertices.normal_offset_bytes())); + glsafe(::glEnableVertexAttribArray(normal_id)); } +#else + glsafe(::glNormalPointer(GL_FLOAT, buffer.vertices.vertex_size_bytes(), (const void*)buffer.vertices.normal_offset_bytes())); + glsafe(::glEnableClientState(GL_NORMAL_ARRAY)); #endif // ENABLE_GLBEGIN_GLEND_SHADERS_ATTRIBUTES } @@ -3301,20 +3288,15 @@ void GCodeViewer::render_toolpaths() glsafe(::glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0)); #if ENABLE_GLBEGIN_GLEND_SHADERS_ATTRIBUTES - if (use_attributes) { - if (normal_id != -1) - glsafe(::glDisableVertexAttribArray(normal_id)); - if (position_id != -1) - glsafe(::glDisableVertexAttribArray(position_id)); - } - else { -#endif // ENABLE_GLBEGIN_GLEND_SHADERS_ATTRIBUTES - if (has_normals) - glsafe(::glDisableClientState(GL_NORMAL_ARRAY)); + if (normal_id != -1) + glsafe(::glDisableVertexAttribArray(normal_id)); + if (position_id != -1) + glsafe(::glDisableVertexAttribArray(position_id)); +#else + if (has_normals) + glsafe(::glDisableClientState(GL_NORMAL_ARRAY)); - glsafe(::glDisableClientState(GL_VERTEX_ARRAY)); -#if ENABLE_GLBEGIN_GLEND_SHADERS_ATTRIBUTES - } + glsafe(::glDisableClientState(GL_VERTEX_ARRAY)); #endif // ENABLE_GLBEGIN_GLEND_SHADERS_ATTRIBUTES glsafe(::glBindBuffer(GL_ARRAY_BUFFER, 0)); } @@ -3339,49 +3321,36 @@ void GCodeViewer::render_toolpaths() #if ENABLE_GLBEGIN_GLEND_SHADERS_ATTRIBUTES int position_id = -1; int normal_id = -1; - const bool use_attributes = boost::algorithm::iends_with(shader->get_name(), "_attr"); - if (use_attributes) { - const Camera& camera = wxGetApp().plater()->get_camera(); - const Transform3d& view_matrix = camera.get_view_matrix(); - shader->set_uniform("view_model_matrix", view_matrix); - shader->set_uniform("projection_matrix", camera.get_projection_matrix()); - shader->set_uniform("normal_matrix", (Matrix3d)view_matrix.matrix().block(0, 0, 3, 3).inverse().transpose()); + const Camera& camera = wxGetApp().plater()->get_camera(); + const Transform3d& view_matrix = camera.get_view_matrix(); + shader->set_uniform("view_model_matrix", view_matrix); + shader->set_uniform("projection_matrix", camera.get_projection_matrix()); + shader->set_uniform("normal_matrix", (Matrix3d)view_matrix.matrix().block(0, 0, 3, 3).inverse().transpose()); - position_id = shader->get_attrib_location("v_position"); - normal_id = shader->get_attrib_location("v_normal"); - } + position_id = shader->get_attrib_location("v_position"); + normal_id = shader->get_attrib_location("v_normal"); #endif // ENABLE_GLBEGIN_GLEND_SHADERS_ATTRIBUTES glsafe(::glBindBuffer(GL_ARRAY_BUFFER, cap.vbo)); #if ENABLE_GLBEGIN_GLEND_SHADERS_ATTRIBUTES - if (use_attributes) { - if (position_id != -1) { - glsafe(::glVertexAttribPointer(position_id, buffer->vertices.position_size_floats(), GL_FLOAT, GL_FALSE, buffer->vertices.vertex_size_bytes(), (const void*)buffer->vertices.position_offset_bytes())); - glsafe(::glEnableVertexAttribArray(position_id)); - } - } - else { -#endif // ENABLE_GLBEGIN_GLEND_SHADERS_ATTRIBUTES - glsafe(::glVertexPointer(buffer->vertices.position_size_floats(), GL_FLOAT, buffer->vertices.vertex_size_bytes(), (const void*)buffer->vertices.position_offset_bytes())); - glsafe(::glEnableClientState(GL_VERTEX_ARRAY)); -#if ENABLE_GLBEGIN_GLEND_SHADERS_ATTRIBUTES + if (position_id != -1) { + glsafe(::glVertexAttribPointer(position_id, buffer->vertices.position_size_floats(), GL_FLOAT, GL_FALSE, buffer->vertices.vertex_size_bytes(), (const void*)buffer->vertices.position_offset_bytes())); + glsafe(::glEnableVertexAttribArray(position_id)); } +#else + glsafe(::glVertexPointer(buffer->vertices.position_size_floats(), GL_FLOAT, buffer->vertices.vertex_size_bytes(), (const void*)buffer->vertices.position_offset_bytes())); + glsafe(::glEnableClientState(GL_VERTEX_ARRAY)); #endif // ENABLE_GLBEGIN_GLEND_SHADERS_ATTRIBUTES const bool has_normals = buffer->vertices.normal_size_floats() > 0; if (has_normals) { #if ENABLE_GLBEGIN_GLEND_SHADERS_ATTRIBUTES - if (use_attributes) { - if (normal_id != -1) { - glsafe(::glVertexAttribPointer(normal_id, buffer->vertices.normal_size_floats(), GL_FLOAT, GL_FALSE, buffer->vertices.vertex_size_bytes(), (const void*)buffer->vertices.normal_offset_bytes())); - glsafe(::glEnableVertexAttribArray(normal_id)); - } - } - else { -#endif // ENABLE_GLBEGIN_GLEND_SHADERS_ATTRIBUTES - glsafe(::glNormalPointer(GL_FLOAT, buffer->vertices.vertex_size_bytes(), (const void*)buffer->vertices.normal_offset_bytes())); - glsafe(::glEnableClientState(GL_NORMAL_ARRAY)); -#if ENABLE_GLBEGIN_GLEND_SHADERS_ATTRIBUTES + if (normal_id != -1) { + glsafe(::glVertexAttribPointer(normal_id, buffer->vertices.normal_size_floats(), GL_FLOAT, GL_FALSE, buffer->vertices.vertex_size_bytes(), (const void*)buffer->vertices.normal_offset_bytes())); + glsafe(::glEnableVertexAttribArray(normal_id)); } +#else + glsafe(::glNormalPointer(GL_FLOAT, buffer->vertices.vertex_size_bytes(), (const void*)buffer->vertices.normal_offset_bytes())); + glsafe(::glEnableClientState(GL_NORMAL_ARRAY)); #endif // ENABLE_GLBEGIN_GLEND_SHADERS_ATTRIBUTES } @@ -3396,20 +3365,15 @@ void GCodeViewer::render_toolpaths() #endif // ENABLE_GCODE_VIEWER_STATISTICS #if ENABLE_GLBEGIN_GLEND_SHADERS_ATTRIBUTES - if (use_attributes) { - if (normal_id != -1) - glsafe(::glDisableVertexAttribArray(normal_id)); - if (position_id != -1) - glsafe(::glDisableVertexAttribArray(position_id)); - } - else { -#endif // ENABLE_GLBEGIN_GLEND_SHADERS_ATTRIBUTES - if (has_normals) - glsafe(::glDisableClientState(GL_NORMAL_ARRAY)); + if (normal_id != -1) + glsafe(::glDisableVertexAttribArray(normal_id)); + if (position_id != -1) + glsafe(::glDisableVertexAttribArray(position_id)); +#else + if (has_normals) + glsafe(::glDisableClientState(GL_NORMAL_ARRAY)); - glsafe(::glDisableClientState(GL_VERTEX_ARRAY)); -#if ENABLE_GLBEGIN_GLEND_SHADERS_ATTRIBUTES - } + glsafe(::glDisableClientState(GL_VERTEX_ARRAY)); #endif // ENABLE_GLBEGIN_GLEND_SHADERS_ATTRIBUTES glsafe(::glBindBuffer(GL_ARRAY_BUFFER, 0)); diff --git a/src/slic3r/GUI/GLModel.cpp b/src/slic3r/GUI/GLModel.cpp index 13606cb65..44d0eb78d 100644 --- a/src/slic3r/GUI/GLModel.cpp +++ b/src/slic3r/GUI/GLModel.cpp @@ -982,8 +982,6 @@ void GLModel::render(const std::pair& range) glsafe(::glBindBuffer(GL_ARRAY_BUFFER, m_render_data.vbo_id)); #if ENABLE_GLBEGIN_GLEND_SHADERS_ATTRIBUTES - bool use_attributes = boost::algorithm::iends_with(shader->get_name(), "_attr"); - int position_id = -1; int normal_id = -1; int tex_coord_id = -1; @@ -991,53 +989,38 @@ void GLModel::render(const std::pair& range) if (position) { #if ENABLE_GLBEGIN_GLEND_SHADERS_ATTRIBUTES - if (use_attributes) { - position_id = shader->get_attrib_location("v_position"); - if (position_id != -1) { - glsafe(::glVertexAttribPointer(position_id, Geometry::position_stride_floats(data.format), GL_FLOAT, GL_FALSE, vertex_stride_bytes, (GLvoid*)Geometry::position_offset_bytes(data.format))); - glsafe(::glEnableVertexAttribArray(position_id)); - } - } - else { -#endif // ENABLE_GLBEGIN_GLEND_SHADERS_ATTRIBUTES - glsafe(::glVertexPointer(Geometry::position_stride_floats(data.format), GL_FLOAT, vertex_stride_bytes, (const void*)Geometry::position_offset_bytes(data.format))); - glsafe(::glEnableClientState(GL_VERTEX_ARRAY)); -#if ENABLE_GLBEGIN_GLEND_SHADERS_ATTRIBUTES + position_id = shader->get_attrib_location("v_position"); + if (position_id != -1) { + glsafe(::glVertexAttribPointer(position_id, Geometry::position_stride_floats(data.format), GL_FLOAT, GL_FALSE, vertex_stride_bytes, (GLvoid*)Geometry::position_offset_bytes(data.format))); + glsafe(::glEnableVertexAttribArray(position_id)); } +#else + glsafe(::glVertexPointer(Geometry::position_stride_floats(data.format), GL_FLOAT, vertex_stride_bytes, (const void*)Geometry::position_offset_bytes(data.format))); + glsafe(::glEnableClientState(GL_VERTEX_ARRAY)); #endif // ENABLE_GLBEGIN_GLEND_SHADERS_ATTRIBUTES } if (normal) { #if ENABLE_GLBEGIN_GLEND_SHADERS_ATTRIBUTES - if (use_attributes) { - normal_id = shader->get_attrib_location("v_normal"); - if (normal_id != -1) { - glsafe(::glVertexAttribPointer(normal_id, Geometry::normal_stride_floats(data.format), GL_FLOAT, GL_FALSE, vertex_stride_bytes, (GLvoid*)Geometry::normal_offset_bytes(data.format))); - glsafe(::glEnableVertexAttribArray(normal_id)); - } - } - else { -#endif // ENABLE_GLBEGIN_GLEND_SHADERS_ATTRIBUTES - glsafe(::glNormalPointer(GL_FLOAT, vertex_stride_bytes, (const void*)Geometry::normal_offset_bytes(data.format))); - glsafe(::glEnableClientState(GL_NORMAL_ARRAY)); -#if ENABLE_GLBEGIN_GLEND_SHADERS_ATTRIBUTES + normal_id = shader->get_attrib_location("v_normal"); + if (normal_id != -1) { + glsafe(::glVertexAttribPointer(normal_id, Geometry::normal_stride_floats(data.format), GL_FLOAT, GL_FALSE, vertex_stride_bytes, (GLvoid*)Geometry::normal_offset_bytes(data.format))); + glsafe(::glEnableVertexAttribArray(normal_id)); } +#else + glsafe(::glNormalPointer(GL_FLOAT, vertex_stride_bytes, (const void*)Geometry::normal_offset_bytes(data.format))); + glsafe(::glEnableClientState(GL_NORMAL_ARRAY)); #endif // ENABLE_GLBEGIN_GLEND_SHADERS_ATTRIBUTES } if (tex_coord) { #if ENABLE_GLBEGIN_GLEND_SHADERS_ATTRIBUTES - if (use_attributes) { - tex_coord_id = shader->get_attrib_location("v_tex_coord"); - if (tex_coord_id != -1) { - glsafe(::glVertexAttribPointer(tex_coord_id, Geometry::tex_coord_stride_floats(data.format), GL_FLOAT, GL_FALSE, vertex_stride_bytes, (GLvoid*)Geometry::tex_coord_offset_bytes(data.format))); - glsafe(::glEnableVertexAttribArray(tex_coord_id)); - } - } - else { -#endif // ENABLE_GLBEGIN_GLEND_SHADERS_ATTRIBUTES - glsafe(::glTexCoordPointer(Geometry::tex_coord_stride_floats(data.format), GL_FLOAT, vertex_stride_bytes, (const void*)Geometry::tex_coord_offset_bytes(data.format))); - glsafe(::glEnableClientState(GL_TEXTURE_COORD_ARRAY)); -#if ENABLE_GLBEGIN_GLEND_SHADERS_ATTRIBUTES + tex_coord_id = shader->get_attrib_location("v_tex_coord"); + if (tex_coord_id != -1) { + glsafe(::glVertexAttribPointer(tex_coord_id, Geometry::tex_coord_stride_floats(data.format), GL_FLOAT, GL_FALSE, vertex_stride_bytes, (GLvoid*)Geometry::tex_coord_offset_bytes(data.format))); + glsafe(::glEnableVertexAttribArray(tex_coord_id)); } +#else + glsafe(::glTexCoordPointer(Geometry::tex_coord_stride_floats(data.format), GL_FLOAT, vertex_stride_bytes, (const void*)Geometry::tex_coord_offset_bytes(data.format))); + glsafe(::glEnableClientState(GL_TEXTURE_COORD_ARRAY)); #endif // ENABLE_GLBEGIN_GLEND_SHADERS_ATTRIBUTES } @@ -1048,24 +1031,19 @@ void GLModel::render(const std::pair& range) glsafe(::glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0)); #if ENABLE_GLBEGIN_GLEND_SHADERS_ATTRIBUTES - if (use_attributes) { - if (tex_coord_id != -1) - glsafe(::glDisableVertexAttribArray(tex_coord_id)); - if (normal_id != -1) - glsafe(::glDisableVertexAttribArray(normal_id)); - if (position_id != -1) - glsafe(::glDisableVertexAttribArray(position_id)); - } - else { -#endif // ENABLE_GLBEGIN_GLEND_SHADERS_ATTRIBUTES - if (tex_coord) - glsafe(::glDisableClientState(GL_TEXTURE_COORD_ARRAY)); - if (normal) - glsafe(::glDisableClientState(GL_NORMAL_ARRAY)); - if (position) - glsafe(::glDisableClientState(GL_VERTEX_ARRAY)); -#if ENABLE_GLBEGIN_GLEND_SHADERS_ATTRIBUTES - } + if (tex_coord_id != -1) + glsafe(::glDisableVertexAttribArray(tex_coord_id)); + if (normal_id != -1) + glsafe(::glDisableVertexAttribArray(normal_id)); + if (position_id != -1) + glsafe(::glDisableVertexAttribArray(position_id)); +#else + if (tex_coord) + glsafe(::glDisableClientState(GL_TEXTURE_COORD_ARRAY)); + if (normal) + glsafe(::glDisableClientState(GL_NORMAL_ARRAY)); + if (position) + glsafe(::glDisableClientState(GL_VERTEX_ARRAY)); #endif // ENABLE_GLBEGIN_GLEND_SHADERS_ATTRIBUTES glsafe(::glBindBuffer(GL_ARRAY_BUFFER, 0));