diff --git a/src/slic3r/GUI/3DBed.cpp b/src/slic3r/GUI/3DBed.cpp index 0964aba2e..177c508ad 100644 --- a/src/slic3r/GUI/3DBed.cpp +++ b/src/slic3r/GUI/3DBed.cpp @@ -366,7 +366,7 @@ void Bed3D::init_triangles() return; GLModel::Geometry init_data; - init_data.format = { GLModel::Geometry::EPrimitiveType::Triangles, GLModel::Geometry::EVertexLayout::P3T2, GLModel::Geometry::index_type(triangles.size()) }; + init_data.format = { GLModel::Geometry::EPrimitiveType::Triangles, GLModel::Geometry::EVertexLayout::P3T2 }; init_data.reserve_vertices(triangles.size()); init_data.reserve_indices(triangles.size() / 3); @@ -390,12 +390,8 @@ void Bed3D::init_triangles() const Vec3f p = { v.x(), v.y(), GROUND_Z }; init_data.add_vertex(p, (Vec2f)(v - min).cwiseProduct(inv_size).eval()); ++vertices_counter; - if (vertices_counter % 3 == 0) { - if (init_data.format.index_type == GLModel::Geometry::EIndexType::USHORT) - init_data.add_ushort_triangle((unsigned short)vertices_counter - 3, (unsigned short)vertices_counter - 2, (unsigned short)vertices_counter - 1); - else - init_data.add_uint_triangle(vertices_counter - 3, vertices_counter - 2, vertices_counter - 1); - } + if (vertices_counter % 3 == 0) + init_data.add_triangle(vertices_counter - 3, vertices_counter - 2, vertices_counter - 1); } m_triangles.init_from(std::move(init_data)); @@ -434,7 +430,7 @@ void Bed3D::init_gridlines() std::copy(contour_lines.begin(), contour_lines.end(), std::back_inserter(gridlines)); GLModel::Geometry init_data; - init_data.format = { GLModel::Geometry::EPrimitiveType::Lines, GLModel::Geometry::EVertexLayout::P3, GLModel::Geometry::index_type(2 * gridlines.size()) }; + init_data.format = { GLModel::Geometry::EPrimitiveType::Lines, GLModel::Geometry::EVertexLayout::P3 }; init_data.reserve_vertices(2 * gridlines.size()); init_data.reserve_indices(2 * gridlines.size()); @@ -442,10 +438,7 @@ void Bed3D::init_gridlines() init_data.add_vertex(Vec3f(unscale(l.a.x()), unscale(l.a.y()), GROUND_Z)); init_data.add_vertex(Vec3f(unscale(l.b.x()), unscale(l.b.y()), GROUND_Z)); const unsigned int vertices_counter = (unsigned int)init_data.vertices_count(); - if (init_data.format.index_type == GLModel::Geometry::EIndexType::USHORT) - init_data.add_ushort_line((unsigned short)vertices_counter - 2, (unsigned short)vertices_counter - 1); - else - init_data.add_uint_line(vertices_counter - 2, vertices_counter - 1); + init_data.add_line(vertices_counter - 2, vertices_counter - 1); } m_gridlines.init_from(std::move(init_data)); diff --git a/src/slic3r/GUI/3DScene.cpp b/src/slic3r/GUI/3DScene.cpp index d13ffa912..0e7c551d5 100644 --- a/src/slic3r/GUI/3DScene.cpp +++ b/src/slic3r/GUI/3DScene.cpp @@ -335,7 +335,7 @@ void GLVolume::SinkingContours::update() m_model.reset(); GUI::GLModel::Geometry init_data; #if ENABLE_LEGACY_OPENGL_REMOVAL - init_data.format = { GUI::GLModel::Geometry::EPrimitiveType::Triangles, GUI::GLModel::Geometry::EVertexLayout::P3, GUI::GLModel::Geometry::EIndexType::UINT }; + init_data.format = { GUI::GLModel::Geometry::EPrimitiveType::Triangles, GUI::GLModel::Geometry::EVertexLayout::P3 }; init_data.color = ColorRGBA::WHITE(); unsigned int vertices_counter = 0; #endif // ENABLE_LEGACY_OPENGL_REMOVAL @@ -351,7 +351,7 @@ void GLVolume::SinkingContours::update() init_data.add_vertex((Vec3f)(v.cast() + 0.015f * Vec3f::UnitZ())); // add a small positive z to avoid z-fighting ++vertices_counter; if (vertices_counter % 3 == 0) - init_data.add_uint_triangle(vertices_counter - 3, vertices_counter - 2, vertices_counter - 1); + init_data.add_triangle(vertices_counter - 3, vertices_counter - 2, vertices_counter - 1); } } m_model.init_from(std::move(init_data)); @@ -431,7 +431,7 @@ void GLVolume::NonManifoldEdges::update() if (!edges.empty()) { GUI::GLModel::Geometry init_data; #if ENABLE_LEGACY_OPENGL_REMOVAL - init_data.format = { GUI::GLModel::Geometry::EPrimitiveType::Lines, GUI::GLModel::Geometry::EVertexLayout::P3, GUI::GLModel::Geometry::index_type(2 * edges.size()) }; + init_data.format = { GUI::GLModel::Geometry::EPrimitiveType::Lines, GUI::GLModel::Geometry::EVertexLayout::P3 }; init_data.reserve_vertices(2 * edges.size()); init_data.reserve_indices(2 * edges.size()); @@ -441,10 +441,7 @@ void GLVolume::NonManifoldEdges::update() init_data.add_vertex((Vec3f)mesh.its.vertices[edge.first].cast()); init_data.add_vertex((Vec3f)mesh.its.vertices[edge.second].cast()); vertices_count += 2; - if (init_data.format.index_type == GUI::GLModel::Geometry::EIndexType::USHORT) - init_data.add_ushort_line((unsigned short)vertices_count - 2, (unsigned short)vertices_count - 1); - else - init_data.add_uint_line(vertices_count - 2, vertices_count - 1); + init_data.add_line(vertices_count - 2, vertices_count - 1); } m_model.init_from(std::move(init_data)); #else @@ -1480,8 +1477,8 @@ static void thick_lines_to_geometry( if (!is_first && bottom_z_different) { // Found a change of the layer thickness -> Add a cap at the end of the previous segment. - geometry.add_uint_triangle(idx_b[Bottom], idx_b[Left], idx_b[Top]); - geometry.add_uint_triangle(idx_b[Bottom], idx_b[Top], idx_b[Right]); + geometry.add_triangle(idx_b[Bottom], idx_b[Left], idx_b[Top]); + geometry.add_triangle(idx_b[Bottom], idx_b[Top], idx_b[Right]); } // Share top / bottom vertices if possible. @@ -1531,13 +1528,13 @@ static void thick_lines_to_geometry( geometry.add_vertex(Vec3f(a2.x(), a2.y(), middle_z), Vec3f(-xy_right_normal.x(), -xy_right_normal.y(), 0.0f)); if (cross2(v_prev, v) > 0.0) { // Right turn. Fill in the right turn wedge. - geometry.add_uint_triangle(idx_prev[Right], idx_a[Right], idx_prev[Top]); - geometry.add_uint_triangle(idx_prev[Right], idx_prev[Bottom], idx_a[Right]); + geometry.add_triangle(idx_prev[Right], idx_a[Right], idx_prev[Top]); + geometry.add_triangle(idx_prev[Right], idx_prev[Bottom], idx_a[Right]); } else { // Left turn. Fill in the left turn wedge. - geometry.add_uint_triangle(idx_prev[Left], idx_prev[Top], idx_a[Left]); - geometry.add_uint_triangle(idx_prev[Left], idx_a[Left], idx_prev[Bottom]); + geometry.add_triangle(idx_prev[Left], idx_prev[Top], idx_a[Left]); + geometry.add_triangle(idx_prev[Left], idx_a[Left], idx_prev[Bottom]); } } } @@ -1559,11 +1556,11 @@ static void thick_lines_to_geometry( // Replace the left / right vertex indices to point to the start of the loop. const size_t indices_count = geometry.indices_count(); for (size_t u = indices_count - 24; u < indices_count; ++u) { - const unsigned int id = geometry.extract_uint_index(u); + const unsigned int id = geometry.extract_index(u); if (id == (unsigned int)idx_prev[Left]) - geometry.set_uint_index(u, (unsigned int)idx_initial[Left]); + geometry.set_index(u, (unsigned int)idx_initial[Left]); else if (id == (unsigned int)idx_prev[Right]) - geometry.set_uint_index(u, (unsigned int)idx_initial[Right]); + geometry.set_index(u, (unsigned int)idx_initial[Right]); } } } @@ -1600,36 +1597,36 @@ static void thick_lines_to_geometry( if (bottom_z_different && (closed || (!is_first && !is_last))) { // Found a change of the layer thickness -> Add a cap at the beginning of this segment. - geometry.add_uint_triangle(idx_a[Bottom], idx_a[Right], idx_a[Top]); - geometry.add_uint_triangle(idx_a[Bottom], idx_a[Top], idx_a[Left]); + geometry.add_triangle(idx_a[Bottom], idx_a[Right], idx_a[Top]); + geometry.add_triangle(idx_a[Bottom], idx_a[Top], idx_a[Left]); } if (!closed) { // Terminate open paths with caps. if (is_first) { - geometry.add_uint_triangle(idx_a[Bottom], idx_a[Right], idx_a[Top]); - geometry.add_uint_triangle(idx_a[Bottom], idx_a[Top], idx_a[Left]); + geometry.add_triangle(idx_a[Bottom], idx_a[Right], idx_a[Top]); + geometry.add_triangle(idx_a[Bottom], idx_a[Top], idx_a[Left]); } // We don't use 'else' because both cases are true if we have only one line. if (is_last) { - geometry.add_uint_triangle(idx_b[Bottom], idx_b[Left], idx_b[Top]); - geometry.add_uint_triangle(idx_b[Bottom], idx_b[Top], idx_b[Right]); + geometry.add_triangle(idx_b[Bottom], idx_b[Left], idx_b[Top]); + geometry.add_triangle(idx_b[Bottom], idx_b[Top], idx_b[Right]); } } // Add quads for a straight hollow tube-like segment. // bottom-right face - geometry.add_uint_triangle(idx_a[Bottom], idx_b[Bottom], idx_b[Right]); - geometry.add_uint_triangle(idx_a[Bottom], idx_b[Right], idx_a[Right]); + geometry.add_triangle(idx_a[Bottom], idx_b[Bottom], idx_b[Right]); + geometry.add_triangle(idx_a[Bottom], idx_b[Right], idx_a[Right]); // top-right face - geometry.add_uint_triangle(idx_a[Right], idx_b[Right], idx_b[Top]); - geometry.add_uint_triangle(idx_a[Right], idx_b[Top], idx_a[Top]); + geometry.add_triangle(idx_a[Right], idx_b[Right], idx_b[Top]); + geometry.add_triangle(idx_a[Right], idx_b[Top], idx_a[Top]); // top-left face - geometry.add_uint_triangle(idx_a[Top], idx_b[Top], idx_b[Left]); - geometry.add_uint_triangle(idx_a[Top], idx_b[Left], idx_a[Left]); + geometry.add_triangle(idx_a[Top], idx_b[Top], idx_b[Left]); + geometry.add_triangle(idx_a[Top], idx_b[Left], idx_a[Left]); // bottom-left face - geometry.add_uint_triangle(idx_a[Left], idx_b[Left], idx_b[Bottom]); - geometry.add_uint_triangle(idx_a[Left], idx_b[Bottom], idx_a[Bottom]); + geometry.add_triangle(idx_a[Left], idx_b[Left], idx_b[Bottom]); + geometry.add_triangle(idx_a[Left], idx_b[Bottom], idx_a[Bottom]); } } @@ -1769,13 +1766,13 @@ static void thick_lines_to_geometry( if (is_right_turn) { // Right turn. Fill in the right turn wedge. - geometry.add_uint_triangle(idx_prev[Right], idx_a[Right], idx_prev[Top]); - geometry.add_uint_triangle(idx_prev[Right], idx_prev[Bottom], idx_a[Right]); + geometry.add_triangle(idx_prev[Right], idx_a[Right], idx_prev[Top]); + geometry.add_triangle(idx_prev[Right], idx_prev[Bottom], idx_a[Right]); } else { // Left turn. Fill in the left turn wedge. - geometry.add_uint_triangle(idx_prev[Left], idx_prev[Top], idx_a[Left]); - geometry.add_uint_triangle(idx_prev[Left], idx_a[Left], idx_prev[Bottom]); + geometry.add_triangle(idx_prev[Left], idx_prev[Top], idx_a[Left]); + geometry.add_triangle(idx_prev[Left], idx_a[Left], idx_prev[Bottom]); } } else { @@ -1794,11 +1791,11 @@ static void thick_lines_to_geometry( // Replace the left / right vertex indices to point to the start of the loop. const size_t indices_count = geometry.indices_count(); for (size_t u = indices_count - 24; u < indices_count; ++u) { - const unsigned int id = geometry.extract_uint_index(u); + const unsigned int id = geometry.extract_index(u); if (id == (unsigned int)idx_prev[Left]) - geometry.set_uint_index(u, (unsigned int)idx_initial[Left]); + geometry.set_index(u, (unsigned int)idx_initial[Left]); else if (id == (unsigned int)idx_prev[Right]) - geometry.set_uint_index(u, (unsigned int)idx_initial[Right]); + geometry.set_index(u, (unsigned int)idx_initial[Right]); } } @@ -1837,30 +1834,30 @@ static void thick_lines_to_geometry( if (!closed) { // Terminate open paths with caps. if (i == 0) { - geometry.add_uint_triangle(idx_a[Bottom], idx_a[Right], idx_a[Top]); - geometry.add_uint_triangle(idx_a[Bottom], idx_a[Top], idx_a[Left]); + geometry.add_triangle(idx_a[Bottom], idx_a[Right], idx_a[Top]); + geometry.add_triangle(idx_a[Bottom], idx_a[Top], idx_a[Left]); } // We don't use 'else' because both cases are true if we have only one line. if (i + 1 == lines.size()) { - geometry.add_uint_triangle(idx_b[Bottom], idx_b[Left], idx_b[Top]); - geometry.add_uint_triangle(idx_b[Bottom], idx_b[Top], idx_b[Right]); + geometry.add_triangle(idx_b[Bottom], idx_b[Left], idx_b[Top]); + geometry.add_triangle(idx_b[Bottom], idx_b[Top], idx_b[Right]); } } // Add quads for a straight hollow tube-like segment. // bottom-right face - geometry.add_uint_triangle(idx_a[Bottom], idx_b[Bottom], idx_b[Right]); - geometry.add_uint_triangle(idx_a[Bottom], idx_b[Right], idx_a[Right]); + geometry.add_triangle(idx_a[Bottom], idx_b[Bottom], idx_b[Right]); + geometry.add_triangle(idx_a[Bottom], idx_b[Right], idx_a[Right]); // top-right face - geometry.add_uint_triangle(idx_a[Right], idx_b[Right], idx_b[Top]); - geometry.add_uint_triangle(idx_a[Right], idx_b[Top], idx_a[Top]); + geometry.add_triangle(idx_a[Right], idx_b[Right], idx_b[Top]); + geometry.add_triangle(idx_a[Right], idx_b[Top], idx_a[Top]); // top-left face - geometry.add_uint_triangle(idx_a[Top], idx_b[Top], idx_b[Left]); - geometry.add_uint_triangle(idx_a[Top], idx_b[Left], idx_a[Left]); + geometry.add_triangle(idx_a[Top], idx_b[Top], idx_b[Left]); + geometry.add_triangle(idx_a[Top], idx_b[Left], idx_a[Left]); // bottom-left face - geometry.add_uint_triangle(idx_a[Left], idx_b[Left], idx_b[Bottom]); - geometry.add_uint_triangle(idx_a[Left], idx_b[Bottom], idx_a[Bottom]); + geometry.add_triangle(idx_a[Left], idx_b[Left], idx_b[Bottom]); + geometry.add_triangle(idx_a[Left], idx_b[Bottom], idx_a[Bottom]); } } #else diff --git a/src/slic3r/GUI/GCodeViewer.cpp b/src/slic3r/GUI/GCodeViewer.cpp index 4f6fdc7af..0c3dd6560 100644 --- a/src/slic3r/GUI/GCodeViewer.cpp +++ b/src/slic3r/GUI/GCodeViewer.cpp @@ -1675,7 +1675,7 @@ void GCodeViewer::load_toolpaths(const GCodeProcessorResult& gcode_result) #if ENABLE_LEGACY_OPENGL_REMOVAL const size_t indices_count = data.indices_count(); for (size_t i = 0; i < indices_count; ++i) { - indices.push_back(static_cast(data.extract_ushort_index(i) + base_index)); + indices.push_back(static_cast(data.extract_index(i) + base_index)); } #else for (const auto& entity : data.entities) { diff --git a/src/slic3r/GUI/GLCanvas3D.cpp b/src/slic3r/GUI/GLCanvas3D.cpp index 10e4efc11..4a42e11c1 100644 --- a/src/slic3r/GUI/GLCanvas3D.cpp +++ b/src/slic3r/GUI/GLCanvas3D.cpp @@ -161,7 +161,11 @@ void GLCanvas3D::LayersEditing::select_object(const Model &model, int object_id) bool GLCanvas3D::LayersEditing::is_allowed() const { +#if ENABLE_GL_SHADERS_ATTRIBUTES + return wxGetApp().get_shader("variable_layer_height_attr") != nullptr && m_z_texture_id > 0; +#else return wxGetApp().get_shader("variable_layer_height") != nullptr && m_z_texture_id > 0; +#endif // ENABLE_GL_SHADERS_ATTRIBUTES } bool GLCanvas3D::LayersEditing::is_enabled() const @@ -324,7 +328,11 @@ Rect GLCanvas3D::LayersEditing::get_bar_rect_viewport(const GLCanvas3D& canvas) bool GLCanvas3D::LayersEditing::is_initialized() const { +#if ENABLE_GL_SHADERS_ATTRIBUTES + return wxGetApp().get_shader("variable_layer_height_attr") != nullptr; +#else return wxGetApp().get_shader("variable_layer_height") != nullptr; +#endif // ENABLE_GL_SHADERS_ATTRIBUTES } std::string GLCanvas3D::LayersEditing::get_tooltip(const GLCanvas3D& canvas) const @@ -402,7 +410,7 @@ void GLCanvas3D::LayersEditing::render_active_object_annotations(const GLCanvas3 m_profile.background.reset(); GLModel::Geometry init_data; - init_data.format = { GLModel::Geometry::EPrimitiveType::Triangles, GLModel::Geometry::EVertexLayout::P2T2, GLModel::Geometry::EIndexType::USHORT }; + init_data.format = { GLModel::Geometry::EPrimitiveType::Triangles, GLModel::Geometry::EVertexLayout::P2T2 }; init_data.reserve_vertices(4); init_data.reserve_indices(6); @@ -424,8 +432,8 @@ void GLCanvas3D::LayersEditing::render_active_object_annotations(const GLCanvas3 init_data.add_vertex(Vec2f(l, t), Vec2f(0.0f, 1.0f)); // indices - init_data.add_ushort_triangle(0, 1, 2); - init_data.add_ushort_triangle(2, 3, 0); + init_data.add_triangle(0, 1, 2); + init_data.add_triangle(2, 3, 0); m_profile.background.init_from(std::move(init_data)); } @@ -491,7 +499,7 @@ void GLCanvas3D::LayersEditing::render_profile(const Rect& bar_rect) m_profile.baseline.reset(); GLModel::Geometry init_data; - init_data.format = { GLModel::Geometry::EPrimitiveType::Lines, GLModel::Geometry::EVertexLayout::P2, GLModel::Geometry::EIndexType::USHORT }; + init_data.format = { GLModel::Geometry::EPrimitiveType::Lines, GLModel::Geometry::EVertexLayout::P2 }; init_data.color = ColorRGBA::BLACK(); init_data.reserve_vertices(2); init_data.reserve_indices(2); @@ -508,7 +516,7 @@ void GLCanvas3D::LayersEditing::render_profile(const Rect& bar_rect) #endif // ENABLE_GL_SHADERS_ATTRIBUTES // indices - init_data.add_ushort_line(0, 1); + init_data.add_line(0, 1); m_profile.baseline.init_from(std::move(init_data)); } @@ -522,7 +530,7 @@ void GLCanvas3D::LayersEditing::render_profile(const Rect& bar_rect) m_profile.profile.reset(); GLModel::Geometry init_data; - init_data.format = { GLModel::Geometry::EPrimitiveType::LineStrip, GLModel::Geometry::EVertexLayout::P2, GLModel::Geometry::index_type(m_layer_height_profile.size() / 2) }; + init_data.format = { GLModel::Geometry::EPrimitiveType::LineStrip, GLModel::Geometry::EVertexLayout::P2 }; init_data.color = ColorRGBA::BLUE(); init_data.reserve_vertices(m_layer_height_profile.size() / 2); init_data.reserve_indices(m_layer_height_profile.size() / 2); @@ -536,10 +544,7 @@ void GLCanvas3D::LayersEditing::render_profile(const Rect& bar_rect) init_data.add_vertex(Vec2f(bar_rect.get_left() + float(m_layer_height_profile[i + 1]) * scale_x, bar_rect.get_bottom() + float(m_layer_height_profile[i]) * scale_y)); #endif // ENABLE_GL_SHADERS_ATTRIBUTES - if (init_data.format.index_type == GLModel::Geometry::EIndexType::USHORT) - init_data.add_ushort_index((unsigned short)i / 2); - else - init_data.add_uint_index(i / 2); + init_data.add_index(i / 2); } m_profile.profile.init_from(std::move(init_data)); @@ -994,7 +999,7 @@ void GLCanvas3D::SequentialPrintClearance::set_polygons(const Polygons& polygons if (m_render_fill) { GLModel::Geometry fill_data; #if ENABLE_LEGACY_OPENGL_REMOVAL - fill_data.format = { GLModel::Geometry::EPrimitiveType::Triangles, GLModel::Geometry::EVertexLayout::P3, GLModel::Geometry::EIndexType::UINT }; + fill_data.format = { GLModel::Geometry::EPrimitiveType::Triangles, GLModel::Geometry::EVertexLayout::P3 }; fill_data.color = { 0.3333f, 0.0f, 0.0f, 0.5f }; // vertices + indices @@ -1008,7 +1013,7 @@ void GLCanvas3D::SequentialPrintClearance::set_polygons(const Polygons& polygons fill_data.add_vertex((Vec3f)(v.cast() + 0.0125f * Vec3f::UnitZ())); // add a small positive z to avoid z-fighting ++vertices_counter; if (vertices_counter % 3 == 0) - fill_data.add_uint_triangle(vertices_counter - 3, vertices_counter - 2, vertices_counter - 1); + fill_data.add_triangle(vertices_counter - 3, vertices_counter - 2, vertices_counter - 1); } } @@ -5439,7 +5444,7 @@ void GLCanvas3D::_render_background() m_background.reset(); GLModel::Geometry init_data; - init_data.format = { GLModel::Geometry::EPrimitiveType::Triangles, GLModel::Geometry::EVertexLayout::P2T2, GLModel::Geometry::EIndexType::USHORT }; + init_data.format = { GLModel::Geometry::EPrimitiveType::Triangles, GLModel::Geometry::EVertexLayout::P2T2 }; init_data.reserve_vertices(4); init_data.reserve_indices(6); @@ -5450,8 +5455,8 @@ void GLCanvas3D::_render_background() init_data.add_vertex(Vec2f(-1.0f, 1.0f), Vec2f(0.0f, 1.0f)); // indices - init_data.add_ushort_triangle(0, 1, 2); - init_data.add_ushort_triangle(2, 3, 0); + init_data.add_triangle(0, 1, 2); + init_data.add_triangle(2, 3, 0); m_background.init_from(std::move(init_data)); } @@ -6142,7 +6147,7 @@ void GLCanvas3D::_render_sla_slices() #if ENABLE_LEGACY_OPENGL_REMOVAL auto init_model = [](GLModel& model, const Pointf3s& triangles, const ColorRGBA& color) { GLModel::Geometry init_data; - init_data.format = { GLModel::Geometry::EPrimitiveType::Triangles, GLModel::Geometry::EVertexLayout::P3, GLModel::Geometry::index_type(triangles.size()) }; + init_data.format = { GLModel::Geometry::EPrimitiveType::Triangles, GLModel::Geometry::EVertexLayout::P3 }; init_data.reserve_vertices(triangles.size()); init_data.reserve_indices(triangles.size() / 3); init_data.color = color; @@ -6151,12 +6156,8 @@ void GLCanvas3D::_render_sla_slices() for (const Vec3d& v : triangles) { init_data.add_vertex((Vec3f)v.cast()); ++vertices_count; - if (vertices_count % 3 == 0) { - if (init_data.format.index_type == GLModel::Geometry::EIndexType::USHORT) - init_data.add_ushort_triangle((unsigned short)vertices_count - 3, (unsigned short)vertices_count - 2, (unsigned short)vertices_count - 1); - else - init_data.add_uint_triangle(vertices_count - 3, vertices_count - 2, vertices_count - 1); - } + if (vertices_count % 3 == 0) + init_data.add_triangle(vertices_count - 3, vertices_count - 2, vertices_count - 1); } if (!init_data.is_empty()) @@ -6485,7 +6486,7 @@ void GLCanvas3D::_load_print_toolpaths(const BuildVolume &build_volume) #if ENABLE_LEGACY_OPENGL_REMOVAL GLVolume* volume = m_volumes.new_toolpath_volume(color); GLModel::Geometry init_data; - init_data.format = { GLModel::Geometry::EPrimitiveType::Triangles, GLModel::Geometry::EVertexLayout::P3N3, GLModel::Geometry::EIndexType::UINT }; + init_data.format = { GLModel::Geometry::EPrimitiveType::Triangles, GLModel::Geometry::EVertexLayout::P3N3 }; #else GLVolume *volume = m_volumes.new_toolpath_volume(color, VERTEX_BUFFER_RESERVE_SIZE); #endif // ENABLE_LEGACY_OPENGL_REMOVAL @@ -6750,7 +6751,7 @@ void GLCanvas3D::_load_print_object_toolpaths(const PrintObject& print_object, c #if ENABLE_LEGACY_OPENGL_REMOVAL assert(vols.size() == geometries.size()); for (GLModel::Geometry& g : geometries) { - g.format = { GLModel::Geometry::EPrimitiveType::Triangles, GLModel::Geometry::EVertexLayout::P3N3, GLModel::Geometry::EIndexType::UINT }; + g.format = { GLModel::Geometry::EPrimitiveType::Triangles, GLModel::Geometry::EVertexLayout::P3N3 }; } #else for (GLVolume *vol : vols) @@ -7006,7 +7007,7 @@ void GLCanvas3D::_load_wipe_tower_toolpaths(const BuildVolume& build_volume, con #if ENABLE_LEGACY_OPENGL_REMOVAL assert(vols.size() == geometries.size()); for (GLModel::Geometry& g : geometries) { - g.format = { GLModel::Geometry::EPrimitiveType::Triangles, GLModel::Geometry::EVertexLayout::P3N3, GLModel::Geometry::EIndexType::UINT }; + g.format = { GLModel::Geometry::EPrimitiveType::Triangles, GLModel::Geometry::EVertexLayout::P3N3 }; } #else for (GLVolume *volume : vols) diff --git a/src/slic3r/GUI/GLModel.cpp b/src/slic3r/GUI/GLModel.cpp index d659e66a0..af650875b 100644 --- a/src/slic3r/GUI/GLModel.cpp +++ b/src/slic3r/GUI/GLModel.cpp @@ -59,16 +59,6 @@ static void smooth_normals_corner(const TriangleMesh& mesh, std::vector::iterator it = vertices.begin() + id * stride; + const size_t stride = vertex_stride_floats(format); + std::vector::const_iterator it = vertices.begin() + id * stride; vertices.erase(it, it + stride); } } @@ -402,21 +311,17 @@ size_t GLModel::Geometry::tex_coord_offset_floats(const Format& format) }; } -size_t GLModel::Geometry::index_stride_bytes(const Format& format) +size_t GLModel::Geometry::index_stride_bytes(const Geometry& data) { - switch (format.index_type) + switch (data.index_type) { case EIndexType::UINT: { return sizeof(unsigned int); } case EIndexType::USHORT: { return sizeof(unsigned short); } + case EIndexType::UBYTE: { return sizeof(unsigned char); } default: { assert(false); return 0; } }; } -GLModel::Geometry::EIndexType GLModel::Geometry::index_type(size_t vertices_count) -{ - return (vertices_count < 65536) ? EIndexType::USHORT : EIndexType::UINT; -} - bool GLModel::Geometry::has_position(const Format& format) { switch (format.vertex_layout) @@ -616,7 +521,7 @@ void GLModel::init_from(const indexed_triangle_set& its, const BoundingBoxf3 &bb } Geometry& data = m_render_data.geometry; - data.format = { Geometry::EPrimitiveType::Triangles, Geometry::EVertexLayout::P3N3, GLModel::Geometry::index_type(3 * its.indices.size()) }; + data.format = { Geometry::EPrimitiveType::Triangles, Geometry::EVertexLayout::P3N3 }; data.reserve_vertices(3 * its.indices.size()); data.reserve_indices(3 * its.indices.size()); @@ -630,10 +535,7 @@ void GLModel::init_from(const indexed_triangle_set& its, const BoundingBoxf3 &bb data.add_vertex(vertex[j], n); } vertices_counter += 3; - if (data.format.index_type == GLModel::Geometry::EIndexType::USHORT) - data.add_ushort_triangle((unsigned short)vertices_counter - 3, (unsigned short)vertices_counter - 2, (unsigned short)vertices_counter - 1); - else - data.add_uint_triangle(vertices_counter - 3, vertices_counter - 2, vertices_counter - 1); + data.add_triangle(vertices_counter - 3, vertices_counter - 2, vertices_counter - 1); } // update bounding box @@ -695,7 +597,7 @@ void GLModel::init_from(const Polygons& polygons, float z) } Geometry& data = m_render_data.geometry; - data.format = { Geometry::EPrimitiveType::Lines, Geometry::EVertexLayout::P3, Geometry::EIndexType::UINT }; + data.format = { Geometry::EPrimitiveType::Lines, Geometry::EVertexLayout::P3 }; size_t segments_count = 0; for (const Polygon& polygon : polygons) { @@ -714,7 +616,7 @@ void GLModel::init_from(const Polygons& polygons, float z) data.add_vertex(Vec3f(unscale(p0.x()), unscale(p0.y()), z)); data.add_vertex(Vec3f(unscale(p1.x()), unscale(p1.y()), z)); vertices_counter += 2; - data.add_uint_line(vertices_counter - 2, vertices_counter - 1); + data.add_line(vertices_counter - 2, vertices_counter - 1); } } @@ -809,7 +711,7 @@ void GLModel::reset() m_render_data.vertices_count = 0; m_render_data.indices_count = 0; m_render_data.geometry.vertices = std::vector(); - m_render_data.geometry.indices = std::vector(); + m_render_data.geometry.indices = std::vector(); #else for (RenderData& data : m_render_data) { // release gpu memory @@ -841,13 +743,14 @@ static GLenum get_primitive_mode(const GLModel::Geometry::Format& format) } } -static GLenum get_index_type(const GLModel::Geometry::Format& format) +static GLenum get_index_type(const GLModel::Geometry& data) { - switch (format.index_type) + switch (data.index_type) { default: case GLModel::Geometry::EIndexType::UINT: { return GL_UNSIGNED_INT; } case GLModel::Geometry::EIndexType::USHORT: { return GL_UNSIGNED_SHORT; } + case GLModel::Geometry::EIndexType::UBYTE: { return GL_UNSIGNED_BYTE; } } } @@ -861,58 +764,6 @@ void GLModel::render() const #else GLShaderProgram* shader = wxGetApp().get_current_shader(); -//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ -//#if ENABLE_LEGACY_OPENGL_REMOVAL -// if (shader == nullptr) -// return; -// -// // sends data to gpu if not done yet -// if (m_render_data.vbo_id == 0 || m_render_data.ibo_id == 0) { -// if (m_render_data.geometry.vertices_count() > 0 && m_render_data.geometry.indices_count() > 0 && !send_to_gpu()) -// return; -// } -// -// const Geometry& data = m_render_data.geometry; -// -// const GLenum mode = get_primitive_mode(data.format); -// const GLenum index_type = get_index_type(data.format); -// -// const size_t vertex_stride_bytes = Geometry::vertex_stride_bytes(data.format); -// const bool position = Geometry::has_position(data.format); -// const bool normal = Geometry::has_normal(data.format); -// const bool tex_coord = Geometry::has_tex_coord(data.format); -// -// glsafe(::glBindBuffer(GL_ARRAY_BUFFER, m_render_data.vbo_id)); -// -// if (position) { -// 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 (normal) { -// glsafe(::glNormalPointer(GL_FLOAT, vertex_stride_bytes, (const void*)Geometry::normal_offset_bytes(data.format))); -// glsafe(::glEnableClientState(GL_NORMAL_ARRAY)); -// } -// if (tex_coord) { -// 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)); -// } -// -// shader->set_uniform("uniform_color", data.color); -// -// glsafe(::glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_render_data.ibo_id)); -// glsafe(::glDrawElements(mode, indices_count(), index_type, nullptr)); -// glsafe(::glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0)); -// -// if (tex_coord) -// glsafe(::glDisableClientState(GL_TEXTURE_COORD_ARRAY)); -// if (normal) -// glsafe(::glDisableClientState(GL_NORMAL_ARRAY)); -// if (position) -// glsafe(::glDisableClientState(GL_VERTEX_ARRAY)); -// -// glsafe(::glBindBuffer(GL_ARRAY_BUFFER, 0)); -//#else -//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ for (const RenderData& data : m_render_data) { if (data.vbo_id == 0 || data.ibo_id == 0) continue; @@ -948,9 +799,6 @@ void GLModel::render() const glsafe(::glBindBuffer(GL_ARRAY_BUFFER, 0)); } -//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ -//#endif // ENABLE_LEGACY_OPENGL_REMOVAL -//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ #endif // ENABLE_LEGACY_OPENGL_REMOVAL } @@ -976,7 +824,7 @@ void GLModel::render(const std::pair& range) const Geometry& data = m_render_data.geometry; const GLenum mode = get_primitive_mode(data.format); - const GLenum index_type = get_index_type(data.format); + const GLenum index_type = get_index_type(data); const size_t vertex_stride_bytes = Geometry::vertex_stride_bytes(data.format); const bool position = Geometry::has_position(data.format); @@ -1031,7 +879,7 @@ void GLModel::render(const std::pair& range) shader->set_uniform("uniform_color", data.color); glsafe(::glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_render_data.ibo_id)); - glsafe(::glDrawElements(mode, range.second - range.first, index_type, (const void*)(range.first * Geometry::index_stride_bytes(data.format)))); + glsafe(::glDrawElements(mode, range.second - range.first, index_type, (const void*)(range.first * Geometry::index_stride_bytes(data)))); glsafe(::glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0)); #if ENABLE_GL_SHADERS_ATTRIBUTES @@ -1073,14 +921,14 @@ void GLModel::render_instanced(unsigned int instances_vbo, unsigned int instance return; // vertex attributes - GLint position_id = shader->get_attrib_location("v_position"); - GLint normal_id = shader->get_attrib_location("v_normal"); + const GLint position_id = shader->get_attrib_location("v_position"); + const GLint normal_id = shader->get_attrib_location("v_normal"); if (position_id == -1 || normal_id == -1) return; // instance attributes - GLint offset_id = shader->get_attrib_location("i_offset"); - GLint scales_id = shader->get_attrib_location("i_scales"); + const GLint offset_id = shader->get_attrib_location("i_offset"); + const GLint scales_id = shader->get_attrib_location("i_scales"); if (offset_id == -1 || scales_id == -1) return; @@ -1127,8 +975,8 @@ void GLModel::render_instanced(unsigned int instances_vbo, unsigned int instance #if ENABLE_LEGACY_OPENGL_REMOVAL const Geometry& data = m_render_data.geometry; - GLenum mode = get_primitive_mode(data.format); - GLenum index_type = get_index_type(data.format); + const GLenum mode = get_primitive_mode(data.format); + const GLenum index_type = get_index_type(data); shader->set_uniform("uniform_color", data.color); @@ -1233,10 +1081,32 @@ bool GLModel::send_to_gpu() // indices glsafe(::glGenBuffers(1, &m_render_data.ibo_id)); glsafe(::glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_render_data.ibo_id)); - glsafe(::glBufferData(GL_ELEMENT_ARRAY_BUFFER, data.indices_size_bytes(), data.indices.data(), GL_STATIC_DRAW)); - glsafe(::glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0)); + if (m_render_data.vertices_count <= 256) { + // convert indices to unsigned char to save gpu memory + std::vector reduced_indices(data.indices.size()); + for (size_t i = 0; i < data.indices.size(); ++i) { + reduced_indices[i] = (unsigned char)data.indices[i]; + } + data.index_type = Geometry::EIndexType::UBYTE; + glsafe(::glBufferData(GL_ELEMENT_ARRAY_BUFFER, reduced_indices.size() * sizeof(unsigned char), reduced_indices.data(), GL_STATIC_DRAW)); + glsafe(::glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0)); + } + else if (m_render_data.vertices_count <= 65536) { + // convert indices to unsigned short to save gpu memory + std::vector reduced_indices(data.indices.size()); + for (size_t i = 0; i < data.indices.size(); ++i) { + reduced_indices[i] = (unsigned short)data.indices[i]; + } + data.index_type = Geometry::EIndexType::USHORT; + glsafe(::glBufferData(GL_ELEMENT_ARRAY_BUFFER, reduced_indices.size() * sizeof(unsigned short), reduced_indices.data(), GL_STATIC_DRAW)); + glsafe(::glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0)); + } + else { + glsafe(::glBufferData(GL_ELEMENT_ARRAY_BUFFER, data.indices_size_bytes(), data.indices.data(), GL_STATIC_DRAW)); + glsafe(::glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0)); + } m_render_data.indices_count = indices_count(); - data.indices = std::vector(); + data.indices = std::vector(); return true; } @@ -1260,20 +1130,6 @@ void GLModel::send_to_gpu(RenderData& data, const std::vector& vertices, } #endif // ENABLE_LEGACY_OPENGL_REMOVAL -#if ENABLE_LEGACY_OPENGL_REMOVAL -static void append_vertex(GLModel::Geometry& data, const Vec3f& position, const Vec3f& normal) -{ - data.add_vertex(position, normal); -} - -static void append_triangle(GLModel::Geometry& data, unsigned short v1, unsigned short v2, unsigned short v3) -{ - data.add_ushort_index(v1); - data.add_ushort_index(v2); - data.add_ushort_index(v3); -} -#endif // ENABLE_LEGACY_OPENGL_REMOVAL - #if ENABLE_LEGACY_OPENGL_REMOVAL template inline bool all_vertices_inside(const GLModel::Geometry& geometry, Fn fn) @@ -1330,7 +1186,7 @@ bool contains(const BuildVolume& volume, const GLModel& model, bool ignore_botto } #endif // ENABLE_LEGACY_OPENGL_REMOVAL -GLModel::Geometry stilized_arrow(unsigned short resolution, float tip_radius, float tip_height, float stem_radius, float stem_height) +GLModel::Geometry stilized_arrow(unsigned int resolution, float tip_radius, float tip_height, float stem_radius, float stem_height) { #if !ENABLE_LEGACY_OPENGL_REMOVAL auto append_vertex = [](GLModel::Geometry::Entity& entity, const Vec3f& position, const Vec3f& normal) { @@ -1344,14 +1200,11 @@ GLModel::Geometry stilized_arrow(unsigned short resolution, float tip_radius, fl }; #endif // !ENABLE_LEGACY_OPENGL_REMOVAL - resolution = std::max(4, resolution); -#if ENABLE_LEGACY_OPENGL_REMOVAL - resolution = std::min(10922, resolution); // ensure no unsigned short overflow of indices -#endif // ENABLE_LEGACY_OPENGL_REMOVAL + resolution = std::max(4, resolution); GLModel::Geometry data; #if ENABLE_LEGACY_OPENGL_REMOVAL - data.format = { GLModel::Geometry::EPrimitiveType::Triangles, GLModel::Geometry::EVertexLayout::P3N3, GLModel::Geometry::EIndexType::USHORT }; + data.format = { GLModel::Geometry::EPrimitiveType::Triangles, GLModel::Geometry::EVertexLayout::P3N3 }; data.reserve_vertices(6 * resolution + 2); data.reserve_indices(6 * resolution * 3); #else @@ -1363,7 +1216,7 @@ GLModel::Geometry stilized_arrow(unsigned short resolution, float tip_radius, fl std::vector cosines(resolution); std::vector sines(resolution); - for (unsigned short i = 0; i < resolution; ++i) { + for (unsigned int i = 0; i < resolution; ++i) { const float angle = angle_step * float(i); cosines[i] = ::cos(angle); sines[i] = -::sin(angle); @@ -1373,63 +1226,63 @@ GLModel::Geometry stilized_arrow(unsigned short resolution, float tip_radius, fl // tip vertices/normals #if ENABLE_LEGACY_OPENGL_REMOVAL - append_vertex(data, { 0.0f, 0.0f, total_height }, Vec3f::UnitZ()); - for (unsigned short i = 0; i < resolution; ++i) { - append_vertex(data, { tip_radius * sines[i], tip_radius * cosines[i], stem_height }, { sines[i], cosines[i], 0.0f }); + data.add_vertex(Vec3f(0.0f, 0.0f, total_height), (Vec3f)Vec3f::UnitZ()); + for (unsigned int i = 0; i < resolution; ++i) { + data.add_vertex(Vec3f(tip_radius * sines[i], tip_radius * cosines[i], stem_height), Vec3f(sines[i], cosines[i], 0.0f)); } // tip triangles - for (unsigned short i = 0; i < resolution; ++i) { - const unsigned short v3 = (i < resolution - 1) ? i + 2 : 1; - append_triangle(data, 0, i + 1, v3); + for (unsigned int i = 0; i < resolution; ++i) { + const unsigned int v3 = (i < resolution - 1) ? i + 2 : 1; + data.add_triangle(0, i + 1, v3); } // tip cap outer perimeter vertices - for (unsigned short i = 0; i < resolution; ++i) { - append_vertex(data, { tip_radius * sines[i], tip_radius * cosines[i], stem_height }, -Vec3f::UnitZ()); + for (unsigned int i = 0; i < resolution; ++i) { + data.add_vertex(Vec3f(tip_radius * sines[i], tip_radius * cosines[i], stem_height), (Vec3f)(-Vec3f::UnitZ())); } // tip cap inner perimeter vertices - for (unsigned short i = 0; i < resolution; ++i) { - append_vertex(data, { stem_radius * sines[i], stem_radius * cosines[i], stem_height }, -Vec3f::UnitZ()); + for (unsigned int i = 0; i < resolution; ++i) { + data.add_vertex(Vec3f(stem_radius * sines[i], stem_radius * cosines[i], stem_height), (Vec3f)(-Vec3f::UnitZ())); } // tip cap triangles - for (unsigned short i = 0; i < resolution; ++i) { - const unsigned short v2 = (i < resolution - 1) ? i + resolution + 2 : resolution + 1; - const unsigned short v3 = (i < resolution - 1) ? i + 2 * resolution + 2 : 2 * resolution + 1; - append_triangle(data, i + resolution + 1, v3, v2); - append_triangle(data, i + resolution + 1, i + 2 * resolution + 1, v3); + for (unsigned int i = 0; i < resolution; ++i) { + const unsigned int v2 = (i < resolution - 1) ? i + resolution + 2 : resolution + 1; + const unsigned int v3 = (i < resolution - 1) ? i + 2 * resolution + 2 : 2 * resolution + 1; + data.add_triangle(i + resolution + 1, v3, v2); + data.add_triangle(i + resolution + 1, i + 2 * resolution + 1, v3); } // stem bottom vertices - for (unsigned short i = 0; i < resolution; ++i) { - append_vertex(data, { stem_radius * sines[i], stem_radius * cosines[i], stem_height }, { sines[i], cosines[i], 0.0f }); + for (unsigned int i = 0; i < resolution; ++i) { + data.add_vertex(Vec3f(stem_radius * sines[i], stem_radius * cosines[i], stem_height), Vec3f(sines[i], cosines[i], 0.0f)); } // stem top vertices - for (unsigned short i = 0; i < resolution; ++i) { - append_vertex(data, { stem_radius * sines[i], stem_radius * cosines[i], 0.0f }, { sines[i], cosines[i], 0.0f }); + for (unsigned int i = 0; i < resolution; ++i) { + data.add_vertex(Vec3f(stem_radius * sines[i], stem_radius * cosines[i], 0.0f), Vec3f(sines[i], cosines[i], 0.0f)); } // stem triangles - for (unsigned short i = 0; i < resolution; ++i) { - const unsigned short v2 = (i < resolution - 1) ? i + 3 * resolution + 2 : 3 * resolution + 1; - const unsigned short v3 = (i < resolution - 1) ? i + 4 * resolution + 2 : 4 * resolution + 1; - append_triangle(data, i + 3 * resolution + 1, v3, v2); - append_triangle(data, i + 3 * resolution + 1, i + 4 * resolution + 1, v3); + for (unsigned int i = 0; i < resolution; ++i) { + const unsigned int v2 = (i < resolution - 1) ? i + 3 * resolution + 2 : 3 * resolution + 1; + const unsigned int v3 = (i < resolution - 1) ? i + 4 * resolution + 2 : 4 * resolution + 1; + data.add_triangle(i + 3 * resolution + 1, v3, v2); + data.add_triangle(i + 3 * resolution + 1, i + 4 * resolution + 1, v3); } // stem cap vertices - append_vertex(data, Vec3f::Zero(), -Vec3f::UnitZ()); - for (unsigned short i = 0; i < resolution; ++i) { - append_vertex(data, { stem_radius * sines[i], stem_radius * cosines[i], 0.0f }, -Vec3f::UnitZ()); + data.add_vertex((Vec3f)Vec3f::Zero(), (Vec3f)(-Vec3f::UnitZ())); + for (unsigned int i = 0; i < resolution; ++i) { + data.add_vertex(Vec3f(stem_radius * sines[i], stem_radius * cosines[i], 0.0f), (Vec3f)(-Vec3f::UnitZ())); } // stem cap triangles - for (unsigned short i = 0; i < resolution; ++i) { - const unsigned short v3 = (i < resolution - 1) ? i + 5 * resolution + 3 : 5 * resolution + 2; - append_triangle(data, 5 * resolution + 1, v3, i + 5 * resolution + 2); + for (unsigned int i = 0; i < resolution; ++i) { + const unsigned int v3 = (i < resolution - 1) ? i + 5 * resolution + 3 : 5 * resolution + 2; + data.add_triangle(5 * resolution + 1, v3, i + 5 * resolution + 2); } #else append_vertex(entity, { 0.0f, 0.0f, total_height }, Vec3f::UnitZ()); @@ -1497,7 +1350,7 @@ GLModel::Geometry stilized_arrow(unsigned short resolution, float tip_radius, fl return data; } -GLModel::Geometry circular_arrow(unsigned short resolution, float radius, float tip_height, float tip_width, float stem_width, float thickness) +GLModel::Geometry circular_arrow(unsigned int resolution, float radius, float tip_height, float tip_width, float stem_width, float thickness) { #if !ENABLE_LEGACY_OPENGL_REMOVAL auto append_vertex = [](GLModel::Geometry::Entity& entity, const Vec3f& position, const Vec3f& normal) { @@ -1511,14 +1364,11 @@ GLModel::Geometry circular_arrow(unsigned short resolution, float radius, float }; #endif // !ENABLE_LEGACY_OPENGL_REMOVAL - resolution = std::max(2, resolution); -#if ENABLE_LEGACY_OPENGL_REMOVAL - resolution = std::min(8188, resolution); // ensure no unsigned short overflow of indices -#endif // ENABLE_LEGACY_OPENGL_REMOVAL + resolution = std::max(2, resolution); GLModel::Geometry data; #if ENABLE_LEGACY_OPENGL_REMOVAL - data.format = { GLModel::Geometry::EPrimitiveType::Triangles, GLModel::Geometry::EVertexLayout::P3N3, GLModel::Geometry::EIndexType::USHORT }; + data.format = { GLModel::Geometry::EPrimitiveType::Triangles, GLModel::Geometry::EVertexLayout::P3N3 }; data.reserve_vertices(8 * (resolution + 1) + 30); data.reserve_indices((8 * resolution + 16) * 3); #else @@ -1537,146 +1387,146 @@ GLModel::Geometry circular_arrow(unsigned short resolution, float radius, float #if ENABLE_LEGACY_OPENGL_REMOVAL // tip // top face vertices - append_vertex(data, { 0.0f, outer_radius, half_thickness }, Vec3f::UnitZ()); - append_vertex(data, { 0.0f, radius + half_tip_width, half_thickness }, Vec3f::UnitZ()); - append_vertex(data, { -tip_height, radius, half_thickness }, Vec3f::UnitZ()); - append_vertex(data, { 0.0f, radius - half_tip_width, half_thickness }, Vec3f::UnitZ()); - append_vertex(data, { 0.0f, inner_radius, half_thickness }, Vec3f::UnitZ()); + data.add_vertex(Vec3f(0.0f, outer_radius, half_thickness), (Vec3f)Vec3f::UnitZ()); + data.add_vertex(Vec3f(0.0f, radius + half_tip_width, half_thickness), (Vec3f)Vec3f::UnitZ()); + data.add_vertex(Vec3f(-tip_height, radius, half_thickness), (Vec3f)Vec3f::UnitZ()); + data.add_vertex(Vec3f(0.0f, radius - half_tip_width, half_thickness), (Vec3f)Vec3f::UnitZ()); + data.add_vertex(Vec3f(0.0f, inner_radius, half_thickness), (Vec3f)Vec3f::UnitZ()); // top face triangles - append_triangle(data, 0, 1, 2); - append_triangle(data, 0, 2, 4); - append_triangle(data, 4, 2, 3); + data.add_triangle(0, 1, 2); + data.add_triangle(0, 2, 4); + data.add_triangle(4, 2, 3); // bottom face vertices - append_vertex(data, { 0.0f, outer_radius, -half_thickness }, -Vec3f::UnitZ()); - append_vertex(data, { 0.0f, radius + half_tip_width, -half_thickness }, -Vec3f::UnitZ()); - append_vertex(data, { -tip_height, radius, -half_thickness }, -Vec3f::UnitZ()); - append_vertex(data, { 0.0f, radius - half_tip_width, -half_thickness }, -Vec3f::UnitZ()); - append_vertex(data, { 0.0f, inner_radius, -half_thickness }, -Vec3f::UnitZ()); + data.add_vertex(Vec3f(0.0f, outer_radius, -half_thickness), (Vec3f)(-Vec3f::UnitZ())); + data.add_vertex(Vec3f(0.0f, radius + half_tip_width, -half_thickness), (Vec3f)(-Vec3f::UnitZ())); + data.add_vertex(Vec3f(-tip_height, radius, -half_thickness), (Vec3f)(-Vec3f::UnitZ())); + data.add_vertex(Vec3f(0.0f, radius - half_tip_width, -half_thickness), (Vec3f)(-Vec3f::UnitZ())); + data.add_vertex(Vec3f(0.0f, inner_radius, -half_thickness), (Vec3f)(-Vec3f::UnitZ())); // bottom face triangles - append_triangle(data, 5, 7, 6); - append_triangle(data, 5, 9, 7); - append_triangle(data, 9, 8, 7); + data.add_triangle(5, 7, 6); + data.add_triangle(5, 9, 7); + data.add_triangle(9, 8, 7); // side faces vertices - append_vertex(data, { 0.0f, outer_radius, -half_thickness }, Vec3f::UnitX()); - append_vertex(data, { 0.0f, radius + half_tip_width, -half_thickness }, Vec3f::UnitX()); - append_vertex(data, { 0.0f, outer_radius, half_thickness }, Vec3f::UnitX()); - append_vertex(data, { 0.0f, radius + half_tip_width, half_thickness }, Vec3f::UnitX()); + data.add_vertex(Vec3f(0.0f, outer_radius, -half_thickness), (Vec3f)Vec3f::UnitX()); + data.add_vertex(Vec3f(0.0f, radius + half_tip_width, -half_thickness), (Vec3f)Vec3f::UnitX()); + data.add_vertex(Vec3f(0.0f, outer_radius, half_thickness), (Vec3f)Vec3f::UnitX()); + data.add_vertex(Vec3f(0.0f, radius + half_tip_width, half_thickness), (Vec3f)Vec3f::UnitX()); Vec3f normal(-half_tip_width, tip_height, 0.0f); normal.normalize(); - append_vertex(data, { 0.0f, radius + half_tip_width, -half_thickness }, normal); - append_vertex(data, { -tip_height, radius, -half_thickness }, normal); - append_vertex(data, { 0.0f, radius + half_tip_width, half_thickness }, normal); - append_vertex(data, { -tip_height, radius, half_thickness }, normal); + data.add_vertex(Vec3f(0.0f, radius + half_tip_width, -half_thickness), normal); + data.add_vertex(Vec3f(-tip_height, radius, -half_thickness), normal); + data.add_vertex(Vec3f(0.0f, radius + half_tip_width, half_thickness), normal); + data.add_vertex(Vec3f(-tip_height, radius, half_thickness), normal); normal = { -half_tip_width, -tip_height, 0.0f }; normal.normalize(); - append_vertex(data, { -tip_height, radius, -half_thickness }, normal); - append_vertex(data, { 0.0f, radius - half_tip_width, -half_thickness }, normal); - append_vertex(data, { -tip_height, radius, half_thickness }, normal); - append_vertex(data, { 0.0f, radius - half_tip_width, half_thickness }, normal); + data.add_vertex(Vec3f(-tip_height, radius, -half_thickness), normal); + data.add_vertex(Vec3f(0.0f, radius - half_tip_width, -half_thickness), normal); + data.add_vertex(Vec3f(-tip_height, radius, half_thickness), normal); + data.add_vertex(Vec3f(0.0f, radius - half_tip_width, half_thickness), normal); - append_vertex(data, { 0.0f, radius - half_tip_width, -half_thickness }, Vec3f::UnitX()); - append_vertex(data, { 0.0f, inner_radius, -half_thickness }, Vec3f::UnitX()); - append_vertex(data, { 0.0f, radius - half_tip_width, half_thickness }, Vec3f::UnitX()); - append_vertex(data, { 0.0f, inner_radius, half_thickness }, Vec3f::UnitX()); + data.add_vertex(Vec3f(0.0f, radius - half_tip_width, -half_thickness), (Vec3f)Vec3f::UnitX()); + data.add_vertex(Vec3f(0.0f, inner_radius, -half_thickness), (Vec3f)Vec3f::UnitX()); + data.add_vertex(Vec3f(0.0f, radius - half_tip_width, half_thickness), (Vec3f)Vec3f::UnitX()); + data.add_vertex(Vec3f(0.0f, inner_radius, half_thickness), (Vec3f)Vec3f::UnitX()); // side face triangles - for (unsigned short i = 0; i < 4; ++i) { - const unsigned short ii = i * 4; - append_triangle(data, 10 + ii, 11 + ii, 13 + ii); - append_triangle(data, 10 + ii, 13 + ii, 12 + ii); + for (unsigned int i = 0; i < 4; ++i) { + const unsigned int ii = i * 4; + data.add_triangle(10 + ii, 11 + ii, 13 + ii); + data.add_triangle(10 + ii, 13 + ii, 12 + ii); } // stem // top face vertices - for (unsigned short i = 0; i <= resolution; ++i) { + for (unsigned int i = 0; i <= resolution; ++i) { const float angle = float(i) * step_angle; - append_vertex(data, { inner_radius * ::sin(angle), inner_radius * ::cos(angle), half_thickness }, Vec3f::UnitZ()); + data.add_vertex(Vec3f(inner_radius * ::sin(angle), inner_radius * ::cos(angle), half_thickness), (Vec3f)Vec3f::UnitZ()); } - for (unsigned short i = 0; i <= resolution; ++i) { + for (unsigned int i = 0; i <= resolution; ++i) { const float angle = float(i) * step_angle; - append_vertex(data, { outer_radius * ::sin(angle), outer_radius * ::cos(angle), half_thickness }, Vec3f::UnitZ()); + data.add_vertex(Vec3f(outer_radius * ::sin(angle), outer_radius * ::cos(angle), half_thickness), (Vec3f)Vec3f::UnitZ()); } // top face triangles - for (unsigned short i = 0; i < resolution; ++i) { - append_triangle(data, 26 + i, 27 + i, 27 + resolution + i); - append_triangle(data, 27 + i, 28 + resolution + i, 27 + resolution + i); + for (unsigned int i = 0; i < resolution; ++i) { + data.add_triangle(26 + i, 27 + i, 27 + resolution + i); + data.add_triangle(27 + i, 28 + resolution + i, 27 + resolution + i); } // bottom face vertices - for (unsigned short i = 0; i <= resolution; ++i) { + for (unsigned int i = 0; i <= resolution; ++i) { const float angle = float(i) * step_angle; - append_vertex(data, { inner_radius * ::sin(angle), inner_radius * ::cos(angle), -half_thickness }, -Vec3f::UnitZ()); + data.add_vertex(Vec3f(inner_radius * ::sin(angle), inner_radius * ::cos(angle), -half_thickness), (Vec3f)(-Vec3f::UnitZ())); } - for (unsigned short i = 0; i <= resolution; ++i) { + for (unsigned int i = 0; i <= resolution; ++i) { const float angle = float(i) * step_angle; - append_vertex(data, { outer_radius * ::sin(angle), outer_radius * ::cos(angle), -half_thickness }, -Vec3f::UnitZ()); + data.add_vertex(Vec3f(outer_radius * ::sin(angle), outer_radius * ::cos(angle), -half_thickness), (Vec3f)(-Vec3f::UnitZ())); } // bottom face triangles - for (unsigned short i = 0; i < resolution; ++i) { - append_triangle(data, 28 + 2 * resolution + i, 29 + 3 * resolution + i, 29 + 2 * resolution + i); - append_triangle(data, 29 + 2 * resolution + i, 29 + 3 * resolution + i, 30 + 3 * resolution + i); + for (unsigned int i = 0; i < resolution; ++i) { + data.add_triangle(28 + 2 * resolution + i, 29 + 3 * resolution + i, 29 + 2 * resolution + i); + data.add_triangle(29 + 2 * resolution + i, 29 + 3 * resolution + i, 30 + 3 * resolution + i); } // side faces vertices and triangles - for (unsigned short i = 0; i <= resolution; ++i) { + for (unsigned int i = 0; i <= resolution; ++i) { const float angle = float(i) * step_angle; const float c = ::cos(angle); const float s = ::sin(angle); - append_vertex(data, { inner_radius * s, inner_radius * c, -half_thickness }, { -s, -c, 0.0f }); + data.add_vertex(Vec3f(inner_radius * s, inner_radius * c, -half_thickness), Vec3f(-s, -c, 0.0f)); } - for (unsigned short i = 0; i <= resolution; ++i) { + for (unsigned int i = 0; i <= resolution; ++i) { const float angle = float(i) * step_angle; const float c = ::cos(angle); const float s = ::sin(angle); - append_vertex(data, { inner_radius * s, inner_radius * c, half_thickness }, { -s, -c, 0.0f }); + data.add_vertex(Vec3f(inner_radius * s, inner_radius * c, half_thickness), Vec3f(-s, -c, 0.0f)); } - unsigned short first_id = 26 + 4 * (resolution + 1); - for (unsigned short i = 0; i < resolution; ++i) { - const unsigned short ii = first_id + i; - append_triangle(data, ii, ii + 1, ii + resolution + 2); - append_triangle(data, ii, ii + resolution + 2, ii + resolution + 1); + unsigned int first_id = 26 + 4 * (resolution + 1); + for (unsigned int i = 0; i < resolution; ++i) { + const unsigned int ii = first_id + i; + data.add_triangle(ii, ii + 1, ii + resolution + 2); + data.add_triangle(ii, ii + resolution + 2, ii + resolution + 1); } - append_vertex(data, { inner_radius, 0.0f, -half_thickness }, -Vec3f::UnitY()); - append_vertex(data, { outer_radius, 0.0f, -half_thickness }, -Vec3f::UnitY()); - append_vertex(data, { inner_radius, 0.0f, half_thickness }, -Vec3f::UnitY()); - append_vertex(data, { outer_radius, 0.0f, half_thickness }, -Vec3f::UnitY()); + data.add_vertex(Vec3f(inner_radius, 0.0f, -half_thickness), (Vec3f)(-Vec3f::UnitY())); + data.add_vertex(Vec3f(outer_radius, 0.0f, -half_thickness), (Vec3f)(-Vec3f::UnitY())); + data.add_vertex(Vec3f(inner_radius, 0.0f, half_thickness), (Vec3f)(-Vec3f::UnitY())); + data.add_vertex(Vec3f(outer_radius, 0.0f, half_thickness), (Vec3f)(-Vec3f::UnitY())); first_id = 26 + 6 * (resolution + 1); - append_triangle(data, first_id, first_id + 1, first_id + 3); - append_triangle(data, first_id, first_id + 3, first_id + 2); + data.add_triangle(first_id, first_id + 1, first_id + 3); + data.add_triangle(first_id, first_id + 3, first_id + 2); - for (short i = resolution; i >= 0; --i) { + for (int i = resolution; i >= 0; --i) { const float angle = float(i) * step_angle; const float c = ::cos(angle); const float s = ::sin(angle); - append_vertex(data, { outer_radius * s, outer_radius * c, -half_thickness }, { s, c, 0.0f }); + data.add_vertex(Vec3f(outer_radius * s, outer_radius * c, -half_thickness), Vec3f(s, c, 0.0f)); } - for (short i = resolution; i >= 0; --i) { + for (int i = resolution; i >= 0; --i) { const float angle = float(i) * step_angle; const float c = ::cos(angle); const float s = ::sin(angle); - append_vertex(data, { outer_radius * s, outer_radius * c, +half_thickness }, { s, c, 0.0f }); + data.add_vertex(Vec3f(outer_radius * s, outer_radius * c, +half_thickness), Vec3f(s, c, 0.0f)); } first_id = 30 + 6 * (resolution + 1); - for (unsigned short i = 0; i < resolution; ++i) { - const unsigned short ii = first_id + i; - append_triangle(data, ii, ii + 1, ii + resolution + 2); - append_triangle(data, ii, ii + resolution + 2, ii + resolution + 1); + for (unsigned int i = 0; i < resolution; ++i) { + const unsigned int ii = first_id + i; + data.add_triangle(ii, ii + 1, ii + resolution + 2); + data.add_triangle(ii, ii + resolution + 2, ii + resolution + 1); } #else // tip @@ -1845,7 +1695,7 @@ GLModel::Geometry straight_arrow(float tip_width, float tip_height, float stem_w GLModel::Geometry data; #if ENABLE_LEGACY_OPENGL_REMOVAL - data.format = { GLModel::Geometry::EPrimitiveType::Triangles, GLModel::Geometry::EVertexLayout::P3N3, GLModel::Geometry::EIndexType::USHORT }; + data.format = { GLModel::Geometry::EPrimitiveType::Triangles, GLModel::Geometry::EVertexLayout::P3N3 }; data.reserve_vertices(42); data.reserve_indices(72); #else @@ -1860,82 +1710,82 @@ GLModel::Geometry straight_arrow(float tip_width, float tip_height, float stem_w #if ENABLE_LEGACY_OPENGL_REMOVAL // top face vertices - append_vertex(data, { half_stem_width, 0.0, half_thickness }, Vec3f::UnitZ()); - append_vertex(data, { half_stem_width, stem_height, half_thickness }, Vec3f::UnitZ()); - append_vertex(data, { half_tip_width, stem_height, half_thickness }, Vec3f::UnitZ()); - append_vertex(data, { 0.0, total_height, half_thickness }, Vec3f::UnitZ()); - append_vertex(data, { -half_tip_width, stem_height, half_thickness }, Vec3f::UnitZ()); - append_vertex(data, { -half_stem_width, stem_height, half_thickness }, Vec3f::UnitZ()); - append_vertex(data, { -half_stem_width, 0.0, half_thickness }, Vec3f::UnitZ()); + data.add_vertex(Vec3f(half_stem_width, 0.0f, half_thickness), (Vec3f)Vec3f::UnitZ()); + data.add_vertex(Vec3f(half_stem_width, stem_height, half_thickness), (Vec3f)Vec3f::UnitZ()); + data.add_vertex(Vec3f(half_tip_width, stem_height, half_thickness), (Vec3f)Vec3f::UnitZ()); + data.add_vertex(Vec3f(0.0f, total_height, half_thickness), (Vec3f)Vec3f::UnitZ()); + data.add_vertex(Vec3f(-half_tip_width, stem_height, half_thickness), (Vec3f)Vec3f::UnitZ()); + data.add_vertex(Vec3f(-half_stem_width, stem_height, half_thickness), (Vec3f)Vec3f::UnitZ()); + data.add_vertex(Vec3f(-half_stem_width, 0.0f, half_thickness), (Vec3f)Vec3f::UnitZ()); // top face triangles - append_triangle(data, 0, 1, 6); - append_triangle(data, 6, 1, 5); - append_triangle(data, 4, 5, 3); - append_triangle(data, 5, 1, 3); - append_triangle(data, 1, 2, 3); + data.add_triangle(0, 1, 6); + data.add_triangle(6, 1, 5); + data.add_triangle(4, 5, 3); + data.add_triangle(5, 1, 3); + data.add_triangle(1, 2, 3); // bottom face vertices - append_vertex(data, { half_stem_width, 0.0, -half_thickness }, -Vec3f::UnitZ()); - append_vertex(data, { half_stem_width, stem_height, -half_thickness }, -Vec3f::UnitZ()); - append_vertex(data, { half_tip_width, stem_height, -half_thickness }, -Vec3f::UnitZ()); - append_vertex(data, { 0.0, total_height, -half_thickness }, -Vec3f::UnitZ()); - append_vertex(data, { -half_tip_width, stem_height, -half_thickness }, -Vec3f::UnitZ()); - append_vertex(data, { -half_stem_width, stem_height, -half_thickness }, -Vec3f::UnitZ()); - append_vertex(data, { -half_stem_width, 0.0, -half_thickness }, -Vec3f::UnitZ()); + data.add_vertex(Vec3f(half_stem_width, 0.0f, -half_thickness), (Vec3f)(-Vec3f::UnitZ())); + data.add_vertex(Vec3f(half_stem_width, stem_height, -half_thickness), (Vec3f)(-Vec3f::UnitZ())); + data.add_vertex(Vec3f(half_tip_width, stem_height, -half_thickness), (Vec3f)(-Vec3f::UnitZ())); + data.add_vertex(Vec3f(0.0f, total_height, -half_thickness), (Vec3f)(-Vec3f::UnitZ())); + data.add_vertex(Vec3f(-half_tip_width, stem_height, -half_thickness), (Vec3f)(-Vec3f::UnitZ())); + data.add_vertex(Vec3f(-half_stem_width, stem_height, -half_thickness), (Vec3f)(-Vec3f::UnitZ())); + data.add_vertex(Vec3f(-half_stem_width, 0.0f, -half_thickness), (Vec3f)(-Vec3f::UnitZ())); // bottom face triangles - append_triangle(data, 7, 13, 8); - append_triangle(data, 13, 12, 8); - append_triangle(data, 12, 11, 10); - append_triangle(data, 8, 12, 10); - append_triangle(data, 9, 8, 10); + data.add_triangle(7, 13, 8); + data.add_triangle(13, 12, 8); + data.add_triangle(12, 11, 10); + data.add_triangle(8, 12, 10); + data.add_triangle(9, 8, 10); // side faces vertices - append_vertex(data, { half_stem_width, 0.0, -half_thickness }, Vec3f::UnitX()); - append_vertex(data, { half_stem_width, stem_height, -half_thickness }, Vec3f::UnitX()); - append_vertex(data, { half_stem_width, 0.0, half_thickness }, Vec3f::UnitX()); - append_vertex(data, { half_stem_width, stem_height, half_thickness }, Vec3f::UnitX()); + data.add_vertex(Vec3f(half_stem_width, 0.0f, -half_thickness), (Vec3f)Vec3f::UnitX()); + data.add_vertex(Vec3f(half_stem_width, stem_height, -half_thickness), (Vec3f)Vec3f::UnitX()); + data.add_vertex(Vec3f(half_stem_width, 0.0f, half_thickness), (Vec3f)Vec3f::UnitX()); + data.add_vertex(Vec3f(half_stem_width, stem_height, half_thickness), (Vec3f)Vec3f::UnitX()); - append_vertex(data, { half_stem_width, stem_height, -half_thickness }, -Vec3f::UnitY()); - append_vertex(data, { half_tip_width, stem_height, -half_thickness }, -Vec3f::UnitY()); - append_vertex(data, { half_stem_width, stem_height, half_thickness }, -Vec3f::UnitY()); - append_vertex(data, { half_tip_width, stem_height, half_thickness }, -Vec3f::UnitY()); + data.add_vertex(Vec3f(half_stem_width, stem_height, -half_thickness), (Vec3f)(-Vec3f::UnitY())); + data.add_vertex(Vec3f(half_tip_width, stem_height, -half_thickness), (Vec3f)(-Vec3f::UnitY())); + data.add_vertex(Vec3f(half_stem_width, stem_height, half_thickness), (Vec3f)(-Vec3f::UnitY())); + data.add_vertex(Vec3f(half_tip_width, stem_height, half_thickness), (Vec3f)(-Vec3f::UnitY())); Vec3f normal(tip_height, half_tip_width, 0.0f); normal.normalize(); - append_vertex(data, { half_tip_width, stem_height, -half_thickness }, normal); - append_vertex(data, { 0.0, total_height, -half_thickness }, normal); - append_vertex(data, { half_tip_width, stem_height, half_thickness }, normal); - append_vertex(data, { 0.0, total_height, half_thickness }, normal); + data.add_vertex(Vec3f(half_tip_width, stem_height, -half_thickness), normal); + data.add_vertex(Vec3f(0.0f, total_height, -half_thickness), normal); + data.add_vertex(Vec3f(half_tip_width, stem_height, half_thickness), normal); + data.add_vertex(Vec3f(0.0f, total_height, half_thickness), normal); normal = { -tip_height, half_tip_width, 0.0f }; normal.normalize(); - append_vertex(data, { 0.0, total_height, -half_thickness }, normal); - append_vertex(data, { -half_tip_width, stem_height, -half_thickness }, normal); - append_vertex(data, { 0.0, total_height, half_thickness }, normal); - append_vertex(data, { -half_tip_width, stem_height, half_thickness }, normal); + data.add_vertex(Vec3f(0.0f, total_height, -half_thickness), normal); + data.add_vertex(Vec3f(-half_tip_width, stem_height, -half_thickness), normal); + data.add_vertex(Vec3f(0.0f, total_height, half_thickness), normal); + data.add_vertex(Vec3f(-half_tip_width, stem_height, half_thickness), normal); - append_vertex(data, { -half_tip_width, stem_height, -half_thickness }, -Vec3f::UnitY()); - append_vertex(data, { -half_stem_width, stem_height, -half_thickness }, -Vec3f::UnitY()); - append_vertex(data, { -half_tip_width, stem_height, half_thickness }, -Vec3f::UnitY()); - append_vertex(data, { -half_stem_width, stem_height, half_thickness }, -Vec3f::UnitY()); + data.add_vertex(Vec3f(-half_tip_width, stem_height, -half_thickness), (Vec3f)(-Vec3f::UnitY())); + data.add_vertex(Vec3f(-half_stem_width, stem_height, -half_thickness), (Vec3f)(-Vec3f::UnitY())); + data.add_vertex(Vec3f(-half_tip_width, stem_height, half_thickness), (Vec3f)(-Vec3f::UnitY())); + data.add_vertex(Vec3f(-half_stem_width, stem_height, half_thickness), (Vec3f)(-Vec3f::UnitY())); - append_vertex(data, { -half_stem_width, stem_height, -half_thickness }, -Vec3f::UnitX()); - append_vertex(data, { -half_stem_width, 0.0, -half_thickness }, -Vec3f::UnitX()); - append_vertex(data, { -half_stem_width, stem_height, half_thickness }, -Vec3f::UnitX()); - append_vertex(data, { -half_stem_width, 0.0, half_thickness }, -Vec3f::UnitX()); + data.add_vertex(Vec3f(-half_stem_width, stem_height, -half_thickness), (Vec3f)(-Vec3f::UnitX())); + data.add_vertex(Vec3f(-half_stem_width, 0.0f, -half_thickness), (Vec3f)(-Vec3f::UnitX())); + data.add_vertex(Vec3f(-half_stem_width, stem_height, half_thickness), (Vec3f)(-Vec3f::UnitX())); + data.add_vertex(Vec3f(-half_stem_width, 0.0f, half_thickness), (Vec3f)(-Vec3f::UnitX())); - append_vertex(data, { -half_stem_width, 0.0, -half_thickness }, -Vec3f::UnitY()); - append_vertex(data, { half_stem_width, 0.0, -half_thickness }, -Vec3f::UnitY()); - append_vertex(data, { -half_stem_width, 0.0, half_thickness }, -Vec3f::UnitY()); - append_vertex(data, { half_stem_width, 0.0, half_thickness }, -Vec3f::UnitY()); + data.add_vertex(Vec3f(-half_stem_width, 0.0f, -half_thickness), (Vec3f)(-Vec3f::UnitY())); + data.add_vertex(Vec3f(half_stem_width, 0.0f, -half_thickness), (Vec3f)(-Vec3f::UnitY())); + data.add_vertex(Vec3f(-half_stem_width, 0.0f, half_thickness), (Vec3f)(-Vec3f::UnitY())); + data.add_vertex(Vec3f(half_stem_width, 0.0f, half_thickness), (Vec3f)(-Vec3f::UnitY())); // side face triangles - for (unsigned short i = 0; i < 7; ++i) { - const unsigned short ii = i * 4; - append_triangle(data, 14 + ii, 15 + ii, 17 + ii); - append_triangle(data, 14 + ii, 17 + ii, 16 + ii); + for (unsigned int i = 0; i < 7; ++i) { + const unsigned int ii = i * 4; + data.add_triangle(14 + ii, 15 + ii, 17 + ii); + data.add_triangle(14 + ii, 17 + ii, 16 + ii); } #else // top face vertices @@ -2023,16 +1873,13 @@ GLModel::Geometry straight_arrow(float tip_width, float tip_height, float stem_w return data; } -GLModel::Geometry diamond(unsigned short resolution) +GLModel::Geometry diamond(unsigned int resolution) { - resolution = std::max(4, resolution); -#if ENABLE_LEGACY_OPENGL_REMOVAL - resolution = std::min(65534, resolution); // ensure no unsigned short overflow of indices -#endif // ENABLE_LEGACY_OPENGL_REMOVAL + resolution = std::max(4, resolution); GLModel::Geometry data; #if ENABLE_LEGACY_OPENGL_REMOVAL - data.format = { GLModel::Geometry::EPrimitiveType::Triangles, GLModel::Geometry::EVertexLayout::P3N3, GLModel::Geometry::EIndexType::USHORT }; + data.format = { GLModel::Geometry::EPrimitiveType::Triangles, GLModel::Geometry::EVertexLayout::P3N3 }; data.reserve_vertices(resolution + 2); data.reserve_indices((2 * (resolution + 1)) * 3); #else @@ -2044,28 +1891,28 @@ GLModel::Geometry diamond(unsigned short resolution) #if ENABLE_LEGACY_OPENGL_REMOVAL // vertices - for (unsigned short i = 0; i < resolution; ++i) { + for (unsigned int i = 0; i < resolution; ++i) { const float ii = float(i) * step; const Vec3f p = { 0.5f * ::cos(ii), 0.5f * ::sin(ii), 0.0f }; - append_vertex(data, p, p.normalized()); + data.add_vertex(p, (Vec3f)p.normalized()); } Vec3f p = { 0.0f, 0.0f, 0.5f }; - append_vertex(data, p, p.normalized()); + data.add_vertex(p, (Vec3f)p.normalized()); p = { 0.0f, 0.0f, -0.5f }; - append_vertex(data, p, p.normalized()); + data.add_vertex(p, (Vec3f)p.normalized()); // triangles // top - for (unsigned short i = 0; i < resolution; ++i) { - append_triangle(data, i + 0, i + 1, resolution); + for (unsigned int i = 0; i < resolution; ++i) { + data.add_triangle(i + 0, i + 1, resolution); } - append_triangle(data, resolution - 1, 0, resolution); + data.add_triangle(resolution - 1, 0, resolution); // bottom - for (unsigned short i = 0; i < resolution; ++i) { - append_triangle(data, i + 0, resolution + 1, i + 1); + for (unsigned int i = 0; i < resolution; ++i) { + data.add_triangle(i + 0, resolution + 1, i + 1); } - append_triangle(data, resolution - 1, resolution + 1, 0); + data.add_triangle(resolution - 1, resolution + 1, 0); #else // positions for (int i = 0; i < resolution; ++i) { @@ -2109,24 +1956,23 @@ GLModel::Geometry diamond(unsigned short resolution) #if ENABLE_LEGACY_OPENGL_REMOVAL #if ENABLE_SHOW_TOOLPATHS_COG -GLModel::Geometry smooth_sphere(unsigned short resolution, float radius) +GLModel::Geometry smooth_sphere(unsigned int resolution, float radius) { - resolution = std::max(4, resolution); - resolution = std::min(256, resolution); // ensure no unsigned short overflow of indices + resolution = std::max(4, resolution); - const unsigned short sectorCount = /*2 **/ resolution; - const unsigned short stackCount = resolution; + const unsigned int sectorCount = resolution; + const unsigned int stackCount = resolution; const float sectorStep = float(2.0 * M_PI / sectorCount); const float stackStep = float(M_PI / stackCount); GLModel::Geometry data; - data.format = { GLModel::Geometry::EPrimitiveType::Triangles, GLModel::Geometry::EVertexLayout::P3N3, GLModel::Geometry::EIndexType::USHORT }; + data.format = { GLModel::Geometry::EPrimitiveType::Triangles, GLModel::Geometry::EVertexLayout::P3N3 }; data.reserve_vertices((stackCount - 1) * sectorCount + 2); data.reserve_indices((2 * (stackCount - 1) * sectorCount) * 3); // vertices - for (unsigned short i = 0; i <= stackCount; ++i) { + for (unsigned int i = 0; i <= stackCount; ++i) { // from pi/2 to -pi/2 const double stackAngle = 0.5 * M_PI - stackStep * i; const double xy = double(radius) * ::cos(stackAngle); @@ -2136,7 +1982,7 @@ GLModel::Geometry smooth_sphere(unsigned short resolution, float radius) data.add_vertex(v, (Vec3f)v.normalized()); } else { - for (unsigned short j = 0; j < sectorCount; ++j) { + for (unsigned int j = 0; j < sectorCount; ++j) { // from 0 to 2pi const double sectorAngle = sectorStep * j; const Vec3f v(float(xy * std::cos(sectorAngle)), float(xy * std::sin(sectorAngle)), float(z)); @@ -2146,24 +1992,24 @@ GLModel::Geometry smooth_sphere(unsigned short resolution, float radius) } // triangles - for (unsigned short i = 0; i < stackCount; ++i) { + for (unsigned int i = 0; i < stackCount; ++i) { // Beginning of current stack. - unsigned short k1 = (i == 0) ? 0 : (1 + (i - 1) * sectorCount); - const unsigned short k1_first = k1; + unsigned int k1 = (i == 0) ? 0 : (1 + (i - 1) * sectorCount); + const unsigned int k1_first = k1; // Beginning of next stack. - unsigned short k2 = (i == 0) ? 1 : (k1 + sectorCount); - const unsigned short k2_first = k2; - for (unsigned short j = 0; j < sectorCount; ++j) { + unsigned int k2 = (i == 0) ? 1 : (k1 + sectorCount); + const unsigned int k2_first = k2; + for (unsigned int j = 0; j < sectorCount; ++j) { // 2 triangles per sector excluding first and last stacks - unsigned short k1_next = k1; - unsigned short k2_next = k2; + unsigned int k1_next = k1; + unsigned int k2_next = k2; if (i != 0) { k1_next = (j + 1 == sectorCount) ? k1_first : (k1 + 1); - data.add_ushort_triangle(k1, k2, k1_next); + data.add_triangle(k1, k2, k1_next); } if (i + 1 != stackCount) { k2_next = (j + 1 == sectorCount) ? k2_first : (k2 + 1); - data.add_ushort_triangle(k1_next, k2, k2_next); + data.add_triangle(k1_next, k2, k2_next); } k1 = k1_next; k2 = k2_next; diff --git a/src/slic3r/GUI/GLModel.hpp b/src/slic3r/GUI/GLModel.hpp index 0894cf853..e18d04678 100644 --- a/src/slic3r/GUI/GLModel.hpp +++ b/src/slic3r/GUI/GLModel.hpp @@ -68,23 +68,25 @@ namespace GUI { enum class EIndexType : unsigned char { UINT, // unsigned int - USHORT // unsigned short + USHORT, // unsigned short + UBYTE // unsigned byte }; struct Format { EPrimitiveType type{ EPrimitiveType::Triangles }; EVertexLayout vertex_layout{ EVertexLayout::P3N3 }; - EIndexType index_type{ EIndexType::UINT }; }; Format format; std::vector vertices; - std::vector indices; + std::vector indices; + EIndexType index_type{ EIndexType::UINT }; ColorRGBA color{ ColorRGBA::BLACK() }; - void reserve_vertices(size_t vertices_count); - void reserve_indices(size_t indices_count); + void reserve_vertices(size_t vertices_count) { vertices.reserve(vertices_count * vertex_stride_floats(format)); } + void reserve_indices(size_t indices_count) { indices.reserve(indices_count * index_stride_bytes(*this)); } + void add_vertex(const Vec2f& position); // EVertexLayout::P2 void add_vertex(const Vec2f& position, const Vec2f& tex_coord); // EVertexLayout::P2T2 @@ -94,36 +96,29 @@ namespace GUI { void set_vertex(size_t id, const Vec3f& position, const Vec3f& normal); // EVertexLayout::P3N3 - void set_ushort_index(size_t id, unsigned short index); - void set_uint_index(size_t id, unsigned int index); + void set_index(size_t id, unsigned int index); - void add_ushort_index(unsigned short id); - void add_uint_index(unsigned int id); - - void add_ushort_line(unsigned short id1, unsigned short id2); - void add_uint_line(unsigned int id1, unsigned int id2); - - void add_ushort_triangle(unsigned short id1, unsigned short id2, unsigned short id3); - void add_uint_triangle(unsigned int id1, unsigned int id2, unsigned int id3); + void add_index(unsigned int id); + void add_line(unsigned int id1, unsigned int id2); + void add_triangle(unsigned int id1, unsigned int id2, unsigned int id3); Vec2f extract_position_2(size_t id) const; Vec3f extract_position_3(size_t id) const; Vec3f extract_normal_3(size_t id) const; Vec2f extract_tex_coord_2(size_t id) const; - unsigned int extract_uint_index(size_t id) const; - unsigned short extract_ushort_index(size_t id) const; + unsigned int extract_index(size_t id) const; void remove_vertex(size_t id); bool is_empty() const { return vertices_count() == 0 || indices_count() == 0; } size_t vertices_count() const { return vertices.size() / vertex_stride_floats(format); } - size_t indices_count() const { return indices.size() / index_stride_bytes(format); } + size_t indices_count() const { return indices.size(); } size_t vertices_size_floats() const { return vertices.size(); } size_t vertices_size_bytes() const { return vertices_size_floats() * sizeof(float); } - size_t indices_size_bytes() const { return indices.size(); } + size_t indices_size_bytes() const { return indices.size() * index_stride_bytes(*this); } static size_t vertex_stride_floats(const Format& format); static size_t vertex_stride_bytes(const Format& format) { return vertex_stride_floats(format) * sizeof(float); } @@ -143,9 +138,7 @@ namespace GUI { static size_t tex_coord_offset_floats(const Format& format); static size_t tex_coord_offset_bytes(const Format& format) { return tex_coord_offset_floats(format) * sizeof(float); } - static size_t index_stride_bytes(const Format& format); - - static EIndexType index_type(size_t vertices_count); + static size_t index_stride_bytes(const Geometry& data); static bool has_position(const Format& format); static bool has_normal(const Format& format); @@ -213,7 +206,7 @@ namespace GUI { size_t vertices_size_floats() const { return vertices_count() * Geometry::vertex_stride_floats(m_render_data.geometry.format); } size_t vertices_size_bytes() const { return vertices_size_floats() * sizeof(float); } - size_t indices_size_bytes() const { return indices_count() * Geometry::index_stride_bytes(m_render_data.geometry.format); } + size_t indices_size_bytes() const { return indices_count() * Geometry::index_stride_bytes(m_render_data.geometry); } const Geometry& get_geometry() const { return m_render_data.geometry; } @@ -297,13 +290,13 @@ namespace GUI { // the origin of the arrow is in the center of the stem cap // the arrow has its axis of symmetry along the Z axis and is pointing upward // used to render bed axes and sequential marker - GLModel::Geometry stilized_arrow(unsigned short resolution, float tip_radius, float tip_height, float stem_radius, float stem_height); + GLModel::Geometry stilized_arrow(unsigned int resolution, float tip_radius, float tip_height, float stem_radius, float stem_height); // create an arrow whose stem is a quarter of circle, with the given dimensions and resolution // the origin of the arrow is in the center of the circle // the arrow is contained in the 1st quadrant of the XY plane and is pointing counterclockwise // used to render sidebar hints for rotations - GLModel::Geometry circular_arrow(unsigned short resolution, float radius, float tip_height, float tip_width, float stem_width, float thickness); + GLModel::Geometry circular_arrow(unsigned int resolution, float radius, float tip_height, float tip_width, float stem_width, float thickness); // create an arrow with the given dimensions // the origin of the arrow is in the center of the stem cap @@ -314,13 +307,13 @@ namespace GUI { // create a diamond with the given resolution // the origin of the diamond is in its center // the diamond is contained into a box with size [1, 1, 1] - GLModel::Geometry diamond(unsigned short resolution); + GLModel::Geometry diamond(unsigned int resolution); #if ENABLE_LEGACY_OPENGL_REMOVAL #if ENABLE_SHOW_TOOLPATHS_COG // create a sphere with the given resolution and smooth normals // the origin of the sphere is in its center - GLModel::Geometry smooth_sphere(unsigned short resolution, float radius); + GLModel::Geometry smooth_sphere(unsigned int resolution, float radius); #endif // ENABLE_SHOW_TOOLPATHS_COG #endif // ENABLE_LEGACY_OPENGL_REMOVAL diff --git a/src/slic3r/GUI/GLSelectionRectangle.cpp b/src/slic3r/GUI/GLSelectionRectangle.cpp index bbc66d711..2563939cf 100644 --- a/src/slic3r/GUI/GLSelectionRectangle.cpp +++ b/src/slic3r/GUI/GLSelectionRectangle.cpp @@ -145,7 +145,7 @@ namespace GUI { m_rectangle.reset(); GLModel::Geometry init_data; - init_data.format = { GLModel::Geometry::EPrimitiveType::LineLoop, GLModel::Geometry::EVertexLayout::P2, GLModel::Geometry::EIndexType::USHORT }; + init_data.format = { GLModel::Geometry::EPrimitiveType::LineLoop, GLModel::Geometry::EVertexLayout::P2 }; init_data.reserve_vertices(4); init_data.reserve_indices(4); @@ -156,10 +156,10 @@ namespace GUI { init_data.add_vertex(Vec2f(left, top)); // indices - init_data.add_ushort_index(0); - init_data.add_ushort_index(1); - init_data.add_ushort_index(2); - init_data.add_ushort_index(3); + init_data.add_index(0); + init_data.add_index(1); + init_data.add_index(2); + init_data.add_index(3); m_rectangle.init_from(std::move(init_data)); } diff --git a/src/slic3r/GUI/GLTexture.cpp b/src/slic3r/GUI/GLTexture.cpp index dc21fdde2..064ca1a18 100644 --- a/src/slic3r/GUI/GLTexture.cpp +++ b/src/slic3r/GUI/GLTexture.cpp @@ -341,7 +341,7 @@ void GLTexture::render_sub_texture(unsigned int tex_id, float left, float right, #if ENABLE_LEGACY_OPENGL_REMOVAL GLModel::Geometry init_data; - init_data.format = { GLModel::Geometry::EPrimitiveType::Triangles, GLModel::Geometry::EVertexLayout::P2T2, GLModel::Geometry::EIndexType::USHORT }; + init_data.format = { GLModel::Geometry::EPrimitiveType::Triangles, GLModel::Geometry::EVertexLayout::P2T2 }; init_data.reserve_vertices(4); init_data.reserve_indices(6); @@ -352,8 +352,8 @@ void GLTexture::render_sub_texture(unsigned int tex_id, float left, float right, init_data.add_vertex(Vec2f(left, top), Vec2f(uvs.left_top.u, uvs.left_top.v)); // indices - init_data.add_ushort_triangle(0, 1, 2); - init_data.add_ushort_triangle(2, 3, 0); + init_data.add_triangle(0, 1, 2); + init_data.add_triangle(2, 3, 0); GLModel model; model.init_from(std::move(init_data)); diff --git a/src/slic3r/GUI/Gizmos/GLGizmoCut.cpp b/src/slic3r/GUI/Gizmos/GLGizmoCut.cpp index c6d5259a0..5c9b08a93 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmoCut.cpp +++ b/src/slic3r/GUI/Gizmos/GLGizmoCut.cpp @@ -126,7 +126,7 @@ void GLGizmoCut::on_render() m_plane.reset(); GLModel::Geometry init_data; - init_data.format = { GLModel::Geometry::EPrimitiveType::Triangles, GLModel::Geometry::EVertexLayout::P3, GLModel::Geometry::EIndexType::USHORT }; + init_data.format = { GLModel::Geometry::EPrimitiveType::Triangles, GLModel::Geometry::EVertexLayout::P3 }; init_data.color = { 0.8f, 0.8f, 0.8f, 0.5f }; init_data.reserve_vertices(4); init_data.reserve_indices(6); @@ -138,8 +138,8 @@ void GLGizmoCut::on_render() init_data.add_vertex(Vec3f(min_x, max_y, plane_center.z())); // indices - init_data.add_ushort_triangle(0, 1, 2); - init_data.add_ushort_triangle(2, 3, 0); + init_data.add_triangle(0, 1, 2); + init_data.add_triangle(2, 3, 0); m_plane.init_from(std::move(init_data)); } @@ -177,7 +177,7 @@ void GLGizmoCut::on_render() m_grabber_connection.reset(); GLModel::Geometry init_data; - init_data.format = { GLModel::Geometry::EPrimitiveType::Lines, GLModel::Geometry::EVertexLayout::P3, GLModel::Geometry::EIndexType::USHORT }; + init_data.format = { GLModel::Geometry::EPrimitiveType::Lines, GLModel::Geometry::EVertexLayout::P3 }; init_data.color = ColorRGBA::YELLOW(); init_data.reserve_vertices(2); init_data.reserve_indices(2); @@ -187,7 +187,7 @@ void GLGizmoCut::on_render() init_data.add_vertex((Vec3f)m_grabbers[0].center.cast()); // indices - init_data.add_ushort_line(0, 1); + init_data.add_line(0, 1); m_grabber_connection.init_from(std::move(init_data)); } diff --git a/src/slic3r/GUI/Gizmos/GLGizmoFlatten.cpp b/src/slic3r/GUI/Gizmos/GLGizmoFlatten.cpp index 5ad8ba9d4..48c81bc5a 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmoFlatten.cpp +++ b/src/slic3r/GUI/Gizmos/GLGizmoFlatten.cpp @@ -429,16 +429,13 @@ void GLGizmoFlatten::update_planes() for (auto& plane : m_planes) { #if ENABLE_LEGACY_OPENGL_REMOVAL GLModel::Geometry init_data; - init_data.format = { GLModel::Geometry::EPrimitiveType::TriangleFan, GLModel::Geometry::EVertexLayout::P3N3, GLModel::Geometry::index_type(plane.vertices.size()) }; + init_data.format = { GLModel::Geometry::EPrimitiveType::TriangleFan, GLModel::Geometry::EVertexLayout::P3N3 }; init_data.reserve_vertices(plane.vertices.size()); init_data.reserve_indices(plane.vertices.size()); // vertices + indices for (size_t i = 0; i < plane.vertices.size(); ++i) { init_data.add_vertex((Vec3f)plane.vertices[i].cast(), (Vec3f)plane.normal.cast()); - if (init_data.format.index_type == GLModel::Geometry::EIndexType::USHORT) - init_data.add_ushort_index((unsigned short)i); - else - init_data.add_uint_index((unsigned int)i); + init_data.add_index((unsigned int)i); } plane.vbo.init_from(std::move(init_data)); #else diff --git a/src/slic3r/GUI/Gizmos/GLGizmoMove.cpp b/src/slic3r/GUI/Gizmos/GLGizmoMove.cpp index f4e468a26..18acf6e9b 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmoMove.cpp +++ b/src/slic3r/GUI/Gizmos/GLGizmoMove.cpp @@ -132,7 +132,7 @@ void GLGizmoMove3D::on_render() m_grabber_connections[id].model.reset(); GLModel::Geometry init_data; - init_data.format = { GLModel::Geometry::EPrimitiveType::Lines, GLModel::Geometry::EVertexLayout::P3, GLModel::Geometry::EIndexType::USHORT }; + init_data.format = { GLModel::Geometry::EPrimitiveType::Lines, GLModel::Geometry::EVertexLayout::P3 }; init_data.color = AXES_COLOR[id]; init_data.reserve_vertices(2); init_data.reserve_indices(2); @@ -142,7 +142,7 @@ void GLGizmoMove3D::on_render() init_data.add_vertex((Vec3f)m_grabbers[id].center.cast()); // indices - init_data.add_ushort_line(0, 1); + init_data.add_line(0, 1); m_grabber_connections[id].model.init_from(std::move(init_data)); } diff --git a/src/slic3r/GUI/Gizmos/GLGizmoPainterBase.cpp b/src/slic3r/GUI/Gizmos/GLGizmoPainterBase.cpp index e0b0242d4..03d60440a 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmoPainterBase.cpp +++ b/src/slic3r/GUI/Gizmos/GLGizmoPainterBase.cpp @@ -230,21 +230,21 @@ void GLGizmoPainterBase::render_cursor_circle() GLModel::Geometry init_data; static const unsigned int StepsCount = 32; static const float StepSize = 2.0f * float(PI) / float(StepsCount); - init_data.format = { GLModel::Geometry::EPrimitiveType::LineLoop, GLModel::Geometry::EVertexLayout::P2, GLModel::Geometry::EIndexType::USHORT }; + init_data.format = { GLModel::Geometry::EPrimitiveType::LineLoop, GLModel::Geometry::EVertexLayout::P2 }; init_data.color = { 0.0f, 1.0f, 0.3f, 1.0f }; init_data.reserve_vertices(StepsCount); init_data.reserve_indices(StepsCount); // vertices + indices - for (unsigned short i = 0; i < StepsCount; ++i) { - const float angle = float(i * StepSize); + for (unsigned int i = 0; i < StepsCount; ++i) { + const float angle = float(i) * StepSize; #if ENABLE_GL_SHADERS_ATTRIBUTES init_data.add_vertex(Vec2f(2.0f * ((center.x() + ::cos(angle) * radius) * cnv_inv_width - 0.5f), -2.0f * ((center.y() + ::sin(angle) * radius) * cnv_inv_height - 0.5f))); #else init_data.add_vertex(Vec2f(center.x() + ::cos(angle) * m_cursor_radius, center.y() + ::sin(angle) * m_cursor_radius)); #endif // ENABLE_GL_SHADERS_ATTRIBUTES - init_data.add_ushort_index(i); + init_data.add_index(i); } m_circle.init_from(std::move(init_data)); @@ -1014,12 +1014,12 @@ void TriangleSelectorGUI::update_render_data() } GLModel::Geometry iva_enforcers_data; - iva_enforcers_data.format = { GLModel::Geometry::EPrimitiveType::Triangles, GLModel::Geometry::EVertexLayout::P3N3, GLModel::Geometry::EIndexType::UINT }; + iva_enforcers_data.format = { GLModel::Geometry::EPrimitiveType::Triangles, GLModel::Geometry::EVertexLayout::P3N3 }; GLModel::Geometry iva_blockers_data; - iva_blockers_data.format = { GLModel::Geometry::EPrimitiveType::Triangles, GLModel::Geometry::EVertexLayout::P3N3, GLModel::Geometry::EIndexType::UINT }; + iva_blockers_data.format = { GLModel::Geometry::EPrimitiveType::Triangles, GLModel::Geometry::EVertexLayout::P3N3 }; std::array iva_seed_fills_data; for (auto& data : iva_seed_fills_data) - data.format = { GLModel::Geometry::EPrimitiveType::Triangles, GLModel::Geometry::EVertexLayout::P3N3, GLModel::Geometry::EIndexType::UINT }; + data.format = { GLModel::Geometry::EPrimitiveType::Triangles, GLModel::Geometry::EVertexLayout::P3N3 }; #else for (auto *iva : {&m_iva_enforcers, &m_iva_blockers}) iva->release_geometry(); @@ -1055,7 +1055,7 @@ void TriangleSelectorGUI::update_render_data() iva.add_vertex(v0, n); iva.add_vertex(v1, n); iva.add_vertex(v2, n); - iva.add_uint_triangle((unsigned int)cnt, (unsigned int)cnt + 1, (unsigned int)cnt + 2); + iva.add_triangle((unsigned int)cnt, (unsigned int)cnt + 1, (unsigned int)cnt + 2); #else iva.push_geometry(v0, n); iva.push_geometry(v1, n); @@ -1345,7 +1345,7 @@ void TriangleSelectorGUI::update_paint_contour() GLModel::Geometry init_data; const std::vector contour_edges = this->get_seed_fill_contour(); - init_data.format = { GLModel::Geometry::EPrimitiveType::Lines, GLModel::Geometry::EVertexLayout::P3, GLModel::Geometry::index_type(2 * contour_edges.size()) }; + init_data.format = { GLModel::Geometry::EPrimitiveType::Lines, GLModel::Geometry::EVertexLayout::P3 }; init_data.reserve_vertices(2 * contour_edges.size()); init_data.reserve_indices(2 * contour_edges.size()); #if ENABLE_GL_SHADERS_ATTRIBUTES @@ -1358,10 +1358,7 @@ void TriangleSelectorGUI::update_paint_contour() init_data.add_vertex(m_vertices[edge(0)].v); init_data.add_vertex(m_vertices[edge(1)].v); vertices_count += 2; - if (init_data.format.index_type == GLModel::Geometry::EIndexType::USHORT) - init_data.add_ushort_line((unsigned short)vertices_count - 2, (unsigned short)vertices_count - 1); - else - init_data.add_uint_line(vertices_count - 2, vertices_count - 1); + init_data.add_line(vertices_count - 2, vertices_count - 1); } if (!init_data.is_empty()) diff --git a/src/slic3r/GUI/Gizmos/GLGizmoRotate.cpp b/src/slic3r/GUI/Gizmos/GLGizmoRotate.cpp index e9d07f21c..33866c64f 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmoRotate.cpp +++ b/src/slic3r/GUI/Gizmos/GLGizmoRotate.cpp @@ -297,15 +297,15 @@ void GLGizmoRotate::render_circle() const m_circle.reset(); GLModel::Geometry init_data; - init_data.format = { GLModel::Geometry::EPrimitiveType::LineLoop, GLModel::Geometry::EVertexLayout::P3, GLModel::Geometry::EIndexType::USHORT }; + init_data.format = { GLModel::Geometry::EPrimitiveType::LineLoop, GLModel::Geometry::EVertexLayout::P3 }; init_data.reserve_vertices(ScaleStepsCount); init_data.reserve_indices(ScaleStepsCount); // vertices + indices - for (unsigned short i = 0; i < ScaleStepsCount; ++i) { + for (unsigned int i = 0; i < ScaleStepsCount; ++i) { const float angle = float(i * ScaleStepRad); init_data.add_vertex(Vec3f(::cos(angle) * m_radius, ::sin(angle) * m_radius, 0.0f)); - init_data.add_ushort_index(i); + init_data.add_index(i); } m_circle.init_from(std::move(init_data)); @@ -340,12 +340,12 @@ void GLGizmoRotate::render_scale() const m_scale.reset(); GLModel::Geometry init_data; - init_data.format = { GLModel::Geometry::EPrimitiveType::Lines, GLModel::Geometry::EVertexLayout::P3, GLModel::Geometry::EIndexType::USHORT }; + init_data.format = { GLModel::Geometry::EPrimitiveType::Lines, GLModel::Geometry::EVertexLayout::P3 }; init_data.reserve_vertices(2 * ScaleStepsCount); init_data.reserve_indices(2 * ScaleStepsCount); // vertices + indices - for (unsigned short i = 0; i < ScaleStepsCount; ++i) { + for (unsigned int i = 0; i < ScaleStepsCount; ++i) { const float angle = float(i * ScaleStepRad); const float cosa = ::cos(angle); const float sina = ::sin(angle); @@ -354,10 +354,12 @@ void GLGizmoRotate::render_scale() const const float out_x = (i % ScaleLongEvery == 0) ? cosa * out_radius_long : cosa * out_radius_short; const float out_y = (i % ScaleLongEvery == 0) ? sina * out_radius_long : sina * out_radius_short; + // vertices init_data.add_vertex(Vec3f(in_x, in_y, 0.0f)); init_data.add_vertex(Vec3f(out_x, out_y, 0.0f)); - init_data.add_ushort_index(i * 2); - init_data.add_ushort_index(i * 2 + 1); + + // indices + init_data.add_line(i * 2, i * 2 + 1); } m_scale.init_from(std::move(init_data)); @@ -399,12 +401,12 @@ void GLGizmoRotate::render_snap_radii() const m_snap_radii.reset(); GLModel::Geometry init_data; - init_data.format = { GLModel::Geometry::EPrimitiveType::Lines, GLModel::Geometry::EVertexLayout::P3, GLModel::Geometry::EIndexType::USHORT }; + init_data.format = { GLModel::Geometry::EPrimitiveType::Lines, GLModel::Geometry::EVertexLayout::P3 }; init_data.reserve_vertices(2 * ScaleStepsCount); init_data.reserve_indices(2 * ScaleStepsCount); // vertices + indices - for (unsigned short i = 0; i < ScaleStepsCount; ++i) { + for (unsigned int i = 0; i < ScaleStepsCount; ++i) { const float angle = float(i * step); const float cosa = ::cos(angle); const float sina = ::sin(angle); @@ -413,10 +415,12 @@ void GLGizmoRotate::render_snap_radii() const const float out_x = cosa * out_radius; const float out_y = sina * out_radius; + // vertices init_data.add_vertex(Vec3f(in_x, in_y, 0.0f)); init_data.add_vertex(Vec3f(out_x, out_y, 0.0f)); - init_data.add_ushort_index(i * 2); - init_data.add_ushort_index(i * 2 + 1); + + // indices + init_data.add_line(i * 2, i * 2 + 1); } m_snap_radii.init_from(std::move(init_data)); @@ -450,7 +454,7 @@ void GLGizmoRotate::render_reference_radius(const ColorRGBA& color, bool radius_ m_reference_radius.reset(); GLModel::Geometry init_data; - init_data.format = { GLModel::Geometry::EPrimitiveType::Lines, GLModel::Geometry::EVertexLayout::P3, GLModel::Geometry::EIndexType::USHORT }; + init_data.format = { GLModel::Geometry::EPrimitiveType::Lines, GLModel::Geometry::EVertexLayout::P3 }; init_data.reserve_vertices(2); init_data.reserve_indices(2); @@ -459,7 +463,7 @@ void GLGizmoRotate::render_reference_radius(const ColorRGBA& color, bool radius_ init_data.add_vertex(Vec3f(m_radius * (1.0f + GrabberOffset), 0.0f, 0.0f)); // indices - init_data.add_ushort_line(0, 1); + init_data.add_line(0, 1); m_reference_radius.init_from(std::move(init_data)); } @@ -494,15 +498,15 @@ void GLGizmoRotate::render_angle() const m_angle_arc.reset(); if (m_angle > 0.0f) { GLModel::Geometry init_data; - init_data.format = { GLModel::Geometry::EPrimitiveType::LineStrip, GLModel::Geometry::EVertexLayout::P3, GLModel::Geometry::EIndexType::USHORT }; + init_data.format = { GLModel::Geometry::EPrimitiveType::LineStrip, GLModel::Geometry::EVertexLayout::P3 }; init_data.reserve_vertices(1 + AngleResolution); init_data.reserve_indices(1 + AngleResolution); // vertices + indices - for (unsigned short i = 0; i <= AngleResolution; ++i) { + for (unsigned int i = 0; i <= AngleResolution; ++i) { const float angle = float(i) * step_angle; init_data.add_vertex(Vec3f(::cos(angle) * ex_radius, ::sin(angle) * ex_radius, 0.0f)); - init_data.add_ushort_index(i); + init_data.add_index(i); } m_angle_arc.init_from(std::move(init_data)); @@ -532,7 +536,7 @@ void GLGizmoRotate::render_grabber_connection(const ColorRGBA& color, bool radiu m_grabber_connection.old_center = m_grabbers.front().center; GLModel::Geometry init_data; - init_data.format = { GLModel::Geometry::EPrimitiveType::Lines, GLModel::Geometry::EVertexLayout::P3, GLModel::Geometry::EIndexType::USHORT }; + init_data.format = { GLModel::Geometry::EPrimitiveType::Lines, GLModel::Geometry::EVertexLayout::P3 }; init_data.reserve_vertices(2); init_data.reserve_indices(2); @@ -541,7 +545,7 @@ void GLGizmoRotate::render_grabber_connection(const ColorRGBA& color, bool radiu init_data.add_vertex((Vec3f)m_grabbers.front().center.cast()); // indices - init_data.add_ushort_line(0, 1); + init_data.add_line(0, 1); m_grabber_connection.model.init_from(std::move(init_data)); } diff --git a/src/slic3r/GUI/Gizmos/GLGizmoScale.cpp b/src/slic3r/GUI/Gizmos/GLGizmoScale.cpp index f32aac604..373a2396d 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmoScale.cpp +++ b/src/slic3r/GUI/Gizmos/GLGizmoScale.cpp @@ -515,7 +515,7 @@ void GLGizmoScale3D::render_grabbers_connection(unsigned int id_1, unsigned int m_grabber_connections[id].model.reset(); GLModel::Geometry init_data; - init_data.format = { GLModel::Geometry::EPrimitiveType::Lines, GLModel::Geometry::EVertexLayout::P3, GLModel::Geometry::EIndexType::USHORT }; + init_data.format = { GLModel::Geometry::EPrimitiveType::Lines, GLModel::Geometry::EVertexLayout::P3 }; init_data.reserve_vertices(2); init_data.reserve_indices(2); @@ -524,7 +524,7 @@ void GLGizmoScale3D::render_grabbers_connection(unsigned int id_1, unsigned int init_data.add_vertex((Vec3f)m_grabbers[id_2].center.cast()); // indices - init_data.add_ushort_line(0, 1); + init_data.add_line(0, 1); m_grabber_connections[id].model.init_from(std::move(init_data)); } diff --git a/src/slic3r/GUI/MeshUtils.cpp b/src/slic3r/GUI/MeshUtils.cpp index 4e4b26830..e7e9ba2fb 100644 --- a/src/slic3r/GUI/MeshUtils.cpp +++ b/src/slic3r/GUI/MeshUtils.cpp @@ -202,7 +202,7 @@ void MeshClipper::recalculate_triangles() m_model.reset(); GLModel::Geometry init_data; - init_data.format = { GLModel::Geometry::EPrimitiveType::Triangles, GLModel::Geometry::EVertexLayout::P3N3, GLModel::Geometry::index_type(m_triangles2d.size()) }; + init_data.format = { GLModel::Geometry::EPrimitiveType::Triangles, GLModel::Geometry::EVertexLayout::P3N3 }; init_data.reserve_vertices(m_triangles2d.size()); init_data.reserve_indices(m_triangles2d.size()); @@ -212,10 +212,7 @@ void MeshClipper::recalculate_triangles() init_data.add_vertex((Vec3f)(tr * Vec3d((*(it + 1)).x(), (*(it + 1)).y(), height_mesh)).cast(), (Vec3f)up.cast()); init_data.add_vertex((Vec3f)(tr * Vec3d((*(it + 2)).x(), (*(it + 2)).y(), height_mesh)).cast(), (Vec3f)up.cast()); const size_t idx = it - m_triangles2d.cbegin(); - if (init_data.format.index_type == GLModel::Geometry::EIndexType::USHORT) - init_data.add_ushort_triangle((unsigned short)idx, (unsigned short)idx + 1, (unsigned short)idx + 2); - else - init_data.add_uint_triangle((unsigned int)idx, (unsigned int)idx + 1, (unsigned int)idx + 2); + init_data.add_triangle((unsigned int)idx, (unsigned int)idx + 1, (unsigned int)idx + 2); } if (!init_data.is_empty()) diff --git a/src/slic3r/GUI/Selection.cpp b/src/slic3r/GUI/Selection.cpp index 9f554b64d..68a052341 100644 --- a/src/slic3r/GUI/Selection.cpp +++ b/src/slic3r/GUI/Selection.cpp @@ -1947,7 +1947,7 @@ void Selection::render_bounding_box(const BoundingBoxf3 & box, float* color) con const Vec3f size = 0.2f * box.size().cast(); GLModel::Geometry init_data; - init_data.format = { GLModel::Geometry::EPrimitiveType::Lines, GLModel::Geometry::EVertexLayout::P3, GLModel::Geometry::EIndexType::USHORT }; + init_data.format = { GLModel::Geometry::EPrimitiveType::Lines, GLModel::Geometry::EVertexLayout::P3 }; init_data.reserve_vertices(48); init_data.reserve_indices(48); @@ -2009,8 +2009,8 @@ void Selection::render_bounding_box(const BoundingBoxf3 & box, float* color) con init_data.add_vertex(Vec3f(b_min.x(), b_max.y(), b_max.z() - size.z())); // indices - for (unsigned short i = 0; i < 48; ++i) { - init_data.add_ushort_index(i); + for (unsigned int i = 0; i < 48; ++i) { + init_data.add_index(i); } m_box.init_from(std::move(init_data)); @@ -2371,7 +2371,7 @@ void Selection::render_sidebar_layers_hints(const std::string& sidebar_field) m_planes.models[0].reset(); GLModel::Geometry init_data; - init_data.format = { GLModel::Geometry::EPrimitiveType::Triangles, GLModel::Geometry::EVertexLayout::P3, GLModel::Geometry::EIndexType::USHORT }; + init_data.format = { GLModel::Geometry::EPrimitiveType::Triangles, GLModel::Geometry::EVertexLayout::P3 }; init_data.reserve_vertices(4); init_data.reserve_indices(6); @@ -2382,8 +2382,8 @@ void Selection::render_sidebar_layers_hints(const std::string& sidebar_field) init_data.add_vertex(Vec3f(p1.x(), p2.y(), z1)); // indices - init_data.add_ushort_triangle(0, 1, 2); - init_data.add_ushort_triangle(2, 3, 0); + init_data.add_triangle(0, 1, 2); + init_data.add_triangle(2, 3, 0); m_planes.models[0].init_from(std::move(init_data)); } @@ -2393,7 +2393,7 @@ void Selection::render_sidebar_layers_hints(const std::string& sidebar_field) m_planes.models[1].reset(); GLModel::Geometry init_data; - init_data.format = { GLModel::Geometry::EPrimitiveType::Triangles, GLModel::Geometry::EVertexLayout::P3, GLModel::Geometry::EIndexType::USHORT }; + init_data.format = { GLModel::Geometry::EPrimitiveType::Triangles, GLModel::Geometry::EVertexLayout::P3 }; init_data.reserve_vertices(4); init_data.reserve_indices(6); @@ -2404,8 +2404,8 @@ void Selection::render_sidebar_layers_hints(const std::string& sidebar_field) init_data.add_vertex(Vec3f(p1.x(), p2.y(), z2)); // indices - init_data.add_ushort_triangle(0, 1, 2); - init_data.add_ushort_triangle(2, 3, 0); + init_data.add_triangle(0, 1, 2); + init_data.add_triangle(2, 3, 0); m_planes.models[1].init_from(std::move(init_data)); }