Gerbview: seriously speed up the calculation time to draw polygons on OpenGL.

Mainly CacheTriangulation() was creating triangles using partition mode.
But this mode is optimized for Pcbnew and Gerbview and different internal units.
Now CacheTriangulation() is used in no partition, much faster in GERBVIEW_PAINTER.
From Master branch
This commit is contained in:
jean-pierre charras 2022-05-13 18:33:53 +02:00
parent f25d74628b
commit c07ac8b3db
2 changed files with 16 additions and 3 deletions

View File

@ -2,7 +2,7 @@
* This program source code file is part of KiCad, a free EDA CAD application. * This program source code file is part of KiCad, a free EDA CAD application.
* *
* Copyright (C) 2017 Jon Evans <jon@craftyjon.com> * Copyright (C) 2017 Jon Evans <jon@craftyjon.com>
* Copyright (C) 2021 KiCad Developers, see AUTHORS.txt for contributors. * Copyright (C) 2022 KiCad Developers, see AUTHORS.txt for contributors.
* *
* This program is free software: you can redistribute it and/or modify it * This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the * under the terms of the GNU General Public License as published by the
@ -299,8 +299,11 @@ void GERBVIEW_PAINTER::draw( /*const*/ GERBER_DRAW_ITEM* aItem, int aLayer )
// On Opengl, a not convex filled polygon is usually drawn by using triangles as primitives. // On Opengl, a not convex filled polygon is usually drawn by using triangles as primitives.
// CacheTriangulation() can create basic triangle primitives to draw the polygon solid shape // CacheTriangulation() can create basic triangle primitives to draw the polygon solid shape
// on Opengl // on Opengl
// We use the fastest CacheTriangulation calculation mode: no partition created because
// the partition is useless in Gerbview, and very time consumming (optimized only
// for pcbnew that has different internal unit)
if( m_gal->IsOpenGlEngine() && !aItem->m_AbsolutePolygon.IsTriangulationUpToDate() ) if( m_gal->IsOpenGlEngine() && !aItem->m_AbsolutePolygon.IsTriangulationUpToDate() )
aItem->m_AbsolutePolygon.CacheTriangulation(); aItem->m_AbsolutePolygon.CacheTriangulation( false /* fastest triangulation calculation mode */ );
m_gal->DrawPolygon( aItem->m_AbsolutePolygon ); m_gal->DrawPolygon( aItem->m_AbsolutePolygon );
} }

View File

@ -499,6 +499,16 @@ public:
SHAPE_POLY_SET& operator=( const SHAPE_POLY_SET& aOther ); SHAPE_POLY_SET& operator=( const SHAPE_POLY_SET& aOther );
/**
* Build a polygon triangulation, needed to draw a polygon on OpenGL and in some
* other calculations
* @param aPartition = true to created a trinagulation in a partition on a grid
* false to create a more basic triangulation of the polygons
* Note
* in partition calculations the grid size is hard coded to 1e7.
* This is a good value for Pcbnew: 1cm, in internal units.
* But not good for Gerbview (1e7 = 10cm), however using a partition is not useful.
*/
void CacheTriangulation( bool aPartition = true ); void CacheTriangulation( bool aPartition = true );
bool IsTriangulationUpToDate() const; bool IsTriangulationUpToDate() const;