58using namespace std::placeholders;
66#include <glsl_kicad_frag.h>
67#include <glsl_kicad_vert.h>
77 wxGLAttributes attribs;
78 attribs.RGBA().DoubleBuffer().Depth( 8 ).EndList();
127 glDeleteTextures( 1, &bitmap.second.id );
133#ifndef DISABLE_BITMAP_CACHE
139 if( glIsTexture( it->second.id ) )
141 it->second.accessTime = wxGetUTCTimeMillis().GetValue();
142 return it->second.id;
147 glDeleteTextures( 1, &it->second.id );
175 return std::numeric_limits< GLuint >::max();
177 const wxImage& imgData = *imgPtr;
179 bmp.
w = imgData.GetSize().x;
180 bmp.
h = imgData.GetSize().y;
186 glGenTextures( 1, &textureID );
194 glPixelStorei( GL_UNPACK_ALIGNMENT, 1 );
196 if( imgData.HasAlpha() || imgData.HasMask() )
198 bmp.
size = bmp.
w * bmp.
h * 4;
199 auto buf = std::make_unique<uint8_t[]>( bmp.
size );
201 uint8_t* dstP = buf.get();
202 uint8_t* srcP = imgData.GetData();
204 long long pxCount =
static_cast<long long>( bmp.
w ) * bmp.
h;
206 if( imgData.HasAlpha() )
208 uint8_t* srcAlpha = imgData.GetAlpha();
210 for(
long long px = 0; px < pxCount; px++ )
212 memcpy( dstP, srcP, 3 );
220 else if( imgData.HasMask() )
222 uint8_t maskRed = imgData.GetMaskRed();
223 uint8_t maskGreen = imgData.GetMaskGreen();
224 uint8_t maskBlue = imgData.GetMaskBlue();
226 for(
long long px = 0; px < pxCount; px++ )
228 memcpy( dstP, srcP, 3 );
230 if( srcP[0] == maskRed && srcP[1] == maskGreen && srcP[2] == maskBlue )
231 dstP[3] = wxALPHA_TRANSPARENT;
233 dstP[3] = wxALPHA_OPAQUE;
240 glBindTexture( GL_TEXTURE_2D, textureID );
241 glTexImage2D( GL_TEXTURE_2D, 0, GL_RGBA8, bmp.
w, bmp.
h, 0, GL_RGBA, GL_UNSIGNED_BYTE,
246 bmp.
size = bmp.
w * bmp.
h * 3;
248 uint8_t* srcP = imgData.GetData();
250 glBindTexture( GL_TEXTURE_2D, textureID );
251 glTexImage2D( GL_TEXTURE_2D, 0, GL_RGB8, bmp.
w, bmp.
h, 0, GL_RGB, GL_UNSIGNED_BYTE, srcP );
254 glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST );
255 glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST );
257 long long currentTime = wxGetUTCTimeMillis().GetValue();
262#ifndef DISABLE_BITMAP_CACHE
270 for(
const auto& [kiid, cachedBmp] :
m_bitmaps )
272 const int cacheTimeoutMillis = 1000L;
274 if( currentTime - cachedBmp.accessTime > cacheTimeoutMillis )
288 toRemove = *toRemoveLru;
294 glDeleteTextures( 1, &cachedBitmap.
id );
312 wxEvtHandler* aMouseListener, wxEvtHandler* aPaintListener,
313 const wxString& aName ) :
314 GAL( aDisplayOptions ),
336 throw std::runtime_error(
"Could not create the main OpenGL context" );
345 throw std::runtime_error(
"Could not create a private OpenGL context" );
390#if defined _WIN32 || defined _WIN64
397 SetSize( aParent->GetClientSize() );
408 gluTessProperty(
m_tesselator, GLU_TESS_WINDING_RULE, GLU_TESS_WINDING_POSITIVE );
478 wxString retVal = wxEmptyString;
480 wxFrame* testFrame =
new wxFrame(
nullptr, wxID_ANY, wxT(
"" ), wxDefaultPosition,
481 wxSize( 1, 1 ), wxFRAME_TOOL_WINDOW | wxNO_BORDER );
496 catch( std::runtime_error& err )
499 retVal = wxString( err.what() );
557#ifdef KICAD_GAL_PROFILE
558 PROF_TIMER totalRealTime(
"OPENGL_GAL::beginDrawing()",
true );
561 wxASSERT_MSG(
m_isContextLocked,
"GAL_DRAWING_CONTEXT RAII object should have locked context. "
562 "Calling GAL::beginDrawing() directly is not allowed." );
564 wxASSERT_MSG(
IsVisible(),
"GAL::beginDrawing() must not be entered when GAL is not visible. "
565 "Other drawing routines will expect everything to be initialized "
566 "which will not be the case." );
572 glMatrixMode( GL_PROJECTION );
588 catch(
const std::runtime_error& )
590 wxLogVerbose(
"Could not create a framebuffer for diff mode blending.\n" );
597 catch(
const std::runtime_error& )
599 wxLogVerbose(
"Could not create a framebuffer for overlays.\n" );
609 glDisable( GL_TEXTURE_2D );
611 glShadeModel( GL_FLAT );
614 glEnable( GL_DEPTH_TEST );
615 glDepthFunc( GL_LESS );
618 glEnable( GL_BLEND );
619 glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );
621 glMatrixMode( GL_MODELVIEW );
625 GLdouble matrixData[16] = { 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1 };
635 glLoadMatrixd( matrixData );
654 const GLint FONT_TEXTURE_UNIT = 2;
659 glActiveTexture( GL_TEXTURE0 + FONT_TEXTURE_UNIT );
664 glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
665 glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
666 checkGlError(
"loading bitmap font", __FILE__, __LINE__ );
668 glActiveTexture( GL_TEXTURE0 );
674 glActiveTexture( GL_TEXTURE0 + FONT_TEXTURE_UNIT );
676 glActiveTexture( GL_TEXTURE0 );
683 checkGlError(
"setting bitmap font sampler as shader parameter", __FILE__, __LINE__ );
693 double pixelSizeMultiplier =
m_compositor->GetAntialiasSupersamplingFactor();
696 renderingOffset.
x *= screenPixelSize.
x;
697 renderingOffset.
y *= screenPixelSize.
y;
704 glActiveTexture( GL_TEXTURE0 );
709#ifdef KICAD_GAL_PROFILE
710 totalRealTime.
Stop();
711 wxLogTrace(
traceGalProfile, wxT(
"OPENGL_GAL::beginDrawing(): %.1f ms" ),
712 totalRealTime.
msecs() );
735 PROF_TIMER cntEndNoncached(
"gl-end-noncached" );
745 cntEndNoncached.
Start();
747 cntEndNoncached.
Stop();
749 cntEndCached.
Start();
753 cntEndOverlay.
Start();
759 cntEndOverlay.
Stop();
761 cntComposite.
Start();
764 glColor4d( 1.0, 1.0, 1.0, 1.0 );
801 wxASSERT_MSG(
m_isContextLocked,
"Context not locked. A GAL_CONTEXT_LOCKER RAII object must "
802 "be stacked rather than making separate lock/unlock calls." );
805 "Context was locked by a different client. "
806 "Should not be possible with RAII objects." );
816 wxASSERT_MSG(
m_isContextLocked,
"GAL_UPDATE_CONTEXT RAII object should have locked context. "
817 "Calling this from anywhere else is not allowed." );
819 wxASSERT_MSG(
IsVisible(),
"GAL::beginUpdate() must not be entered when GAL is not visible. "
820 "Other update routines will expect everything to be initialized "
821 "which will not be the case." );
857 VECTOR2D startEndVector = aEndPoint - aStartPoint;
864 float startX =
static_cast<float>( aStartPoint.
x );
865 float startY =
static_cast<float>( aStartPoint.
y );
866 float endX =
static_cast<float>( aEndPoint.
x );
867 float endY =
static_cast<float>( aEndPoint.
y );
869 if( startX == endX && startY == endY )
871 drawCircle( aStartPoint, aWidth / 2, aReserve );
1006 double startAngle = aStartAngle.
AsRadians();
1007 double endAngle = startAngle + aAngle.
AsRadians();
1024 for( alpha = startAngle; ( alpha + alphaIncrement ) < endAngle; )
1030 alpha += alphaIncrement;
1036 const VECTOR2D endPoint( cos( endAngle ) * aRadius, sin( endAngle ) * aRadius );
1049 VECTOR2D p( cos( startAngle ) * aRadius, sin( startAngle ) * aRadius );
1051 unsigned int lineCount = 0;
1053 for( alpha = startAngle + alphaIncrement; alpha <= endAngle; alpha += alphaIncrement )
1056 if( alpha != endAngle )
1061 for( alpha = startAngle + alphaIncrement; alpha <= endAngle; alpha += alphaIncrement )
1063 VECTOR2D p_next( cos( alpha ) * aRadius, sin( alpha ) * aRadius );
1070 if( alpha != endAngle )
1072 VECTOR2D p_last( cos( endAngle ) * aRadius, sin( endAngle ) * aRadius );
1083 double aWidth,
double aMaxError )
1094 double startAngle = aStartAngle.
AsRadians();
1095 double endAngle = startAngle + aAngle.
AsRadians();
1103 double alphaIncrement = 2.0 *
M_PI / segCount360;
1108 int seg_count =
KiROUND( ( endAngle - startAngle ) / alphaIncrement );
1110 if( seg_count % 2 != 0 )
1114 if( seg_count == 0 )
1116 VECTOR2D p_start( aCenterPoint.
x + cos( startAngle ) * aRadius,
1117 aCenterPoint.
y + sin( startAngle ) * aRadius );
1119 VECTOR2D p_end( aCenterPoint.
x + cos( endAngle ) * aRadius,
1120 aCenterPoint.
y + sin( endAngle ) * aRadius );
1127 alphaIncrement = ( endAngle - startAngle ) / seg_count;
1137 double width = aWidth / 2.0;
1138 VECTOR2D startPoint( cos( startAngle ) * aRadius, sin( startAngle ) * aRadius );
1139 VECTOR2D endPoint( cos( endAngle ) * aRadius, sin( endAngle ) * aRadius );
1144 VECTOR2D pOuter( cos( startAngle ) * ( aRadius + width ),
1145 sin( startAngle ) * ( aRadius + width ) );
1147 VECTOR2D pInner( cos( startAngle ) * ( aRadius - width ),
1148 sin( startAngle ) * ( aRadius - width ) );
1152 for( alpha = startAngle + alphaIncrement; alpha <= endAngle; alpha += alphaIncrement )
1154 VECTOR2D pNextOuter( cos( alpha ) * ( aRadius + width ),
1155 sin( alpha ) * ( aRadius + width ) );
1156 VECTOR2D pNextInner( cos( alpha ) * ( aRadius - width ),
1157 sin( alpha ) * ( aRadius - width ) );
1162 pOuter = pNextOuter;
1163 pInner = pNextInner;
1167 if( alpha != endAngle )
1169 VECTOR2D pLastOuter( cos( endAngle ) * ( aRadius + width ),
1170 sin( endAngle ) * ( aRadius + width ) );
1171 VECTOR2D pLastInner( cos( endAngle ) * ( aRadius - width ),
1172 sin( endAngle ) * ( aRadius - width ) );
1184 VECTOR2D p( cos( startAngle ) * aRadius, sin( startAngle ) * aRadius );
1189 for( alpha = startAngle + alphaIncrement; alpha <= endAngle; alpha += alphaIncrement )
1195 if( alpha != endAngle )
1202 for( alpha = startAngle + alphaIncrement; alpha <= endAngle; alpha += alphaIncrement )
1204 VECTOR2D p_next( cos( alpha ) * aRadius, sin( alpha ) * aRadius );
1211 if( alpha != endAngle )
1213 VECTOR2D p_last( cos( endAngle ) * aRadius, sin( endAngle ) * aRadius );
1225 VECTOR2D diagonalPointA( aEndPoint.
x, aStartPoint.
y );
1226 VECTOR2D diagonalPointB( aStartPoint.
x, aEndPoint.
y );
1252 if( aStartPoint == aEndPoint )
1258 std::deque<VECTOR2D> pointList;
1260 pointList.push_back( aStartPoint );
1261 pointList.push_back( diagonalPointA );
1262 pointList.push_back( aEndPoint );
1263 pointList.push_back( diagonalPointB );
1264 pointList.push_back( aStartPoint );
1276 return aPointList[idx];
1278 aPointList.size(), aWidth );
1292 return aLineChain.
CPoint( idx );
1294 numPoints, aWidth );
1303 return aPointList[idx];
1305 aPointList.size() );
1314 return aPointList[idx];
1316 aPointList.size() );
1325 return aPointList[idx];
1341 return aLineChain.
CPoint( idx );
1349 int lineQuadCount = 0;
1351 for(
const std::vector<VECTOR2D>& points : aPointList )
1352 lineQuadCount += points.size() - 1;
1356 for(
const std::vector<VECTOR2D>& points : aPointList )
1363 points.size(),
false );
1370 wxCHECK( aPointList.size() >= 2, );
1371 auto points = std::unique_ptr<GLdouble[]>(
new GLdouble[3 * aPointList.size()] );
1372 GLdouble* ptr = points.get();
1374 for(
const VECTOR2D& p : aPointList )
1387 wxCHECK( aListSize >= 2, );
1388 auto points = std::unique_ptr<GLdouble[]>(
new GLdouble[3 * aListSize] );
1389 GLdouble* target = points.get();
1392 for(
int i = 0; i < aListSize; ++i )
1405 bool aStrokeTriangulation )
1412 int totalTriangleCount = 0;
1427 for(
size_t i = 0; i < triPoly->GetTriangleCount(); i++ )
1430 triPoly->GetTriangle( i, a, b, c );
1442 const auto& poly = aPolySet.
Polygon( j );
1444 for(
const auto& lc : poly )
1453 aStrokeTriangulation =
true;
1457 if( aStrokeTriangulation )
1466 for(
size_t i = 0; i < triPoly->GetTriangleCount(); i++ )
1469 triPoly->GetTriangle( i, a, b, c );
1501 std::unique_ptr<GLdouble[]> points(
new GLdouble[3 * pointCount] );
1502 GLdouble* ptr = points.get();
1504 for(
int i = 0; i < pointCount; ++i )
1518 double aFilterValue )
1520 std::vector<VECTOR2D> output;
1521 std::vector<VECTOR2D> pointCtrl;
1523 pointCtrl.push_back( aStartPoint );
1524 pointCtrl.push_back( aControlPointA );
1525 pointCtrl.push_back( aControlPointB );
1526 pointCtrl.push_back( aEndPoint );
1529 converter.
GetPoly( output, aFilterValue );
1531 if( output.size() == 1 )
1532 output.push_back( output.front() );
1540 GLfloat alpha = std::clamp( alphaBlend, 0.0, 1.0 );
1550 glm::vec4 v0 = xform * glm::vec4( -w / 2, -h / 2, 0.0, 0.0 );
1551 glm::vec4
v1 = xform * glm::vec4( w / 2, h / 2, 0.0, 0.0 );
1552 glm::vec4 trans = xform[3];
1556 if( !glIsTexture( texture_id ) )
1559 GLboolean depthMask = GL_TRUE;
1560 glGetBooleanv( GL_DEPTH_WRITEMASK, &depthMask );
1563 glDepthMask( GL_FALSE );
1565 glDepthFunc( GL_ALWAYS );
1567 glAlphaFunc( GL_GREATER, 0.01f );
1568 glEnable( GL_ALPHA_TEST );
1570 glMatrixMode( GL_TEXTURE );
1572 glTranslated( 0.5, 0.5, 0.5 );
1574 glTranslated( -0.5, -0.5, -0.5 );
1576 glMatrixMode( GL_MODELVIEW );
1578 glTranslated( trans.x, trans.y, trans.z );
1580 glEnable( GL_TEXTURE_2D );
1581 glActiveTexture( GL_TEXTURE0 );
1582 glBindTexture( GL_TEXTURE_2D, texture_id );
1584 float texStartX = aBitmap.
IsMirroredX() ? 1.0 : 0.0;
1585 float texEndX = aBitmap.
IsMirroredX() ? 0.0 : 1.0;
1586 float texStartY = aBitmap.
IsMirroredY() ? 1.0 : 0.0;
1587 float texEndY = aBitmap.
IsMirroredY() ? 0.0 : 1.0;
1589 glBegin( GL_QUADS );
1590 glColor4f( 1.0, 1.0, 1.0, alpha );
1591 glTexCoord2f( texStartX, texStartY );
1593 glColor4f( 1.0, 1.0, 1.0, alpha );
1594 glTexCoord2f( texEndX, texStartY);
1596 glColor4f( 1.0, 1.0, 1.0, alpha );
1597 glTexCoord2f( texEndX, texEndY);
1599 glColor4f( 1.0, 1.0, 1.0, alpha );
1600 glTexCoord2f( texStartX, texEndY);
1604 glBindTexture( GL_TEXTURE_2D, 0 );
1606#ifdef DISABLE_BITMAP_CACHE
1607 glDeleteTextures( 1, &texture_id );
1612 glMatrixMode( GL_TEXTURE );
1614 glMatrixMode( GL_MODELVIEW );
1616 glDisable( GL_ALPHA_TEST );
1618 glDepthMask( depthMask );
1620 glDepthFunc( GL_LESS );
1629 || aText.Contains( wxT(
"^{" ) )
1630 || aText.Contains( wxT(
"_{" ) )
1631 || aText.Contains( wxT(
"\n" ) ) )
1642 double overbarHeight = textSize.
y;
1673 wxFAIL_MSG( wxT(
"Indeterminate state legal only in dialogs." ) );
1689 overbarHeight = -textSize.
y / 2.0;
1693 wxFAIL_MSG( wxT(
"Indeterminate state legal only in dialogs." ) );
1697 int overbarLength = 0;
1698 int overbarDepth = -1;
1699 int braceNesting = 0;
1701 auto iterateString =
1702 [&](
const std::function<void(
int aOverbarLength,
int aOverbarHeight )>& overbarFn,
1703 const std::function<int(
unsigned long aChar )>& bitmapCharFn )
1707 wxASSERT_MSG( *chIt !=
'\n' && *chIt !=
'\r',
1708 "No support for multiline bitmap text yet" );
1710 if( *chIt ==
'~' && overbarDepth == -1 )
1714 if( ++lookahead !=
end && *lookahead ==
'{' )
1717 overbarDepth = braceNesting;
1722 else if( *chIt ==
'{' )
1726 else if( *chIt ==
'}' )
1728 if( braceNesting > 0 )
1731 if( braceNesting == overbarDepth )
1733 overbarFn( overbarLength, overbarHeight );
1741 if( overbarDepth != -1 )
1742 overbarLength += bitmapCharFn( *chIt );
1744 bitmapCharFn( *chIt );
1751 int overbarsCount = 0;
1754 [&overbarsCount](
int aOverbarLength,
int aOverbarHeight )
1758 [&charsCount](
unsigned long aChar ) ->
int
1774 [&](
int aOverbarLength,
int aOverbarHeight )
1778 [&](
unsigned long aChar ) ->
int
1786 if( overbarDepth != -1 && overbarLength > 0 )
1801 float minorLineWidth = std::fmax( 1.0f,
1803 float majorLineWidth = minorLineWidth * 2.0f;
1847 glDisable( GL_DEPTH_TEST );
1848 glDisable( GL_TEXTURE_2D );
1852 glEnable( GL_STENCIL_TEST );
1853 glStencilFunc( GL_ALWAYS, 1, 1 );
1854 glStencilOp( GL_KEEP, GL_KEEP, GL_INCR );
1855 glColor4d( 0.0, 0.0, 0.0, 0.0 );
1867 for(
int j = gridStartY; j <= gridEndY; j++ )
1873 for(
int i = gridStartX; i <= gridEndX; i++ )
1876 SetLineWidth( ( ( tickX && tickY ) ? majorLineWidth : minorLineWidth ) );
1890 for(
int j = gridStartY; j <= gridEndY; j++ )
1909 glStencilFunc( GL_NOTEQUAL, 0, 1 );
1915 for(
int i = gridStartX; i <= gridEndX; i++ )
1932 glDisable( GL_STENCIL_TEST );
1936 glEnable( GL_DEPTH_TEST );
1937 glEnable( GL_TEXTURE_2D );
1947 m_compositor->Resize( aWidth * scaleFactor, aHeight * scaleFactor );
1950 wxGLCanvas::SetSize( aWidth, aHeight );
1956 bool s = wxGLCanvas::Show( aShow );
1959 wxGLCanvas::Raise();
1977 glClearColor( 0, 0, 0, 1 );
1978 glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT );
1984 GLdouble matrixData[16] = { 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1 };
1986 matrixData[0] = aTransformation.
m_data[0][0];
1987 matrixData[1] = aTransformation.
m_data[1][0];
1988 matrixData[2] = aTransformation.
m_data[2][0];
1989 matrixData[4] = aTransformation.
m_data[0][1];
1990 matrixData[5] = aTransformation.
m_data[1][1];
1991 matrixData[6] = aTransformation.
m_data[2][1];
1992 matrixData[12] = aTransformation.
m_data[0][2];
1993 matrixData[13] = aTransformation.
m_data[1][2];
1994 matrixData[14] = aTransformation.
m_data[2][2];
1996 glMultMatrixd( matrixData );
2034 std::shared_ptr<VERTEX_ITEM> newItem = std::make_shared<VERTEX_ITEM>( *
m_cachedManager );
2036 m_groups.insert( std::make_pair( groupNumber, newItem ) );
2165 wxLogTrace(
traceGalXorMode, wxT(
"OPENGL_GAL::StartDiffLayer() called" ) );
2172 wxLogTrace(
traceGalXorMode, wxT(
"StartDiffLayer(): setting target to TARGET_TEMP" ) );
2179 wxLogTrace(
traceGalXorMode, wxT(
"StartDiffLayer(): TARGET_TEMP set and cleared, compositor buffer=%u" ),
2184 wxLogTrace(
traceGalXorMode, wxT(
"StartDiffLayer(): WARNING - no temp buffer!" ) );
2191 wxLogTrace(
traceGalXorMode, wxT(
"OPENGL_GAL::EndDiffLayer() called" ) );
2192 wxLogTrace(
traceGalXorMode, wxT(
"EndDiffLayer(): m_tempBuffer=%u, m_mainBuffer=%u" ),
2197 wxLogTrace(
traceGalXorMode, wxT(
"EndDiffLayer(): using temp buffer path" ) );
2202 wxLogTrace(
traceGalXorMode, wxT(
"EndDiffLayer(): calling DrawBufferDifference" ) );
2210 wxLogTrace(
traceGalXorMode, wxT(
"EndDiffLayer(): DrawBufferDifference returned" ) );
2214 wxLogTrace(
traceGalXorMode, wxT(
"EndDiffLayer(): NO temp buffer, using fallback path" ) );
2217 glBlendFunc( GL_SRC_ALPHA, GL_ONE );
2219 glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );
2222 wxLogTrace(
traceGalXorMode, wxT(
"OPENGL_GAL::EndDiffLayer() complete" ) );
2234#if wxCHECK_VERSION( 3, 3, 0 )
2246#if wxCHECK_VERSION( 3, 3, 0 )
2265 const bool aReserve )
2283 * glm::vec4( aStartPoint.
x, aStartPoint.
y, 0.0, 0.0 );
2285 * glm::vec4( aEndPoint.
x, aEndPoint.
y, 0.0, 0.0 );
2369 double outerRadius = aRadius + (
m_lineWidth / 2 );
2415 GLdouble* point = aPoints;
2417 for(
int i = 0; i < aPointCount; ++i )
2435 return VECTOR2D( aPoints[idx * 3], aPoints[idx * 3 + 1] );
2445 wxCHECK( aPointCount > 0, );
2449 if( aPointCount == 1 )
2451 drawLineQuad( aPointGetter( 0 ), aPointGetter( 0 ), aReserve );
2460 for(
int i = 1; i < aPointCount; ++i )
2462 auto start = aPointGetter( i - 1 );
2463 auto end = aPointGetter( i );
2471 int aPointCount,
double aWidth,
bool aReserve )
2473 wxCHECK( aPointCount >= 2, );
2479 for(
int i = 1; i < aPointCount; ++i )
2481 auto start = aPointGetter( i - 1 );
2482 auto end = aPointGetter( i );
2484 float startx = start.x;
2485 float starty = start.y;
2494 if( startx == endx && starty == endy )
2506 vertices += 6 + 6 + 3 + 3;
2512 for(
int i = 1; i < aPointCount; ++i )
2514 auto start = aPointGetter( i - 1 );
2515 auto end = aPointGetter( i );
2534 double spaceWidth = g->
advance * 0.74;
2552 const float XOFF = glyph->
minx;
2555 const float round_adjust = ( glyph->
maxy - glyph->
miny )
2558 const float YOFF = round_adjust + top_adjust;
2607 const float H = glyph->
maxy - glyph->
miny;
2637 float commonOffset = std::numeric_limits<float>::max();
2639 int overbarDepth = -1;
2640 int braceNesting = 0;
2644 if( *chIt ==
'~' && overbarDepth == -1 )
2648 if( ++lookahead !=
end && *lookahead ==
'{' )
2651 overbarDepth = braceNesting;
2656 else if( *chIt ==
'{' )
2660 else if( *chIt ==
'}' )
2662 if( braceNesting > 0 )
2665 if( braceNesting == overbarDepth )
2675 || *chIt ==
'-' || *chIt ==
'_' )
2677 glyph = defaultGlyph;
2684 textSize.
y = std::max<float>( textSize.
y, charHeight );
2686 textSize.
y -= commonOffset;
2688 return std::make_pair( textSize, commonOffset );
2732 const int cursorSize = 80;
2739 GLboolean depthTestEnabled = glIsEnabled( GL_DEPTH_TEST );
2740 glDisable( GL_DEPTH_TEST );
2742 glActiveTexture( GL_TEXTURE0 );
2743 glDisable( GL_TEXTURE_2D );
2744 glEnable( GL_BLEND );
2745 glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );
2748 glColor4d( color.
r, color.
g, color.
b, color.
a );
2750 glMatrixMode( GL_PROJECTION );
2752 glTranslated( 0, 0, -0.5 );
2754 glBegin( GL_LINES );
2769 double offset1 = cy - cx;
2770 VECTOR2D pos_start( screenTopLeft.
x, screenTopLeft.
x + offset1 );
2771 VECTOR2D pos_end( screenBottomRight.
x, screenBottomRight.
x + offset1 );
2774 glVertex2d( pos_start.
x, pos_start.
y );
2775 glVertex2d( pos_end.
x, pos_end.
y );
2778 double offset2 = cy + cx;
2779 VECTOR2D neg_start( screenTopLeft.
x, offset2 - screenTopLeft.
x );
2780 VECTOR2D neg_end( screenBottomRight.
x, offset2 - screenBottomRight.
x );
2783 glVertex2d( neg_start.
x, neg_start.
y );
2784 glVertex2d( neg_end.
x, neg_end.
y );
2788 glVertex2d( cursorCenter.
x, cursorBegin.
y );
2789 glVertex2d( cursorCenter.
x, cursorEnd.
y );
2791 glVertex2d( cursorBegin.
x, cursorCenter.
y );
2792 glVertex2d( cursorEnd.
x, cursorCenter.
y );
2799 if( depthTestEnabled )
2800 glEnable( GL_DEPTH_TEST );
2806 wxASSERT_MSG(
m_groups.size() < std::numeric_limits<unsigned int>::max(),
2807 wxT(
"There are no free slots to store a group" ) );
2818#ifndef KICAD_USE_EGL
2819 wxASSERT( IsShownOnScreen() );
2822 wxASSERT_MSG(
m_isContextLocked,
"This should only be called from within a locked context." );
2826 throw std::runtime_error(
"Could not create the tesselator" );
2830 GLenum err = glewInit();
2834 for(
int i = 0; i < 10; i++ )
2836 if( GLEW_OK == err )
2839 std::this_thread::sleep_for( std::chrono::milliseconds( 250 ) );
2845 if( GLEW_OK != err )
2846 throw std::runtime_error( (
const char*) glewGetErrorString( err ) );
2848 SetOpenGLInfo( (
const char*) glGetString( GL_VENDOR ), (
const char*) glGetString( GL_RENDERER ),
2849 (
const char*) glGetString( GL_VERSION ) );
2852 if( !GLEW_VERSION_2_1 )
2853 throw std::runtime_error(
"OpenGL 2.1 or higher is required!" );
2855#if defined( __LINUX__ )
2857 if( GLEW_ARB_debug_output )
2863 if( !GLEW_EXT_framebuffer_object )
2864 throw std::runtime_error(
"Framebuffer objects are not supported!" );
2867 if( !GLEW_ARB_vertex_buffer_object )
2868 throw std::runtime_error(
"Vertex buffer objects are not supported!" );
2873 BUILTIN_SHADERS::glsl_kicad_vert ) )
2875 throw std::runtime_error(
"Cannot compile vertex shader!" );
2880 BUILTIN_SHADERS::glsl_kicad_frag ) )
2882 throw std::runtime_error(
"Cannot compile fragment shader!" );
2886 throw std::runtime_error(
"Cannot link the shaders!" );
2893 glGetIntegerv( GL_MAX_TEXTURE_SIZE, &maxTextureSize );
2899 throw std::runtime_error(
"Requested texture size is not supported" );
2902#if wxCHECK_VERSION( 3, 3, 3 )
2903 wxGLCanvas::SetSwapInterval( -1 );
2940 GLdouble* vertex =
static_cast<GLdouble*
>( aVertexPtr );
2944 assert( vboManager );
2945 vboManager->
Vertex( vertex[0], vertex[1], vertex[2] );
2950 GLdouble** dataOut,
void* aData )
2952 GLdouble* vertex =
new GLdouble[3];
2958 param->
intersectPoints.emplace_back( vertex, std::default_delete<GLdouble[]>() );
2960 memcpy( vertex, coords, 3 *
sizeof( GLdouble ) );
2998 return ( ceil( f / r ) - 0.5 ) * r;
3031 outlineGlyph.Triangulate(
3046 if( aGlyphs.empty() )
3049 bool allGlyphsAreStroke =
true;
3050 bool allGlyphsAreOutline =
true;
3052 for(
const std::unique_ptr<KIFONT::GLYPH>& glyph : aGlyphs )
3054 if( !glyph->IsStroke() )
3056 allGlyphsAreStroke =
false;
3061 for(
const std::unique_ptr<KIFONT::GLYPH>& glyph : aGlyphs )
3063 if( !glyph->IsOutline() )
3065 allGlyphsAreOutline =
false;
3070 if( allGlyphsAreStroke )
3073 int lineQuadCount = 0;
3075 for(
const std::unique_ptr<KIFONT::GLYPH>& glyph : aGlyphs )
3079 for(
const std::vector<VECTOR2D>& points : strokeGlyph )
3080 lineQuadCount += points.size() - 1;
3085 for(
const std::unique_ptr<KIFONT::GLYPH>& glyph : aGlyphs )
3089 for(
const std::vector<VECTOR2D>& points : strokeGlyph )
3096 points.size(),
false );
3102 else if( allGlyphsAreOutline )
3105 int triangleCount = 0;
3107 for(
const std::unique_ptr<KIFONT::GLYPH>& glyph : aGlyphs )
3111 for(
unsigned int i = 0; i < outlineGlyph.TriangulatedPolyCount(); i++ )
3114 outlineGlyph.TriangulatedPolygon( i );
3125 for(
const std::unique_ptr<KIFONT::GLYPH>& glyph : aGlyphs )
3129 for(
unsigned int i = 0; i < outlineGlyph.TriangulatedPolyCount(); i++ )
3132 outlineGlyph.TriangulatedPolygon( i );
3149 for(
size_t i = 0; i < aGlyphs.size(); i++ )
3150 DrawGlyph( *aGlyphs[i], i, aGlyphs.size() );
constexpr BOX2I KiROUND(const BOX2D &aBoxD)
void SetOpenGLInfo(const char *aVendor, const char *aRenderer, const char *aVersion)
A setter for OpenGL info when it's initialized.
void SetOpenGLBackendInfo(wxString aBackend)
A setter for OpenGL backend info after the canvas is created.
static const ADVANCED_CFG & GetCfg()
Get the singleton instance's config, which is shared by all consumers.
Bezier curves to polygon converter.
void GetPoly(std::vector< VECTOR2I > &aOutput, int aMaxError=10)
Convert a Bezier curve to a polygon.
This class handle bitmap images in KiCad.
const wxImage * GetOriginalImageData() const
VECTOR2I GetSizePixels() const
EDA_ANGLE Rotation() const
static const WX_CURSOR_TYPE GetCursor(KICURSOR aCursorType, bool aHiDPI=false)
Get a cursor bundle (wx 3.3+) or appropriate cursor (older versions)
void UnlockCtx(wxGLContext *aContext)
Allow other canvases to bind an OpenGL context.
void DestroyCtx(wxGLContext *aContext)
Destroy a managed OpenGL context.
void LockCtx(wxGLContext *aContext, wxGLCanvas *aCanvas)
Set a context as current and prevents other canvases from switching it.
wxGLContext * CreateCtx(wxGLCanvas *aCanvas, const wxGLContext *aOther=nullptr)
Create a managed OpenGL context.
static wxString DetectGLBackend(wxGLCanvas *aCanvas)
static int SetSwapInterval(int aVal)
Attempt to set the OpenGL swap interval.
HIDPI_GL_CANVAS(const KIGFX::VC_SETTINGS &aSettings, wxWindow *aParent, const wxGLAttributes &aGLAttribs, wxWindowID aId=wxID_ANY, const wxPoint &aPos=wxDefaultPosition, const wxSize &aSize=wxDefaultSize, long aStyle=0, const wxString &aName=wxGLCanvasName, const wxPalette &aPalette=wxNullPalette)
virtual wxSize GetNativePixelSize() const
double GetScaleFactor() const
Get the current scale factor.
virtual bool IsStroke() const
virtual bool IsOutline() const
A color representation with 4 components: red, green, blue, alpha.
static const COLOR4D BLACK
bool IsTextMirrored() const
void SetGridColor(const COLOR4D &aGridColor)
Set the grid color.
virtual void SetLayerDepth(double aLayerDepth)
Set the depth of the layer (position on the z-axis)
bool IsCursorEnabled() const
Return information about cursor visibility.
friend class GAL_CONTEXT_LOCKER
MATRIX3x3D m_worldScreenMatrix
World transformation.
VECTOR2D GetVisibleGridSize() const
Return the visible grid size in x and y directions.
double m_layerDepth
The actual layer depth.
MATRIX3x3D m_screenWorldMatrix
Screen transformation.
friend class GAL_SCOPED_ATTRS
bool m_axesEnabled
Should the axes be drawn.
float m_gridLineWidth
Line width of the grid.
VECTOR2I m_screenSize
Screen size in screen (wx logical) coordinates.
GR_TEXT_H_ALIGN_T GetHorizontalJustify() const
void normalize(T &a, T &b)
Ensure that the first element is smaller than the second.
VECTOR2D m_depthRange
Range of the depth.
virtual void SetFillColor(const COLOR4D &aColor)
Set the fill color.
virtual bool SetNativeCursorStyle(KICURSOR aCursor, bool aHiDPI)
Set the cursor in the native panel.
GRID_STYLE m_gridStyle
Grid display style.
COLOR4D m_axesColor
Color of the axes.
const MATRIX3x3D & GetScreenWorldMatrix() const
Get the screen <-> world transformation matrix.
float m_lineWidth
The line width.
void computeWorldScale()
Compute the scaling factor for the world->screen matrix.
virtual void SetLineWidth(float aLineWidth)
Set the line width.
VECTOR2D m_gridSize
The grid size.
COLOR4D getCursorColor() const
Get the actual cursor color to draw.
COLOR4D m_fillColor
The fill color.
double m_worldUnitLength
The unit length of the world coordinates [inch].
virtual bool updatedGalDisplayOptions(const GAL_DISPLAY_OPTIONS &aOptions)
Handle updating display options.
void SetAxesColor(const COLOR4D &aAxesColor)
Set the axes color.
virtual void SetStrokeColor(const COLOR4D &aColor)
Set the stroke color.
VECTOR2D m_cursorPosition
Current cursor position (world coordinates)
const VECTOR2I & GetGlyphSize() const
int m_gridTick
Every tick line gets the double width.
double m_worldScale
The scale factor world->screen.
VECTOR2D m_gridOrigin
The grid origin.
virtual void SetMinLineWidth(float aLineWidth)
Set the minimum line width in pixels.
KICURSOR m_currentNativeCursor
Current cursor.
bool m_globalFlipY
Flag for Y axis flipping.
float GetMinLineWidth() const
Get the minimum line width in pixels.
bool m_isFillEnabled
Is filling of graphic objects enabled ?
virtual void ComputeWorldScreenMatrix()
Compute the world <-> screen transformation matrix.
COLOR4D m_gridColor
Color of the grid.
COLOR4D m_strokeColor
The color of the outlines.
bool m_isStrokeEnabled
Are the outlines stroked ?
GAL_DISPLAY_OPTIONS & m_options
bool m_gridVisibility
Should the grid be shown.
virtual void BitmapText(const wxString &aText, const VECTOR2I &aPosition, const EDA_ANGLE &aAngle)
Draw a text using a bitmap font.
float GetLineWidth() const
Get the line width.
bool m_globalFlipX
Flag for X axis flipping.
GR_TEXT_V_ALIGN_T GetVerticalJustify() const
KIGFX::CROSS_HAIR_MODE m_crossHairMode
Crosshair drawing mode.
VECTOR2D m_lookAtPoint
Point to be looked at in world space.
GAL(GAL_DISPLAY_OPTIONS &aOptions)
GLuint cacheBitmap(const BITMAP_BASE *aBitmap)
const size_t m_cacheMaxElements
GLuint RequestBitmap(const BITMAP_BASE *aBitmap)
std::list< GLuint > m_freedTextureIds
const size_t m_cacheMaxSize
std::map< const KIID, CACHED_BITMAP > m_bitmaps
std::list< KIID > m_cacheLru
static const unsigned int DIRECT_RENDERING
OpenGL implementation of the Graphics Abstraction Layer.
void Transform(const MATRIX3x3D &aTransformation) override
Transform the context.
void drawPolygon(GLdouble *aPoints, int aPointCount)
Draw a filled polygon.
void ChangeGroupDepth(int aGroupNumber, int aDepth) override
Change the depth (Z-axis position) of the group.
void skipMouseEvent(wxMouseEvent &aEvent)
Skip the mouse event to the parent.
void drawSegment(const VECTOR2D &aStartPoint, const VECTOR2D &aEndPoint, double aWidth, bool aReserve=true)
Internal method for segment drawing.
unsigned int m_groupCounter
Counter used for generating keys for groups.
void EndDiffLayer() override
Ends rendering of a differential layer.
VERTEX_MANAGER * m_overlayManager
Container for storing overlaid VERTEX_ITEMs.
void Scale(const VECTOR2D &aScale) override
Scale the context.
bool m_isInitialized
Basic initialization flag, has to be done when the window is visible.
VERTEX_MANAGER * m_currentManager
Currently used VERTEX_MANAGER (for storing VERTEX_ITEMs).
void drawCircle(const VECTOR2D &aCenterPoint, double aRadius, bool aReserve=true)
Internal method for circle drawing.
std::deque< std::shared_ptr< GLdouble > > m_tessIntersects
void DrawCircle(const VECTOR2D &aCenterPoint, double aRadius) override
Draw a circle using world coordinates.
void LockContext(int aClientCookie) override
Use GAL_CONTEXT_LOCKER RAII object unless you know what you're doing.
WX_CURSOR_TYPE m_currentwxCursor
wx cursor showing the current native cursor.
unsigned int m_mainBuffer
Main rendering target.
std::unique_ptr< GL_BITMAP_CACHE > m_bitmapCache
std::pair< VECTOR2D, float > computeBitmapTextSize(const UTF8 &aText) const
Compute a size of text drawn using bitmap font with current text setting applied.
void SetTarget(RENDER_TARGET aTarget) override
Set the target for rendering.
void blitCursor()
Blit cursor into the current screen.
static wxString CheckFeatures(GAL_DISPLAY_OPTIONS &aOptions)
Checks OpenGL features.
void ClearTarget(RENDER_TARGET aTarget) override
Clear the target for rendering.
void drawBitmapOverbar(double aLength, double aHeight, bool aReserve=true)
Draw an overbar over the currently drawn text.
void EndGroup() override
End the group.
bool m_isBitmapFontInitialized
Is the shader set to use bitmap fonts?
void drawSegmentChain(const std::function< VECTOR2D(int)> &aPointGetter, int aPointCount, double aWidth, bool aReserve=true)
Generic way of drawing a chain of segments stored in different containers.
void DrawArcSegment(const VECTOR2D &aCenterPoint, double aRadius, const EDA_ANGLE &aStartAngle, const EDA_ANGLE &aAngle, double aWidth, double aMaxError) override
Draw an arc segment.
void BitmapText(const wxString &aText, const VECTOR2I &aPosition, const EDA_ANGLE &aAngle) override
Draw a text using a bitmap font.
bool updatedGalDisplayOptions(const GAL_DISPLAY_OPTIONS &aOptions) override
Handle updating display options.
unsigned int m_overlayBuffer
Auxiliary rendering target (for menus etc.)
void PostPaint(wxPaintEvent &aEvent)
Post an event to #m_paint_listener.
OPENGL_COMPOSITOR * m_compositor
Handles multiple rendering targets.
VERTEX_MANAGER * m_cachedManager
Container for storing cached VERTEX_ITEMs.
void Translate(const VECTOR2D &aTranslation) override
Translate the context.
void DrawPolyline(const std::deque< VECTOR2D > &aPointList) override
Draw a polyline.
bool SetNativeCursorStyle(KICURSOR aCursor, bool aHiDPI) override
Set the cursor in the native panel.
void DrawCurve(const VECTOR2D &startPoint, const VECTOR2D &controlPointA, const VECTOR2D &controlPointB, const VECTOR2D &endPoint, double aFilterValue=0.0) override
Draw a cubic bezier spline.
void drawFilledSemiCircle(const VECTOR2D &aCenterPoint, double aRadius, double aAngle)
Draw a filled semicircle.
void onPaint(wxPaintEvent &aEvent)
This is the OnPaint event handler.
void DrawGroup(int aGroupNumber) override
Draw the stored group.
GLint ufm_minLinePixelWidth
void Restore() override
Restore the context.
void DrawSegmentChain(const std::vector< VECTOR2D > &aPointList, double aWidth) override
Draw a chain of rounded segments.
void drawStrokedSemiCircle(const VECTOR2D &aCenterPoint, double aRadius, double aAngle, bool aReserve=true)
Draw a stroked semicircle.
unsigned int getNewGroupNumber()
Return a valid key that can be used as a new group number.
void Flush() override
Force all remaining objects to be drawn.
GLint ufm_antialiasingOffset
void DeleteGroup(int aGroupNumber) override
Delete the group from the memory.
bool IsVisible() const override
Return true if the GAL canvas is visible on the screen.
wxEvtHandler * m_mouseListener
int m_swapInterval
Used to store swap interval information.
void ClearCache() override
Delete all data created during caching of graphic items.
double getWorldPixelSize() const
void DrawSegment(const VECTOR2D &aStartPoint, const VECTOR2D &aEndPoint, double aWidth) override
Draw a rounded segment.
GROUPS_MAP m_groups
Stores information about VBO objects (groups)
void endUpdate() override
void ClearScreen() override
Clear the screen.
void ResizeScreen(int aWidth, int aHeight) override
Resizes the canvas.
GLint ufm_fontTextureWidth
void DrawPolygon(const std::deque< VECTOR2D > &aPointList) override
Draw a polygon.
void drawTriangulatedPolyset(const SHAPE_POLY_SET &aPoly, bool aStrokeTriangulation)
Draw a set of polygons with a cached triangulation.
void DrawCursor(const VECTOR2D &aCursorPosition) override
Draw the cursor.
void DrawRectangle(const VECTOR2D &aStartPoint, const VECTOR2D &aEndPoint) override
Draw a rectangle.
VERTEX_MANAGER * m_nonCachedManager
Container for storing non-cached VERTEX_ITEMs.
int drawBitmapChar(unsigned long aChar, bool aReserve=true)
Draw a single character using bitmap font.
GLUtesselator * m_tesselator
wxEvtHandler * m_paintListener
void StartDiffLayer() override
Begins rendering of a differential layer.
bool m_isContextLocked
Used for assertion checking.
void Save() override
Save the context.
void DrawHoleWall(const VECTOR2D &aCenterPoint, double aHoleRadius, double aWallWidth) override
Draw a hole wall ring.
bool m_isFramebufferInitialized
Are the framebuffers initialized?
void ComputeWorldScreenMatrix() override
Compute the world <-> screen transformation matrix.
bool Show(bool aShow) override
Shows/hides the GAL canvas.
void SetMinLineWidth(float aLineWidth) override
Set the minimum line width in pixels.
static GLuint g_fontTexture
Bitmap font texture handle (shared)
virtual bool HasTarget(RENDER_TARGET aTarget) override
Return true if the target exists.
void reserveLineQuads(const int aLineCount)
Reserve specified number of line quads.
void DrawLine(const VECTOR2D &aStartPoint, const VECTOR2D &aEndPoint) override
Draw a line.
OPENGL_GAL(const KIGFX::VC_SETTINGS &aVcSettings, GAL_DISPLAY_OPTIONS &aDisplayOptions, wxWindow *aParent, wxEvtHandler *aMouseListener=nullptr, wxEvtHandler *aPaintListener=nullptr, const wxString &aName=wxT("GLCanvas"))
void beginUpdate() override
double calcAngleStep(double aRadius) const
Compute the angle step when drawing arcs/circles approximated with lines.
virtual void DrawGlyph(const KIFONT::GLYPH &aGlyph, int aNth, int aTotal) override
Draw a polygon representing a font glyph.
bool m_isGrouping
Was a group started?
void BeginDrawing() override
Start/end drawing functions, draw calls can be only made in between the calls to BeginDrawing()/EndDr...
GLint ufm_screenPixelSize
void Rotate(double aAngle) override
Rotate the context.
int BeginGroup() override
Begin a group.
GLint ufm_pixelSizeMultiplier
VECTOR2D getScreenPixelSize() const
void DrawBitmap(const BITMAP_BASE &aBitmap, double alphaBlend=1.0) override
Draw a bitmap image.
void drawPolyline(const std::function< VECTOR2D(int)> &aPointGetter, int aPointCount, bool aReserve=true)
Generic way of drawing a polyline stored in different containers.
RENDER_TARGET GetTarget() const override
Get the currently used target for rendering.
void skipGestureEvent(wxGestureEvent &aEvent)
Skip the gesture event to the parent.
void UnlockContext(int aClientCookie) override
void drawSemiCircle(const VECTOR2D &aCenterPoint, double aRadius, double aAngle)
Draw a semicircle.
void drawLineQuad(const VECTOR2D &aStartPoint, const VECTOR2D &aEndPoint, bool aReserve=true)
Draw a quad for the line.
VERTEX_MANAGER * m_tempManager
Container for storing temp (diff mode) VERTEX_ITEMs.
virtual void DrawGlyphs(const std::vector< std::unique_ptr< KIFONT::GLYPH > > &aGlyphs) override
Draw polygons representing font glyphs.
void onSetNativeCursor(wxSetCursorEvent &aEvent)
Give the correct cursor image when the native widget asks for it.
void EnableDepthTest(bool aEnabled=false) override
void EndDrawing() override
End the drawing, needs to be called for every new frame.
SHADER * m_shader
There is only one shader used for different objects.
void DrawArc(const VECTOR2D &aCenterPoint, double aRadius, const EDA_ANGLE &aStartAngle, const EDA_ANGLE &aAngle) override
Draw an arc.
void DrawPolylines(const std::vector< std::vector< VECTOR2D > > &aPointLists) override
Draw multiple polylines.
RENDER_TARGET m_currentTarget
Current rendering target.
wxGLContext * m_glPrivContext
Canvas-specific OpenGL context.
void ChangeGroupColor(int aGroupNumber, const COLOR4D &aNewColor) override
Change the color used to draw the group.
static bool m_isBitmapFontLoaded
Is the bitmap font texture loaded?
static wxGLContext * m_glMainContext
Parent OpenGL context.
void setupShaderParameters()
Set up the shader parameters for OpenGL rendering.
unsigned int m_tempBuffer
Temporary rendering target (for diffing etc.)
void init()
Basic OpenGL initialization and feature checks.
static int m_instanceCounter
GL GAL instance counter.
Provide the access to the OpenGL shaders.
Class to control vertex container and GPU with possibility of emulating old-style OpenGL 1....
bool Vertex(const VERTEX &aVertex)
Add a vertex with the given coordinates to the currently set item.
VECTOR2< T > GetScale() const
Get the scale components of the matrix.
GL_CONTEXT_MANAGER * GetGLContextManager()
A small class to help profiling.
void Stop()
Save the time when this function was called, and set the counter stane to stop.
void Start()
Start or restart the counter.
double msecs(bool aSinceLast=false)
Represent a polyline containing arcs as well as line segments: A chain of connected line and/or arc s...
bool IsClosed() const override
int PointCount() const
Return the number of points (vertices) in this line chain.
const VECTOR2I & CPoint(int aIndex) const
Return a reference to a given point in the line chain.
int SegmentCount() const
Return the number of segments in this line chain.
size_t GetTriangleCount() const
void GetTriangle(int index, VECTOR2I &a, VECTOR2I &b, VECTOR2I &c) const
Represent a set of closed polygons.
bool IsTriangulationUpToDate() const
POLYGON & Polygon(int aIndex)
Return the aIndex-th subpolygon in the set.
const TRIANGULATED_POLYGON * TriangulatedPolygon(int aIndex) const
unsigned int TriangulatedPolyCount() const
Return the number of triangulated polygons.
int OutlineCount() const
Return the number of outlines in the set.
const SHAPE_LINE_CHAIN & COutline(int aIndex) const
uni_iter is a non-mutating iterator that walks through unicode code points in the UTF8 encoded string...
An 8 bit string that is assuredly encoded in UTF8, and supplies special conversion support to and fro...
uni_iter uend() const
Return a uni_iter initialized to the end of "this" UTF8 byte sequence.
uni_iter ubegin() const
Returns a uni_iter initialized to the start of "this" UTF8 byte sequence.
T EuclideanNorm() const
Compute the Euclidean norm of the vector, which is defined as sqrt(x ** 2 + y ** 2).
static constexpr EDA_ANGLE FULL_CIRCLE
a few functions useful in geometry calculations.
int GetArcToSegmentCount(int aRadius, int aErrorMax, const EDA_ANGLE &aArcAngle)
const wxChar *const traceGalProfile
Flag to enable debug output of GAL performance profiling.
This file contains miscellaneous commonly used macros and functions.
MATRIX3x3< double > MATRIX3x3D
FONT_IMAGE_TYPE font_image
const FONT_GLYPH_TYPE * LookupGlyph(unsigned int aCodepoint)
FONT_INFO_TYPE font_information
The Cairo implementation of the graphics abstraction layer.
@ SMALL_CROSS
Use small cross instead of dots for the grid.
@ DOTS
Use dots for the grid.
@ SHADER_TYPE_VERTEX
Vertex shader.
@ SHADER_TYPE_FRAGMENT
Fragment shader.
RENDER_TARGET
RENDER_TARGET: Possible rendering targets.
@ TARGET_NONCACHED
Auxiliary rendering target (noncached)
@ TARGET_TEMP
Temporary target for drawing in separate layer.
@ TARGET_CACHED
Main rendering target (cached)
@ TARGET_OVERLAY
Items that may change while the view stays the same (noncached)
EDA_ANGLE abs(const EDA_ANGLE &aAngle)
static const wxChar *const traceGalXorMode
static void InitTesselatorCallbacks(GLUtesselator *aTesselator)
void CALLBACK CombineCallback(GLdouble coords[3], GLdouble *vertex_data[4], GLfloat weight[4], GLdouble **dataOut, void *aData)
void CALLBACK VertexCallback(GLvoid *aVertexPtr, void *aData)
void CALLBACK EdgeCallback(GLboolean aEdgeFlag)
static wxGLAttributes getGLAttribs()
void CALLBACK ErrorCallback(GLenum aErrorCode)
double round_to_half_pixel(double f, double r)
#define SEG_PER_CIRCLE_COUNT
#define CALLBACK
The default number of points for circle approximation.
void Refresh()
Update the board display after modifying it by a python script (note: it is automatically called by a...
PGM_BASE & Pgm()
The global program "get" accessor.
std::vector< FAB_LAYER_COLOR > dummy
VERTEX_MANAGER * vboManager
Manager used for storing new vertices.
std::deque< std::shared_ptr< GLdouble > > & intersectPoints
Intersect points, that have to be freed after tessellation.
Structure to keep VIEW_CONTROLS settings for easy store/restore operations.
@ GR_TEXT_H_ALIGN_INDETERMINATE
@ GR_TEXT_V_ALIGN_INDETERMINATE
wxLogTrace helper definitions.
#define KI_TRACE(aWhat,...)
void enableGlDebug(bool aEnable)
Enable or disable OpenGL driver messages output.
int checkGlError(const std::string &aInfo, const char *aFile, int aLine, bool aThrow)
Check if a recent OpenGL operation has failed.
VECTOR2< int32_t > VECTOR2I
VECTOR2< double > VECTOR2D
VECTOR2I ToVECTOR2I(const wxSize &aSize)