Tech ENABLE_GLBEGIN_GLEND_REMOVAL - Refactoring to simplify client code of GLModel::Geometry

This commit is contained in:
enricoturri1966 2022-02-09 09:15:20 +01:00
parent ffa3a1d8fc
commit be6b6590be
10 changed files with 45 additions and 45 deletions

View File

@ -326,8 +326,8 @@ void GLVolume::SinkingContours::update()
for (const ExPolygon& expoly : diff_ex(expand(polygons, float(scale_(HalfWidth))), shrink(polygons, float(scale_(HalfWidth))))) { for (const ExPolygon& expoly : diff_ex(expand(polygons, float(scale_(HalfWidth))), shrink(polygons, float(scale_(HalfWidth))))) {
#if ENABLE_GLBEGIN_GLEND_REMOVAL #if ENABLE_GLBEGIN_GLEND_REMOVAL
const std::vector<Vec3d> triangulation = triangulate_expolygon_3d(expoly); const std::vector<Vec3d> triangulation = triangulate_expolygon_3d(expoly);
init_data.vertices.reserve(init_data.vertices.size() + triangulation.size() * GUI::GLModel::Geometry::vertex_stride_floats(init_data.format)); init_data.reserve_vertices(init_data.vertices_count() + triangulation.size());
init_data.indices.reserve(init_data.indices.size() + triangulation.size() * GUI::GLModel::Geometry::index_stride_bytes(init_data.format)); init_data.reserve_indices(init_data.indices_count() + triangulation.size());
for (const Vec3d& v : triangulation) { for (const Vec3d& v : triangulation) {
init_data.add_vertex((Vec3f)(v.cast<float>() + 0.015f * Vec3f::UnitZ())); // add a small positive z to avoid z-fighting init_data.add_vertex((Vec3f)(v.cast<float>() + 0.015f * Vec3f::UnitZ())); // add a small positive z to avoid z-fighting
++vertices_counter; ++vertices_counter;
@ -401,8 +401,8 @@ void GLVolume::NonManifoldEdges::update()
GUI::GLModel::Geometry init_data; GUI::GLModel::Geometry init_data;
#if ENABLE_GLBEGIN_GLEND_REMOVAL #if ENABLE_GLBEGIN_GLEND_REMOVAL
init_data.format = { GUI::GLModel::Geometry::EPrimitiveType::Lines, GUI::GLModel::Geometry::EVertexLayout::P3, GUI::GLModel::Geometry::EIndexType::UINT }; init_data.format = { GUI::GLModel::Geometry::EPrimitiveType::Lines, GUI::GLModel::Geometry::EVertexLayout::P3, GUI::GLModel::Geometry::EIndexType::UINT };
init_data.vertices.reserve(2 * edges.size() * GUI::GLModel::Geometry::vertex_stride_floats(init_data.format)); init_data.reserve_vertices(2 * edges.size());
init_data.indices.reserve(2 * edges.size() * GUI::GLModel::Geometry::index_stride_bytes(init_data.format)); init_data.reserve_indices(2 * edges.size());
// vertices + indices // vertices + indices
unsigned int vertices_count = 0; unsigned int vertices_count = 0;

View File

@ -368,8 +368,8 @@ void GLCanvas3D::LayersEditing::render_active_object_annotations(const GLCanvas3
GLModel::Geometry init_data; 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, GLModel::Geometry::EIndexType::USHORT };
init_data.vertices.reserve(4 * GLModel::Geometry::vertex_stride_floats(init_data.format)); init_data.reserve_vertices(4);
init_data.indices.reserve(6 * GLModel::Geometry::index_stride_bytes(init_data.format)); init_data.reserve_indices(6);
// vertices // vertices
const float l = bar_rect.get_left(); const float l = bar_rect.get_left();
@ -428,8 +428,8 @@ void GLCanvas3D::LayersEditing::render_profile(const Rect& bar_rect)
GLModel::Geometry init_data; 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, GLModel::Geometry::EIndexType::USHORT };
init_data.color = ColorRGBA::BLACK(); init_data.color = ColorRGBA::BLACK();
init_data.vertices.reserve(2 * GLModel::Geometry::vertex_stride_floats(init_data.format)); init_data.reserve_vertices(2);
init_data.indices.reserve(2 * GLModel::Geometry::index_stride_bytes(init_data.format)); init_data.reserve_indices(2);
// vertices // vertices
const float x = bar_rect.get_left() + float(m_slicing_parameters->layer_height) * scale_x; const float x = bar_rect.get_left() + float(m_slicing_parameters->layer_height) * scale_x;
@ -449,8 +449,8 @@ void GLCanvas3D::LayersEditing::render_profile(const Rect& bar_rect)
GLModel::Geometry init_data; GLModel::Geometry init_data;
init_data.format = { GLModel::Geometry::EPrimitiveType::LineStrip, GLModel::Geometry::EVertexLayout::P2, GLModel::Geometry::EIndexType::UINT }; init_data.format = { GLModel::Geometry::EPrimitiveType::LineStrip, GLModel::Geometry::EVertexLayout::P2, GLModel::Geometry::EIndexType::UINT };
init_data.color = ColorRGBA::BLUE(); init_data.color = ColorRGBA::BLUE();
init_data.vertices.reserve(m_layer_height_profile.size() * GLModel::Geometry::vertex_stride_floats(init_data.format)); init_data.reserve_vertices(m_layer_height_profile.size() / 2);
init_data.indices.reserve(m_layer_height_profile.size() * GLModel::Geometry::index_stride_bytes(init_data.format)); init_data.reserve_indices(m_layer_height_profile.size() / 2);
// vertices + indices // vertices + indices
for (unsigned int i = 0; i < (unsigned int)m_layer_height_profile.size(); i += 2) { for (unsigned int i = 0; i < (unsigned int)m_layer_height_profile.size(); i += 2) {
@ -5238,8 +5238,8 @@ void GLCanvas3D::_render_background()
GLModel::Geometry init_data; 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, GLModel::Geometry::EIndexType::USHORT };
init_data.vertices.reserve(4 * GLModel::Geometry::vertex_stride_floats(init_data.format)); init_data.reserve_vertices(4);
init_data.indices.reserve(6 * GLModel::Geometry::index_stride_bytes(init_data.format)); init_data.reserve_indices(6);
// vertices // vertices
init_data.add_vertex(Vec2f(-1.0f, -1.0f), Vec2f(0.0f, 0.0f)); init_data.add_vertex(Vec2f(-1.0f, -1.0f), Vec2f(0.0f, 0.0f));

View File

@ -126,8 +126,8 @@ namespace GUI {
GLModel::Geometry init_data; 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, GLModel::Geometry::EIndexType::USHORT };
init_data.vertices.reserve(4 * GLModel::Geometry::vertex_stride_floats(init_data.format)); init_data.reserve_vertices(4);
init_data.indices.reserve(4 * GLModel::Geometry::index_stride_bytes(init_data.format)); init_data.reserve_indices(4);
// vertices // vertices
init_data.add_vertex(Vec2f(left, bottom)); init_data.add_vertex(Vec2f(left, bottom));

View File

@ -342,8 +342,8 @@ void GLTexture::render_sub_texture(unsigned int tex_id, float left, float right,
#if ENABLE_GLBEGIN_GLEND_REMOVAL #if ENABLE_GLBEGIN_GLEND_REMOVAL
GLModel::Geometry init_data; 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, GLModel::Geometry::EIndexType::USHORT };
init_data.vertices.reserve(4 * GLModel::Geometry::vertex_stride_floats(init_data.format)); init_data.reserve_vertices(4);
init_data.indices.reserve(6 * GLModel::Geometry::index_stride_bytes(init_data.format)); init_data.reserve_indices(6);
// vertices // vertices
init_data.add_vertex(Vec2f(left, bottom), Vec2f(uvs.left_bottom.u, uvs.left_bottom.v)); init_data.add_vertex(Vec2f(left, bottom), Vec2f(uvs.left_bottom.u, uvs.left_bottom.v));

View File

@ -115,8 +115,8 @@ void GLGizmoCut::on_render()
GLModel::Geometry init_data; 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, GLModel::Geometry::EIndexType::USHORT };
init_data.color = { 0.8f, 0.8f, 0.8f, 0.5f }; init_data.color = { 0.8f, 0.8f, 0.8f, 0.5f };
init_data.vertices.reserve(4 * GLModel::Geometry::vertex_stride_floats(init_data.format)); init_data.reserve_vertices(4);
init_data.indices.reserve(6 * GLModel::Geometry::index_stride_bytes(init_data.format)); init_data.reserve_indices(6);
// vertices // vertices
init_data.add_vertex(Vec3f(min_x, min_y, plane_center.z())); init_data.add_vertex(Vec3f(min_x, min_y, plane_center.z()));
@ -160,8 +160,8 @@ void GLGizmoCut::on_render()
GLModel::Geometry init_data; 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, GLModel::Geometry::EIndexType::USHORT };
init_data.color = ColorRGBA::YELLOW(); init_data.color = ColorRGBA::YELLOW();
init_data.vertices.reserve(2 * GLModel::Geometry::vertex_stride_floats(init_data.format)); init_data.reserve_vertices(2);
init_data.indices.reserve(2 * GLModel::Geometry::index_stride_bytes(init_data.format)); init_data.reserve_indices(2);
// vertices // vertices
init_data.add_vertex((Vec3f)plane_center.cast<float>()); init_data.add_vertex((Vec3f)plane_center.cast<float>());

View File

@ -117,8 +117,8 @@ void GLGizmoMove3D::on_render()
GLModel::Geometry init_data; 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, GLModel::Geometry::EIndexType::USHORT };
init_data.color = AXES_COLOR[id]; init_data.color = AXES_COLOR[id];
init_data.vertices.reserve(2 * GLModel::Geometry::vertex_stride_floats(init_data.format)); init_data.reserve_vertices(2);
init_data.indices.reserve(2 * GLModel::Geometry::index_stride_bytes(init_data.format)); init_data.reserve_indices(2);
// vertices // vertices
init_data.add_vertex((Vec3f)center.cast<float>()); init_data.add_vertex((Vec3f)center.cast<float>());

View File

@ -185,8 +185,8 @@ void GLGizmoPainterBase::render_cursor_circle()
static const float StepSize = 2.0f * float(PI) / float(StepsCount); static const float StepSize = 2.0f * float(PI) / float(StepsCount);
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, GLModel::Geometry::EIndexType::USHORT };
init_data.color = { 0.0f, 1.0f, 0.3f, 1.0f }; init_data.color = { 0.0f, 1.0f, 0.3f, 1.0f };
init_data.vertices.reserve(StepsCount * GLModel::Geometry::vertex_stride_floats(init_data.format)); init_data.reserve_vertices(StepsCount);
init_data.indices.reserve(StepsCount * GLModel::Geometry::index_stride_bytes(init_data.format)); init_data.reserve_indices(StepsCount);
// vertices + indices // vertices + indices
for (unsigned short i = 0; i < StepsCount; ++i) { for (unsigned short i = 0; i < StepsCount; ++i) {

View File

@ -235,8 +235,8 @@ void GLGizmoRotate::render_circle() const
GLModel::Geometry init_data; 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, GLModel::Geometry::EIndexType::USHORT };
init_data.vertices.reserve(ScaleStepsCount * GLModel::Geometry::vertex_stride_floats(init_data.format)); init_data.reserve_vertices(ScaleStepsCount);
init_data.indices.reserve(ScaleStepsCount * GLModel::Geometry::index_stride_bytes(init_data.format)); init_data.reserve_indices(ScaleStepsCount);
// vertices + indices // vertices + indices
for (unsigned short i = 0; i < ScaleStepsCount; ++i) { for (unsigned short i = 0; i < ScaleStepsCount; ++i) {
@ -278,8 +278,8 @@ void GLGizmoRotate::render_scale() const
GLModel::Geometry init_data; 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, GLModel::Geometry::EIndexType::USHORT };
init_data.vertices.reserve(2 * ScaleStepsCount * GLModel::Geometry::vertex_stride_floats(init_data.format)); init_data.reserve_vertices(2 * ScaleStepsCount);
init_data.indices.reserve(2 * ScaleStepsCount * GLModel::Geometry::index_stride_bytes(init_data.format)); init_data.reserve_indices(2 * ScaleStepsCount);
// vertices + indices // vertices + indices
for (unsigned short i = 0; i < ScaleStepsCount; ++i) { for (unsigned short i = 0; i < ScaleStepsCount; ++i) {
@ -337,8 +337,8 @@ void GLGizmoRotate::render_snap_radii() const
GLModel::Geometry init_data; 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, GLModel::Geometry::EIndexType::USHORT };
init_data.vertices.reserve(2 * ScaleStepsCount * GLModel::Geometry::vertex_stride_floats(init_data.format)); init_data.reserve_vertices(2 * ScaleStepsCount);
init_data.indices.reserve(2 * ScaleStepsCount * GLModel::Geometry::index_stride_bytes(init_data.format)); init_data.reserve_indices(2 * ScaleStepsCount);
// vertices + indices // vertices + indices
for (unsigned short i = 0; i < ScaleStepsCount; ++i) { for (unsigned short i = 0; i < ScaleStepsCount; ++i) {
@ -388,8 +388,8 @@ void GLGizmoRotate::render_reference_radius(const ColorRGBA& color, bool radius_
GLModel::Geometry init_data; 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, GLModel::Geometry::EIndexType::USHORT };
init_data.vertices.reserve(2 * GLModel::Geometry::vertex_stride_floats(init_data.format)); init_data.reserve_vertices(2);
init_data.indices.reserve(2 * GLModel::Geometry::index_stride_bytes(init_data.format)); init_data.reserve_indices(2);
// vertices // vertices
init_data.add_vertex(Vec3f(0.0f, 0.0f, 0.0f)); init_data.add_vertex(Vec3f(0.0f, 0.0f, 0.0f));
@ -429,8 +429,8 @@ void GLGizmoRotate::render_angle() const
GLModel::Geometry init_data; 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, GLModel::Geometry::EIndexType::USHORT };
init_data.vertices.reserve((1 + AngleResolution) * GLModel::Geometry::vertex_stride_floats(init_data.format)); init_data.reserve_vertices(1 + AngleResolution);
init_data.indices.reserve((1 + AngleResolution) * GLModel::Geometry::index_stride_bytes(init_data.format)); init_data.reserve_indices(1 + AngleResolution);
// vertices + indices // vertices + indices
for (unsigned short i = 0; i <= AngleResolution; ++i) { for (unsigned short i = 0; i <= AngleResolution; ++i) {
@ -466,8 +466,8 @@ void GLGizmoRotate::render_grabber_connection(const ColorRGBA& color, bool radiu
GLModel::Geometry init_data; 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, GLModel::Geometry::EIndexType::USHORT };
init_data.vertices.reserve(2 * GLModel::Geometry::vertex_stride_floats(init_data.format)); init_data.reserve_vertices(2);
init_data.indices.reserve(2 * GLModel::Geometry::index_stride_bytes(init_data.format)); init_data.reserve_indices(2);
// vertices // vertices
init_data.add_vertex(Vec3f(0.0f, 0.0f, 0.0f)); init_data.add_vertex(Vec3f(0.0f, 0.0f, 0.0f));

View File

@ -403,8 +403,8 @@ void GLGizmoScale3D::render_grabbers_connection(unsigned int id_1, unsigned int
GLModel::Geometry init_data; 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, GLModel::Geometry::EIndexType::USHORT };
init_data.vertices.reserve(2 * GLModel::Geometry::vertex_stride_floats(init_data.format)); init_data.reserve_vertices(2);
init_data.indices.reserve(2 * GLModel::Geometry::index_stride_bytes(init_data.format)); init_data.reserve_indices(2);
// vertices // vertices
init_data.add_vertex((Vec3f)m_grabbers[id_1].center.cast<float>()); init_data.add_vertex((Vec3f)m_grabbers[id_1].center.cast<float>());

View File

@ -1261,10 +1261,10 @@ void Selection::render(float scale_factor)
return; return;
m_scale_factor = scale_factor; m_scale_factor = scale_factor;
// render cumulative bounding box of selected volumes
#if ENABLE_GLBEGIN_GLEND_REMOVAL #if ENABLE_GLBEGIN_GLEND_REMOVAL
render_bounding_box(get_bounding_box(), ColorRGB::WHITE()); render_bounding_box(get_bounding_box(), ColorRGB::WHITE());
#else #else
// render cumulative bounding box of selected volumes
render_selected_volumes(); render_selected_volumes();
#endif // ENABLE_GLBEGIN_GLEND_REMOVAL #endif // ENABLE_GLBEGIN_GLEND_REMOVAL
render_synchronized_volumes(); render_synchronized_volumes();
@ -1900,8 +1900,8 @@ void Selection::render_bounding_box(const BoundingBoxf3 & box, float* color) con
GLModel::Geometry init_data; 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, GLModel::Geometry::EIndexType::USHORT };
init_data.vertices.reserve(48 * GLModel::Geometry::vertex_stride_floats(init_data.format)); init_data.reserve_vertices(48);
init_data.indices.reserve(48 * GLModel::Geometry::index_stride_bytes(init_data.format)); init_data.reserve_indices(48);
// vertices // vertices
init_data.add_vertex(Vec3f(b_min.x(), b_min.y(), b_min.z())); init_data.add_vertex(Vec3f(b_min.x(), b_min.y(), b_min.z()));
@ -2209,8 +2209,8 @@ void Selection::render_sidebar_layers_hints(const std::string& sidebar_field)
GLModel::Geometry init_data; 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, GLModel::Geometry::EIndexType::USHORT };
init_data.vertices.reserve(4 * GLModel::Geometry::vertex_stride_floats(init_data.format)); init_data.reserve_vertices(4);
init_data.indices.reserve(6 * GLModel::Geometry::index_stride_bytes(init_data.format)); init_data.reserve_indices(6);
// vertices // vertices
init_data.add_vertex(Vec3f(p1.x(), p1.y(), z1)); init_data.add_vertex(Vec3f(p1.x(), p1.y(), z1));
@ -2231,8 +2231,8 @@ void Selection::render_sidebar_layers_hints(const std::string& sidebar_field)
GLModel::Geometry init_data; 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, GLModel::Geometry::EIndexType::USHORT };
init_data.vertices.reserve(4 * GLModel::Geometry::vertex_stride_floats(init_data.format)); init_data.reserve_vertices(4);
init_data.indices.reserve(6 * GLModel::Geometry::index_stride_bytes(init_data.format)); init_data.reserve_indices(6);
// vertices // vertices
init_data.add_vertex(Vec3f(p1.x(), p1.y(), z2)); init_data.add_vertex(Vec3f(p1.x(), p1.y(), z2));