From 11f8e53e278038f92bb14ea0c728e8056497107d Mon Sep 17 00:00:00 2001 From: Maciej Suminski Date: Fri, 10 Mar 2017 11:18:15 +0100 Subject: [PATCH] Smoother arc rendering in OpenGL GAL Fixes: lp:1496114 * https://bugs.launchpad.net/kicad/+bug/1496114 --- common/gal/opengl/opengl_gal.cpp | 6 +++--- include/gal/opengl/opengl_gal.h | 9 +++++++++ 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/common/gal/opengl/opengl_gal.cpp b/common/gal/opengl/opengl_gal.cpp index 97b5f19b99..f48794f4ec 100644 --- a/common/gal/opengl/opengl_gal.cpp +++ b/common/gal/opengl/opengl_gal.cpp @@ -532,12 +532,13 @@ void OPENGL_GAL::DrawArc( const VECTOR2D& aCenterPoint, double aRadius, double a // Swap the angles, if start angle is greater than end angle SWAP( aStartAngle, >, aEndAngle ); + const double alphaIncrement = calcAngleStep( aRadius ); + Save(); currentManager->Translate( aCenterPoint.x, aCenterPoint.y, 0.0 ); if( isStrokeEnabled ) { - const double alphaIncrement = 2.0 * M_PI / CIRCLE_POINTS; currentManager->Color( strokeColor.r, strokeColor.g, strokeColor.b, strokeColor.a ); VECTOR2D p( cos( aStartAngle ) * aRadius, sin( aStartAngle ) * aRadius ); @@ -561,7 +562,6 @@ void OPENGL_GAL::DrawArc( const VECTOR2D& aCenterPoint, double aRadius, double a if( isFillEnabled ) { - const double alphaIncrement = 2 * M_PI / CIRCLE_POINTS; double alpha; currentManager->Color( fillColor.r, fillColor.g, fillColor.b, fillColor.a ); currentManager->Shader( SHADER_NONE ); @@ -598,7 +598,7 @@ void OPENGL_GAL::DrawArcSegment( const VECTOR2D& aCenterPoint, double aRadius, d // Swap the angles, if start angle is greater than end angle SWAP( aStartAngle, >, aEndAngle ); - const double alphaIncrement = 2.0 * M_PI / CIRCLE_POINTS; + const double alphaIncrement = calcAngleStep( aRadius ); Save(); currentManager->Translate( aCenterPoint.x, aCenterPoint.y, 0.0 ); diff --git a/include/gal/opengl/opengl_gal.h b/include/gal/opengl/opengl_gal.h index e58ce4b2fc..f5c979df7e 100644 --- a/include/gal/opengl/opengl_gal.h +++ b/include/gal/opengl/opengl_gal.h @@ -440,6 +440,15 @@ private: */ unsigned int getNewGroupNumber(); + /** + * @brief Compute the angle step when drawing arcs/circles approximated with lines. + */ + double calcAngleStep( double aRadius ) const + { + // Bigger arcs need smaller alpha increment to make them look smooth + return std::min( 1e6 / aRadius, 2.0 * M_PI / CIRCLE_POINTS ); + } + /** * @brief Basic OpenGL initialization. */