48 using namespace KIGFX;
58 static const int glAttributes[] = { WX_GL_RGBA, WX_GL_DOUBLEBUFFER, WX_GL_DEPTH_SIZE, 8, 0 };
60 wxGLContext* OPENGL_GAL::glMainContext = NULL;
61 int OPENGL_GAL::instanceCounter = 0;
62 GLuint OPENGL_GAL::fontTexture = 0;
63 bool OPENGL_GAL::isBitmapFontLoaded =
false;
64 SHADER* OPENGL_GAL::shader = NULL;
68 wxEvtHandler* aMouseListener, wxEvtHandler* aPaintListener,
69 const wxString& aName ) :
70 GAL( aDisplayOptions ),
73 mouseListener( aMouseListener ), paintListener( aPaintListener ), currentManager( nullptr ),
74 cachedManager( nullptr ), nonCachedManager( nullptr ), overlayManager( nullptr ), mainBuffer( 0 ), overlayBuffer( 0 )
114 #if wxCHECK_VERSION( 3, 1, 0 ) || defined( USE_OSX_MAGNIFY_EVENT ) 117 #if defined _WIN32 || defined _WIN64 121 SetSize( aParent->GetClientSize() );
133 throw std::runtime_error(
"Could not create the tesselator" );
135 gluTessProperty(
tesselator, GLU_TESS_WINDING_RULE, GLU_TESS_WINDING_POSITIVE );
188 bool refresh =
false;
209 if( !IsShownOnScreen() )
213 PROF_COUNTER totalRealTime(
"OPENGL_GAL::BeginDrawing()",
true );
222 glMatrixMode( GL_PROJECTION );
237 catch( std::runtime_error& )
249 glDisable( GL_TEXTURE_2D );
251 glShadeModel( GL_FLAT );
254 glEnable( GL_DEPTH_TEST );
255 glDepthFunc( GL_LESS );
258 glEnable( GL_BLEND );
259 glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );
261 glMatrixMode( GL_MODELVIEW );
265 GLdouble matrixData[16] = { 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1 };
275 glLoadMatrixd( matrixData );
292 const GLint FONT_TEXTURE_UNIT = 2;
297 glActiveTexture( GL_TEXTURE0 + FONT_TEXTURE_UNIT );
302 glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
303 glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
306 glActiveTexture( GL_TEXTURE0 );
312 glActiveTexture( GL_TEXTURE0 + FONT_TEXTURE_UNIT );
314 glActiveTexture( GL_TEXTURE0 );
324 checkGlError(
"setting bitmap font sampler as shader parameter" );
331 glActiveTexture( GL_TEXTURE0 );
337 totalRealTime.
Stop();
338 wxLogTrace(
"GAL_PROFILE",
339 wxT(
"OPENGL_GAL::BeginDrawing(): %.1f ms" ), totalRealTime.
msecs() );
347 PROF_COUNTER totalRealTime(
"OPENGL_GAL::EndDrawing()",
true );
360 glColor4d( 1.0, 1.0, 1.0, 1.0 );
372 totalRealTime.
Stop();
373 wxLogTrace(
"GAL_PROFILE", wxT(
"OPENGL_GAL::EndDrawing(): %.1f ms" ), totalRealTime.
msecs() );
380 if( !IsShownOnScreen() )
403 const VECTOR2D startEndVector = aEndPoint - aStartPoint;
404 double lineAngle = startEndVector.
Angle();
422 VECTOR2D startEndVector = aEndPoint - aStartPoint;
423 double lineAngle = startEndVector.
Angle();
454 VECTOR2D( lineLength, aWidth / 2.0 ) );
457 VECTOR2D( lineLength, -aWidth / 2.0 ) );
512 double outerRadius = aRadius + (
lineWidth / 2 );
535 SWAP( aStartAngle, >, aEndAngle );
546 VECTOR2D p( cos( aStartAngle ) * aRadius, sin( aStartAngle ) * aRadius );
549 for( alpha = aStartAngle + alphaIncrement; alpha <= aEndAngle; alpha += alphaIncrement )
551 VECTOR2D p_next( cos( alpha ) * aRadius, sin( alpha ) * aRadius );
558 if( alpha != aEndAngle )
560 VECTOR2D p_last( cos( aEndAngle ) * aRadius, sin( aEndAngle ) * aRadius );
572 for( alpha = aStartAngle; ( alpha + alphaIncrement ) < aEndAngle; )
577 alpha += alphaIncrement;
582 const VECTOR2D endPoint( cos( aEndAngle ) * aRadius, sin( aEndAngle ) * aRadius );
595 double aEndAngle,
double aWidth )
607 SWAP( aStartAngle, >, aEndAngle );
618 double width = aWidth / 2.0;
619 VECTOR2D startPoint( cos( aStartAngle ) * aRadius,
620 sin( aStartAngle ) * aRadius );
621 VECTOR2D endPoint( cos( aEndAngle ) * aRadius,
622 sin( aEndAngle ) * aRadius );
627 VECTOR2D pOuter( cos( aStartAngle ) * ( aRadius + width ),
628 sin( aStartAngle ) * ( aRadius + width ) );
630 VECTOR2D pInner( cos( aStartAngle ) * ( aRadius - width ),
631 sin( aStartAngle ) * ( aRadius - width ) );
635 for( alpha = aStartAngle + alphaIncrement; alpha <= aEndAngle; alpha += alphaIncrement )
637 VECTOR2D pNextOuter( cos( alpha ) * ( aRadius + width ),
638 sin( alpha ) * ( aRadius + width ) );
639 VECTOR2D pNextInner( cos( alpha ) * ( aRadius - width ),
640 sin( alpha ) * ( aRadius - width ) );
650 if( alpha != aEndAngle )
652 VECTOR2D pLastOuter( cos( aEndAngle ) * ( aRadius + width ),
653 sin( aEndAngle ) * ( aRadius + width ) );
654 VECTOR2D pLastInner( cos( aEndAngle ) * ( aRadius - width ),
655 sin( aEndAngle ) * ( aRadius - width ) );
667 VECTOR2D p( cos( aStartAngle ) * aRadius, sin( aStartAngle ) * aRadius );
670 for( alpha = aStartAngle + alphaIncrement; alpha <= aEndAngle; alpha += alphaIncrement )
672 VECTOR2D p_next( cos( alpha ) * aRadius, sin( alpha ) * aRadius );
679 if( alpha != aEndAngle )
681 VECTOR2D p_last( cos( aEndAngle ) * aRadius, sin( aEndAngle ) * aRadius );
693 VECTOR2D diagonalPointA( aEndPoint.
x, aStartPoint.
y );
694 VECTOR2D diagonalPointB( aStartPoint.
x, aEndPoint.
y );
701 std::deque<VECTOR2D> pointList;
702 pointList.push_back( aStartPoint );
703 pointList.push_back( diagonalPointA );
704 pointList.push_back( aEndPoint );
705 pointList.push_back( diagonalPointB );
706 pointList.push_back( aStartPoint );
730 drawPolyline( [&](
int idx) {
return aPointList[idx]; }, aPointList.size() );
736 drawPolyline( [&](
int idx) {
return aPointList[idx]; }, aListSize );
753 auto points = std::unique_ptr<GLdouble[]>(
new GLdouble[3 * aPointList.size()] );
754 GLdouble* ptr = points.get();
756 for(
const VECTOR2D& p : aPointList )
769 auto points = std::unique_ptr<GLdouble[]>(
new GLdouble[3 * aListSize] );
770 GLdouble* target = points.get();
773 for(
int i = 0;
i < aListSize; ++
i )
796 for(
int i = 0;
i < triPoly->GetTriangleCount();
i++ )
799 triPoly->GetTriangle(
i ,a,b,c);
811 const auto& poly = aPolySet.
Polygon( j );
813 for(
const auto& lc : poly )
838 std::unique_ptr<GLdouble[]> points(
new GLdouble[3 * pointCount] );
839 GLdouble* ptr = points.get();
841 for(
int i = 0;
i < pointCount; ++
i )
861 std::deque<VECTOR2D> pointList;
868 double omt = 1.0 - t;
869 double omt2 = omt * omt;
870 double omt3 = omt * omt2;
874 VECTOR2D vertex = omt3 * aStartPoint + 3.0 * t * omt2 * aControlPointA
875 + 3.0 * t2 * omt * aControlPointB + t3 * aEndPoint;
877 pointList.push_back( vertex );
887 double aRotationAngle )
889 wxASSERT_MSG( !
IsTextMirrored(),
"No support for mirrored text using bitmap fonts." );
892 const auto& text = processedText.first;
893 const auto& overbars = processedText.second;
901 bool overbar =
false;
903 int overbarLength = 0;
904 double overbarHeight = textSize.
y;
939 overbarHeight = -textSize.
y / 2.0;
953 for(
UTF8::uni_iter chIt = text.ubegin(), end = text.uend(); chIt < end; ++chIt )
955 unsigned int c = *chIt;
956 wxASSERT_MSG( c !=
'\n' && c !=
'\r', wxT(
"No support for multiline bitmap text yet" ) );
959 if( overbars[i] && !overbar )
963 else if( overbar && !overbars[i] )
981 if( overbar && overbarLength > 0 )
995 double majorLineWidth = minorLineWidth * 2.0;
1006 glLineWidth( minorLineWidth );
1009 glBegin( GL_LINES );
1010 glVertex2d( worldStartPoint.
x, 0 );
1011 glVertex2d( worldEndPoint.
x, 0 );
1014 glBegin( GL_LINES );
1015 glVertex2d( 0, worldStartPoint.
y );
1016 glVertex2d( 0, worldEndPoint.
y );
1029 if(
std::max( gridScreenSizeDense, gridScreenSizeCoarse ) < gridThreshold )
1041 if( gridStartX > gridEndX )
1042 std::swap( gridStartX, gridEndX );
1044 if( gridStartY > gridEndY )
1045 std::swap( gridStartY, gridEndY );
1048 --gridStartX; ++gridEndX;
1049 --gridStartY; ++gridEndY;
1051 glDisable( GL_DEPTH_TEST );
1052 glDisable( GL_TEXTURE_2D );
1056 glEnable( GL_STENCIL_TEST );
1057 glStencilFunc( GL_ALWAYS, 1, 1 );
1058 glStencilOp( GL_KEEP, GL_KEEP, GL_INCR );
1059 glColor4d( 0.0, 0.0, 0.0, 0.0 );
1068 glLineWidth( minorLineWidth );
1072 int lineLen =
KiROUND( minorLineWidth / worldScale * 2 );
1075 for(
int j = gridStartY; j <= gridEndY; j++ )
1077 if( ( j %
gridTick == 0 && gridScreenSizeCoarse > gridThreshold )
1078 || gridScreenSizeDense > gridThreshold )
1083 for(
int i = gridStartX;
i <= gridEndX;
i++ )
1085 if( (
i %
gridTick == 0 && gridScreenSizeCoarse > gridThreshold )
1086 || gridScreenSizeDense > gridThreshold )
1090 glBegin( GL_LINES );
1091 glVertex2d( posX -lineLen, posY );
1092 glVertex2d( posX + lineLen, posY );
1093 glVertex2d( posX, posY - lineLen );
1094 glVertex2d( posX, posY + lineLen );
1104 for(
int j = gridStartY; j <= gridEndY; j++ )
1112 if( j %
gridTick == 0 && gridScreenSizeDense > gridThreshold )
1113 glLineWidth( majorLineWidth );
1115 glLineWidth( minorLineWidth );
1117 if( ( j %
gridTick == 0 && gridScreenSizeCoarse > gridThreshold )
1118 || gridScreenSizeDense > gridThreshold )
1120 glBegin( GL_LINES );
1129 glStencilFunc( GL_NOTEQUAL, 0, 1 );
1134 for(
int i = gridStartX;
i <= gridEndX;
i++ )
1142 if(
i %
gridTick == 0 && gridScreenSizeDense > gridThreshold )
1143 glLineWidth( majorLineWidth );
1145 glLineWidth( minorLineWidth );
1147 if( (
i %
gridTick == 0 && gridScreenSizeCoarse > gridThreshold )
1148 || gridScreenSizeDense > gridThreshold )
1150 glBegin( GL_LINES );
1158 glDisable( GL_STENCIL_TEST );
1161 glEnable( GL_DEPTH_TEST );
1162 glEnable( GL_TEXTURE_2D );
1175 wxGLCanvas::SetSize( aWidth, aHeight );
1181 bool s = wxGLCanvas::Show( aShow );
1184 wxGLCanvas::Raise();
1201 glClearColor( 0, 0, 0, 1 );
1202 glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT );
1208 GLdouble matrixData[16] = { 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1 };
1210 matrixData[0] = aTransformation.
m_data[0][0];
1211 matrixData[1] = aTransformation.
m_data[1][0];
1212 matrixData[2] = aTransformation.
m_data[2][0];
1213 matrixData[4] = aTransformation.
m_data[0][1];
1214 matrixData[5] = aTransformation.
m_data[1][1];
1215 matrixData[6] = aTransformation.
m_data[2][1];
1216 matrixData[12] = aTransformation.
m_data[0][2];
1217 matrixData[13] = aTransformation.
m_data[1][2];
1218 matrixData[14] = aTransformation.
m_data[2][2];
1220 glMultMatrixd( matrixData );
1258 std::shared_ptr<VERTEX_ITEM> newItem = std::make_shared<VERTEX_ITEM>( *cachedManager );
1260 groups.insert( std::make_pair( groupNumber, newItem ) );
1294 groups.erase( aGroupNumber );
1309 wxASSERT_MSG(
false, wxT(
"Not implemented yet" ) );
1315 wxASSERT_MSG(
false, wxT(
"Not implemented yet" ) );
1404 VECTOR2D startEndVector = aEndPoint - aStartPoint;
1407 if( lineLength <= 0.0 )
1414 glm::vec4( -startEndVector.
y * scale, startEndVector.
x * scale, 0.0, 0.0 );
1489 double outerRadius = aRadius + (
lineWidth / 2 );
1533 GLdouble* point = aPoints;
1535 for(
int i = 0;
i < aPointCount; ++
i )
1545 tessIntersects.clear();
1558 if( aPointCount < 2 )
1564 for( i = 1; i < aPointCount; ++
i )
1566 auto start = aPointGetter( i - 1 );
1567 auto end = aPointGetter( i );
1568 const VECTOR2D startEndVector = ( end - start );
1569 double lineAngle = startEndVector.
Angle();
1578 auto start = aPointGetter( i - 2 );
1579 auto end = aPointGetter( i - 1 );
1580 const VECTOR2D startEndVector = ( end - start );
1581 double lineAngle = startEndVector.
Angle();
1608 const float XOFF = glyph->
minx;
1611 const float round_adjust = ( glyph->
maxy - glyph->
miny )
1614 const float YOFF = round_adjust + top_adjust;
1660 const float H = glyph->
maxy - glyph->
miny;
1687 static const auto defaultGlyph =
LookupGlyph(
'(' );
1691 unsigned int c = *chIt;
1694 wxASSERT( c ==
' ' || glyph );
1698 c ==
'-' || c ==
'_' )
1700 glyph = defaultGlyph;
1711 textSize.
y -= commonOffset;
1713 return std::make_pair( textSize, commonOffset );
1742 VECTOR2D cursorCenter = ( cursorBegin + cursorEnd ) / 2;
1746 cColor.
b * cColor.
a, 1.0 );
1748 glActiveTexture( GL_TEXTURE0 );
1749 glDisable( GL_TEXTURE_2D );
1751 glColor4d( color.
r, color.
g, color.
b, color.
a );
1753 glBegin( GL_LINES );
1754 glVertex2d( cursorCenter.
x, cursorBegin.
y );
1755 glVertex2d( cursorCenter.
x, cursorEnd.
y );
1757 glVertex2d( cursorBegin.
x, cursorCenter.
y );
1758 glVertex2d( cursorEnd.
x, cursorCenter.
y );
1766 wxT(
"There are no free slots to store a group" ) );
1779 wxASSERT( IsShownOnScreen() );
1783 GLenum
err = glewInit();
1787 if( GLEW_OK != err )
1788 throw std::runtime_error( (
const char*) glewGetErrorString( err ) );
1791 if( !GLEW_VERSION_2_1 )
1792 throw std::runtime_error(
"OpenGL 2.1 or higher is required!" );
1794 #if defined (__LINUX__) // calling enableGlDebug crashes opengl on some OS (OSX and some Windows) 1796 if( GLEW_ARB_debug_output )
1802 if( !GLEW_EXT_framebuffer_object )
1803 throw std::runtime_error(
"Framebuffer objects are not supported!" );
1806 if( !GLEW_ARB_vertex_buffer_object )
1807 throw std::runtime_error(
"Vertex buffer objects are not supported!" );
1811 throw std::runtime_error(
"Cannot compile vertex shader!" );
1814 throw std::runtime_error(
"Cannot compile fragment shader!" );
1817 throw std::runtime_error(
"Cannot link the shaders!" );
1821 glGetIntegerv( GL_MAX_TEXTURE_SIZE, &maxTextureSize );
1827 throw std::runtime_error(
"Requested texture size is not supported" );
1830 catch( std::runtime_error& )
1853 GLdouble* vertex =
static_cast<GLdouble*
>( aVertexPtr );
1857 assert( vboManager );
1858 vboManager->
Vertex( vertex[0], vertex[1], vertex[2] );
1863 GLdouble* vertex_data[4],
1864 GLfloat weight[4], GLdouble** dataOut,
void* aData )
1866 GLdouble* vertex =
new GLdouble[3];
1870 param->
intersectPoints.push_back( boost::shared_array<GLdouble>( vertex ) );
1872 memcpy( vertex, coords, 3 *
sizeof(GLdouble) );
double computeMinGridSpacing() const
compute minimum grid spacing from the grid settings
bool IsCursorEnabled() const
Returns information about cursor visibility.
void Stop()
save the time when this function was called, and set the counter stane to stop
int gridTick
Every tick line gets the double width.
virtual void SetFillColor(const COLOR4D &aColor)
Set the fill color.
Class UTF8 is an 8 bit string that is assuredly encoded in UTF8, and supplies special conversion supp...
VERTEX_MANAGER * currentManager
Currently used VERTEX_MANAGER (for storing VERTEX_ITEMs)
EDA_TEXT_HJUSTIFY_T GetHorizontalJustify() const
Returns current text horizontal justification setting.
VECTOR2D cursorPosition
Current cursor position (world coordinates)
static SHADER * shader
There is only one shader used for different objects.
virtual void BeginUpdate() override
Enables item update mode.
bool axesEnabled
Should the axes be drawn.
bool IsLinked() const
Returns true if shaders are linked correctly.
EDA_TEXT_VJUSTIFY_T GetVerticalJustify() const
Returns current text vertical justification setting.
virtual void DrawBuffer(unsigned int aBufferHandle) override
Function DrawBuffer() draws the selected buffer to the output buffer.
static wxGLContext * glMainContext
Parent OpenGL context.
void Clear() const
Function Clear() removes all the stored vertices from the container.
double calcAngleStep(double aRadius) const
Compute the angle step when drawing arcs/circles approximated with lines.
std::pair< UTF8, std::vector< bool > > ProcessOverbars(const UTF8 &aText)
Processes a text to extract the raw text and overbar flags.
double layerDepth
The actual layer depth.
void ChangeItemDepth(const VERTEX_ITEM &aItem, GLfloat aDepth) const
Function ChangeItemDepth() changes the depth of all vertices owned by an item.
virtual void EndUpdate() override
Disables item update mode.
Class CAIRO_GAL is the cairo implementation of the graphics abstraction layer.
static int KiROUND(double v)
KiROUND rounds a floating point number to an int using "round halfway cases away from zero"...
void PushMatrix()
Function PushMatrix() pushes the current transformation matrix stack.
unsigned int overlayBuffer
Auxiliary rendering target (for menus etc.)
std::deque< boost::shared_array< GLdouble > > & intersectPoints
Intersect points, that have to be freed after tessellation.
virtual void Scale(const VECTOR2D &aScale) override
Scale the context.
virtual void ClearTarget(RENDER_TARGET aTarget) override
Clears the target for rendering.
virtual void Translate(const VECTOR2D &aTranslation) override
Translate the context.
virtual void Begin() override
Function Begin() Call this at the beginning of each frame.
bool Reserve(unsigned int aSize)
Function Reserve() allocates space for vertices, so it will be used with subsequent Vertex() calls...
RENDER_TARGET currentTarget
Current rendering target.
int PointCount() const
Function PointCount()
bool isBitmapFontInitialized
Is the shader set to use bitmap fonts?
void Use()
Use the shader.
void drawPolygon(GLdouble *aPoints, int aPointCount)
Draws a filled polygon.
void SetParameter(int aParameterNumber, float aValue) const
Set a parameter of the shader.
static GLuint fontTexture
Bitmap font texture handle (shared)
GRID_STYLE gridStyle
Grid display style.
bool LoadShaderFromStrings(SHADER_TYPE aShaderType, Args &&...aArgs)
Add a shader and compile the shader sources.
void drawLineQuad(const VECTOR2D &aStartPoint, const VECTOR2D &aEndPoint)
Draw a quad for the line.
VERTEX_MANAGER * overlayManager
Container for storing overlaid VERTEX_ITEMs.
virtual void EndDrawing() override
End the drawing, needs to be called for every new frame.
GAL_DISPLAY_OPTIONS & options
virtual void Restore() override
Restore the context.
void CALLBACK EdgeCallback(GLboolean aEdgeFlag)
virtual void ChangeGroupDepth(int aGroupNumber, int aDepth) override
Changes the depth (Z-axis position) of the group.
bool Vertex(const VERTEX &aVertex)
Function Vertex() adds a vertex with the given coordinates to the currently set item.
static const COLOR4D BLACK
wxGLCanvas wrapper for HiDPI/Retina support.
virtual int BeginGroup() override
Begin a group.
static void InitTesselatorCallbacks(GLUtesselator *aTesselator)
virtual void DrawPolygon(const std::deque< VECTOR2D > &aPointList) override
Draw a polygon.
void Rotate(GLfloat aAngle, GLfloat aX, GLfloat aY, GLfloat aZ)
Function Rotate() multiplies the current matrix by a rotation matrix, so the newly vertices will be r...
bool Link()
Link the shaders.
COLOR4D fillColor
The fill color.
VECTOR2D depthRange
Range of the depth.
bool IsTriangulationUpToDate() const
int checkGlError(const std::string &aInfo, bool aThrow)
Checks if one of recent OpenGL operations has failed.
int OutlineCount() const
Returns the number of outlines in the set
MATRIX3x3D screenWorldMatrix
Screen transformation.
bool globalFlipX
Flag for X axis flipping.
const FONT_GLYPH_TYPE * LookupGlyph(unsigned int aCodepoint)
static const unsigned int DIRECT_RENDERING
bool isGrouping
Was a group started?
virtual void ComputeWorldScreenMatrix()
Compute the world <-> screen transformation matrix.
The class PROF_COUNTER is a small class to help profiling.
OPENGL_ANTIALIASING_MODE gl_antialiasing_mode
void UnlockCtx(wxGLContext *aContext)
Function UnlockCtx allows other canvases to bind an OpenGL context.
void enableGlDebug(bool aEnable)
Enables/disables OpenGL driver messages output.
unsigned int smooth_pixels
virtual void ResizeScreen(int aWidth, int aHeight) override
Resizes the canvas.
const char kicad_fragment_shader[]
void CALLBACK VertexCallback(GLvoid *aVertexPtr, void *aData)
virtual void Transform(const MATRIX3x3D &aTransformation) override
Transform the context.
uni_iter ubegin() const
Function ubegin returns a uni_iter initialized to the start of "this" UTF8 byte sequence.
VERTEX_MANAGER * nonCachedManager
Container for storing non-cached VERTEX_ITEMs.
Auxiliary rendering target (noncached)
static int instanceCounter
GL GAL instance counter.
This file contains miscellaneous commonly used macros and functions.
VERTEX_MANAGER * vboManager
Manager used for storing new vertices.
void SetAntialiasingMode(OPENGL_ANTIALIASING_MODE aMode)
virtual void DrawArcSegment(const VECTOR2D &aCenterPoint, double aRadius, double aStartAngle, double aEndAngle, double aWidth) override
Draw an arc segment.
virtual RENDER_TARGET GetTarget() const override
Gets the currently used target for rendering.
static const int CURVE_POINTS
The number of points for curve approximation.
static GL_CONTEXT_MANAGER & Get()
Function Get returns the GL_CONTEXT_MANAGER instance (singleton).
double lineWidth
The line width.
double Angle() const
Function Angle computes the angle of the vector.
void SetGridColor(const COLOR4D &aGridColor)
Set the grid color.
virtual void Save() override
Save the context.
void init()
Basic OpenGL initialization.
void Unmap()
Function Unmap() unmaps vertex buffer.
virtual void SetLineWidth(double aLineWidth)
Set the line width.
OPENGL_COMPOSITOR * compositor
Handles multiple rendering targets.
bool fullscreenCursor
Shape of the cursor (fullscreen or small cross)
T EuclideanNorm() const
Destructor.
bool isStrokeEnabled
Are the outlines stroked ?
VECTOR2< double > VECTOR2D
COLOR4D getCursorColor() const
Gets the actual cursor color to draw.
void Refresh()
Update the board display after modifying it bu a python script (note: it is automatically called by a...
GROUPS_MAP groups
Stores informations about VBO objects (groups)
virtual void Present() override
Function Present() Call this to present the output buffer to the screen.
std::pair< VECTOR2D, float > computeBitmapTextSize(const UTF8 &aText) const
Computes a size of text drawn using bitmap font with current text setting applied.
virtual void BeginDrawing() override
Begin the drawing, needs to be called for every new frame.
virtual void RestoreScreen() override
Restore the screen contents.
unsigned int mainBuffer
Main rendering target.
virtual bool Show(bool aShow) override
Shows/hides the GAL canvas.
virtual void ClearBuffer(const COLOR4D &aColor) override
Function ClearBuffer() clears the selected buffer (set by the SetBuffer() function).
virtual void EndGroup() override
End the group.
COLOR4D axesColor
Color of the axes.
virtual void DeleteGroup(int aGroupNumber) override
Delete the group from the memory.
wxEvtHandler * mouseListener
void SetAxesColor(const COLOR4D &aAxesColor)
Set the axes color.
void EndDrawing() const
Function EndDrawing() finishes drawing operations.
bool updatedGalDisplayOptions(const GAL_DISPLAY_OPTIONS &aOptions) override
Function updatedGalDisplayOptions.
virtual void DrawGrid() override
>
COLOR4D strokeColor
The color of the outlines.
void Translate(GLfloat aX, GLfloat aY, GLfloat aZ)
Function Translate() multiplies the current matrix by a translation matrix, so newly vertices will be...
static const int glAttributes[]
virtual void DrawLine(const VECTOR2D &aStartPoint, const VECTOR2D &aEndPoint) override
Draw a line.
const TRIANGULATED_POLYGON * TriangulatedPolygon(int aIndex) const
Items that may change while the view stays the same (noncached)
void Map()
Function Map() maps vertex buffer.
void onPaint(wxPaintEvent &aEvent)
This is the OnPaint event handler.
int AddParameter(const std::string &aParameterName)
Add a parameter to the parameter queue.
const SHAPE_LINE_CHAIN & COutline(int aIndex) const
const VECTOR2D & GetGlyphSize() const
virtual void DrawGroup(int aGroupNumber) override
Draw the stored group.
void Deactivate()
Deactivate the shader and use the default OpenGL program.
bool isFramebufferInitialized
Are the framebuffers initialized?
virtual void Resize(unsigned int aWidth, unsigned int aHeight) override
Function Resize() clears the state of COMPOSITOR, so it has to be reinitialized again with the new di...
VECTOR2D gridOrigin
The grid origin.
virtual void ClearCache() override
Delete all data created during caching of graphic items.
FONT_IMAGE_TYPE font_image
unsigned char pixels[1024 *1024 *3]
void drawTriangulatedPolyset(const SHAPE_POLY_SET &aPoly)
Draws a set of polygons with a cached triangulation.
OPENGL_ANTIALIASING_MODE GetAntialiasingMode() const
FONT_INFO_TYPE font_information
MATRIX3x3D worldScreenMatrix
World transformation.
virtual void SetBuffer(unsigned int aBufferHandle) override
Function SetBuffer() sets the selected buffer as the rendering target.
Class SHADER provides the access to the OpenGL shaders.
void BeginDrawing() const
Function BeginDrawing() prepares buffers and items to start drawing.
void Color(const COLOR4D &aColor)
Function Color() changes currently used color that will be applied to newly added vertices...
GLUtesselator * tesselator
The tessellator.
Use small cross instead of dots for the grid.
virtual void Rotate(double aAngle) override
Rotate the context.
virtual bool updatedGalDisplayOptions(const GAL_DISPLAY_OPTIONS &aOptions)
Function updatedGalDisplayOptions.
void LockCtx(wxGLContext *aContext, wxGLCanvas *aCanvas)
Function LockCtx sets a context as current and prevents other canvases from switching it...
void drawStrokedSemiCircle(const VECTOR2D &aCenterPoint, double aRadius, double aAngle)
Draw a stroked semicircle.
void PopMatrix()
Function PopMatrix() pops the current transformation matrix stack.
bool isFillEnabled
Is filling of graphic objects enabled ?
void blitCursor()
Blits cursor into the current screen.
VERTEX_MANAGER * cachedManager
Container for storing cached VERTEX_ITEMs.
class uni_iter is a non-mutating iterator that walks through unicode code points in the UTF8 encoded ...
virtual void Initialize() override
Function Reset() performs primary initialiation, necessary to use the object.
virtual void DrawPolyline(const std::deque< VECTOR2D > &aPointList) override
Draw a polyline.
virtual void DrawSegment(const VECTOR2D &aStartPoint, const VECTOR2D &aEndPoint, double aWidth) override
Draw a rounded segment.
const char kicad_vertex_shader[]
std::deque< boost::shared_array< GLdouble > > tessIntersects
Storage for intersecting points.
virtual void DrawArc(const VECTOR2D &aCenterPoint, double aRadius, double aStartAngle, double aEndAngle) override
Draw an arc.
void CALLBACK ErrorCallback(GLenum aErrorCode)
virtual void SaveScreen() override
Save the screen contents.
virtual void SetTarget(RENDER_TARGET aTarget) override
Sets the target for rendering.
virtual void SetStrokeColor(const COLOR4D &aColor)
Set the stroke color.
uni_iter uend() const
Function uend returns a uni_iter initialized to the end of "this" UTF8 byte sequence.
bool isInitialized
Basic initialization flag, has to be done when the window is visible.
COLOR4D gridColor
Color of the grid.
void ChangeItemColor(const VERTEX_ITEM &aItem, const COLOR4D &aColor) const
Function ChangeItemColor() changes the color of all vertices owned by an item.
void PostPaint()
Function PostPaint posts an event to m_paint_listener.
bool gridVisibility
Should the grid be shown.
void drawSemiCircle(const VECTOR2D &aCenterPoint, double aRadius, double aAngle)
Draw a semicircle.
Main rendering target (cached)
bool globalFlipY
Flag for Y axis flipping.
unsigned int groupCounter
Counter used for generating keys for groups.
double worldScale
The scale factor world->screen.
int drawBitmapChar(unsigned long aChar)
Draws a single character using bitmap font.
void FinishItem() const
Function FinishItem() does the cleaning after adding an item.
VECTOR2D gridSize
The grid size.
virtual float GetBackingScaleFactor() const
const glm::mat4 & GetTransformation() const
void Scale(GLfloat aX, GLfloat aY, GLfloat aZ)
Function Scale() multiplies the current matrix by a scaling matrix, so the newly vertices will be sca...
virtual void ClearScreen() override
Clear the screen.
VECTOR2I screenSize
Screen size in screen coordinates.
#define SWAP(varA, condition, varB)
Swap the variables if a condition is met.
unsigned int getNewGroupNumber()
Returns a valid key that can be used as a new group number.
wxGLContext * glPrivContext
Canvas-specific OpenGL context.
virtual void DrawRectangle(const VECTOR2D &aStartPoint, const VECTOR2D &aEndPoint) override
Draw a rectangle.
virtual void Flush() override
Force all remaining objects to be drawn.
bool IsClosed() const
Function IsClosed()
virtual unsigned int GetBuffer() const override
Function GetBuffer() returns currently used buffer handle.
virtual void DrawCursor(const VECTOR2D &aCursorPosition) override
Draw the cursor.
virtual unsigned int CreateBuffer() override
Function CreateBuffer() prepares a new buffer that may be used as a rendering target.
void drawPolyline(const std::function< VECTOR2D(int)> &aPointGetter, int aPointCount)
Generic way of drawing a polyline stored in different containers.
void DestroyCtx(wxGLContext *aContext)
Function DestroyCtx destroys a managed OpenGL context.
void CALLBACK CombineCallback(GLdouble coords[3], GLdouble *vertex_data[4], GLfloat weight[4], GLdouble **dataOut, void *aData)
void Shader(GLfloat aShaderType, GLfloat aParam1=0.0f, GLfloat aParam2=0.0f, GLfloat aParam3=0.0f)
Function Shader() changes currently used shader and its parameters that will be applied to newly adde...
POLYGON & Polygon(int aIndex)
Returns the aIndex-th subpolygon in the set
RENDER_TARGET
RENDER_TARGET: Possible rendering targets.
wxGLContext * CreateCtx(wxGLCanvas *aCanvas, const wxGLContext *aOther=NULL)
Function CreateCtx creates a managed OpenGL context.
virtual void BitmapText(const wxString &aText, const VECTOR2D &aPosition, double aRotationAngle) override
Draws a text using a bitmap font.
bool IsTextMirrored() const
Returns true if text should displayed mirrored.
void DrawItem(const VERTEX_ITEM &aItem) const
Function DrawItem() draws an item to the buffer.
const VECTOR2I & CPoint(int aIndex) const
Function CPoint()
virtual void DrawCircle(const VECTOR2D &aCenterPoint, double aRadius) override
Draw a circle using world coordinates.
static bool isBitmapFontLoaded
Is the bitmap font texture loaded?
int SegmentCount() const
Function SegmentCount()
virtual void DrawCurve(const VECTOR2D &startPoint, const VECTOR2D &controlPointA, const VECTOR2D &controlPointB, const VECTOR2D &endPoint) override
Draw a cubic bezier spline.
void skipMouseEvent(wxMouseEvent &aEvent)
Skip the mouse event to the parent.
void drawFilledSemiCircle(const VECTOR2D &aCenterPoint, double aRadius, double aAngle)
Draw a filled semicircle.
virtual void ChangeGroupColor(int aGroupNumber, const COLOR4D &aNewColor) override
Changes the color used to draw the group.
Class GAL is the abstract interface for drawing on a 2D-surface.
void SetShader(SHADER &aShader) const
Function SetShader() sets a shader program that is going to be used during rendering.
Class COLOR4D is the color representation with 4 components: red, green, blue, alpha.
double gridLineWidth
Line width of the grid.
void drawBitmapOverbar(double aLength, double aHeight)
Draws an overbar over the currently drawn text.