From 0bceb69fe90f6a62c7a3fa583e99406e308a8371 Mon Sep 17 00:00:00 2001 From: jean-pierre charras Date: Sun, 2 Dec 2018 18:00:33 +0100 Subject: [PATCH] Pcbnew: DRAWSEGMENT polygonal shape: use triangulation (CacheTriangulation) to draw the shape (similar to zones). On opengl, creating triangles by CacheTriangulation instead of GLU tesselator is much faster (one order of magnitude) --- pcbnew/class_zone.h | 6 +++--- pcbnew/pcb_painter.cpp | 15 ++++++++------- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/pcbnew/class_zone.h b/pcbnew/class_zone.h index 69bbc5a28b..f116648132 100644 --- a/pcbnew/class_zone.h +++ b/pcbnew/class_zone.h @@ -555,14 +555,14 @@ public: * returns a reference to the list of filled polygons. * @return Reference to the list of filled polygons. */ - - //TODO - This should be called for each layer on which the zone exists - const SHAPE_POLY_SET& GetFilledPolysList() const { return m_FilledPolysList; } + /** (re)create a list of triangles that "fill" the solid areas. + * used for instance to draw these solid areas on opengl + */ void CacheTriangulation(); /** diff --git a/pcbnew/pcb_painter.cpp b/pcbnew/pcb_painter.cpp index 99418f0b3b..a7faeb3888 100644 --- a/pcbnew/pcb_painter.cpp +++ b/pcbnew/pcb_painter.cpp @@ -968,12 +968,16 @@ void PCB_PAINTER::draw( const DRAWSEGMENT* aSegment, int aLayer ) case S_POLYGON: { - const auto& points = aSegment->BuildPolyPointsList(); - std::deque pointsList; + SHAPE_POLY_SET& shape = ((DRAWSEGMENT*)aSegment)->GetPolyShape(); - if( points.empty() ) + if( shape.OutlineCount() == 0 ) break; + if( !shape.IsTriangulationUpToDate() ) + { + shape.CacheTriangulation(); + } + m_gal->Save(); if( MODULE* module = aSegment->GetParentModule() ) @@ -982,13 +986,10 @@ void PCB_PAINTER::draw( const DRAWSEGMENT* aSegment, int aLayer ) m_gal->Rotate( -module->GetOrientationRadians() ); } - std::copy( points.begin(), points.end(), std::back_inserter( pointsList ) ); - pointsList.push_back( points[0] ); - m_gal->SetLineWidth( thickness ); m_gal->SetIsFill( true ); m_gal->SetIsStroke( true ); - m_gal->DrawPolygon( pointsList ); + m_gal->DrawPolygon( shape ); m_gal->Restore(); break;