KiCad PCB EDA Suite
KIGFX::OPENGL_GAL Class Reference

OpenGL implementation of the Graphics Abstraction Layer. More...

#include <opengl_gal.h>

Inheritance diagram for KIGFX::OPENGL_GAL:
KIGFX::GAL HIDPI_GL_CANVAS KIGFX::GAL_DISPLAY_OPTIONS_OBSERVER

Classes

struct  TessParams
 

Public Member Functions

 OPENGL_GAL (GAL_DISPLAY_OPTIONS &aDisplayOptions, wxWindow *aParent, wxEvtHandler *aMouseListener=nullptr, wxEvtHandler *aPaintListener=nullptr, const wxString &aName=wxT("GLCanvas"))
 
 ~OPENGL_GAL ()
 
bool IsOpenGlEngine () override
 Return true if the GAL engine is a OpenGL based type. More...
 
bool IsInitialized () const override
 Return the initialization status for the canvas. More...
 
bool IsVisible () const override
 Return true if the GAL canvas is visible on the screen. More...
 
void DrawLine (const VECTOR2D &aStartPoint, const VECTOR2D &aEndPoint) override
 Draw a line. More...
 
void DrawSegment (const VECTOR2D &aStartPoint, const VECTOR2D &aEndPoint, double aWidth) override
 Draw a rounded segment. More...
 
void DrawSegmentChain (const std::vector< VECTOR2D > &aPointList, double aWidth) override
 Draw a chain of rounded segments. More...
 
void DrawSegmentChain (const SHAPE_LINE_CHAIN &aLineChain, double aWidth) override
 
void DrawCircle (const VECTOR2D &aCenterPoint, double aRadius) override
 Draw a circle using world coordinates. More...
 
void DrawArc (const VECTOR2D &aCenterPoint, double aRadius, const EDA_ANGLE &aStartAngle, const EDA_ANGLE &aEndAngle) override
 Draw an arc. More...
 
void DrawArcSegment (const VECTOR2D &aCenterPoint, double aRadius, const EDA_ANGLE &aStartAngle, const EDA_ANGLE &aEndAngle, double aWidth, double aMaxError) override
 Draw an arc segment. More...
 
void DrawRectangle (const VECTOR2D &aStartPoint, const VECTOR2D &aEndPoint) override
 Draw a rectangle. More...
 
void DrawPolyline (const std::deque< VECTOR2D > &aPointList) override
 Draw a polyline. More...
 
void DrawPolyline (const std::vector< VECTOR2D > &aPointList) override
 
void DrawPolyline (const VECTOR2D aPointList[], int aListSize) override
 
void DrawPolyline (const SHAPE_LINE_CHAIN &aLineChain) override
 
void DrawPolylines (const std::vector< std::vector< VECTOR2D > > &aPointLists) override
 Draw multiple polylines. More...
 
void DrawPolygon (const std::deque< VECTOR2D > &aPointList) override
 Draw a polygon. More...
 
void DrawPolygon (const VECTOR2D aPointList[], int aListSize) override
 
void DrawPolygon (const SHAPE_POLY_SET &aPolySet, bool aStrokeTriangulation=false) override
 
void DrawPolygon (const SHAPE_LINE_CHAIN &aPolySet) override
 
virtual void DrawGlyph (const KIFONT::GLYPH &aGlyph, int aNth, int aTotal) override
 Draw a polygon representing a font glyph. More...
 
virtual void DrawGlyphs (const std::vector< std::unique_ptr< KIFONT::GLYPH > > &aGlyphs) override
 Draw polygons representing font glyphs. More...
 
void DrawCurve (const VECTOR2D &startPoint, const VECTOR2D &controlPointA, const VECTOR2D &controlPointB, const VECTOR2D &endPoint, double aFilterValue=0.0) override
 Draw a cubic bezier spline. More...
 
void DrawBitmap (const BITMAP_BASE &aBitmap, double alphaBlend=1.0) override
 Draw a bitmap image. More...
 
void BitmapText (const wxString &aText, const VECTOR2I &aPosition, const EDA_ANGLE &aAngle) override
 Draw a text using a bitmap font. More...
 
void DrawGrid () override
 
void ResizeScreen (int aWidth, int aHeight) override
 Resizes the canvas. More...
 
bool Show (bool aShow) override
 Shows/hides the GAL canvas. More...
 
void Flush () override
 Force all remaining objects to be drawn. More...
 
void ClearScreen () override
 Clear the screen. More...
 
void Transform (const MATRIX3x3D &aTransformation) override
 Transform the context. More...
 
void Rotate (double aAngle) override
 Rotate the context. More...
 
void Translate (const VECTOR2D &aTranslation) override
 Translate the context. More...
 
void Scale (const VECTOR2D &aScale) override
 Scale the context. More...
 
void Save () override
 Save the context. More...
 
void Restore () override
 Restore the context. More...
 
int BeginGroup () override
 Begin a group. More...
 
void EndGroup () override
 End the group. More...
 
void DrawGroup (int aGroupNumber) override
 Draw the stored group. More...
 
void ChangeGroupColor (int aGroupNumber, const COLOR4D &aNewColor) override
 Change the color used to draw the group. More...
 
void ChangeGroupDepth (int aGroupNumber, int aDepth) override
 Change the depth (Z-axis position) of the group. More...
 
void DeleteGroup (int aGroupNumber) override
 Delete the group from the memory. More...
 
void ClearCache () override
 Delete all data created during caching of graphic items. More...
 
void SetTarget (RENDER_TARGET aTarget) override
 Set the target for rendering. More...
 
RENDER_TARGET GetTarget () const override
 Get the currently used target for rendering. More...
 
void ClearTarget (RENDER_TARGET aTarget) override
 Clear the target for rendering. More...
 
virtual bool HasTarget (RENDER_TARGET aTarget) override
 Return true if the target exists. More...
 
void SetNegativeDrawMode (bool aSetting) override
 Set negative draw mode in the renderer. More...
 
void StartDiffLayer () override
 Begins rendering of a differential layer. More...
 
void EndDiffLayer () override
 Ends rendering of a differential layer. More...
 
void ComputeWorldScreenMatrix () override
 Compute the world <-> screen transformation matrix. More...
 
bool SetNativeCursorStyle (KICURSOR aCursor) override
 Set the cursor in the native panel. More...
 
void DrawCursor (const VECTOR2D &aCursorPosition) override
 Draw the cursor. More...
 
void PostPaint (wxPaintEvent &aEvent)
 Function PostPaint posts an event to m_paint_listener. More...
 
void SetMouseListener (wxEvtHandler *aMouseListener)
 
void SetPaintListener (wxEvtHandler *aPaintListener)
 
void EnableDepthTest (bool aEnabled=false) override
 
bool IsContextLocked () override
 Checks the state of the context lock. More...
 
void LockContext (int aClientCookie) override
 Use GAL_CONTEXT_LOCKER RAII object unless you know what you're doing. More...
 
void UnlockContext (int aClientCookie) override
 
void BeginDrawing () override
 Start/end drawing functions, draw calls can be only made in between the calls to BeginDrawing()/EndDrawing(). More...
 
void EndDrawing () override
 End the drawing, needs to be called for every new frame. More...
 
virtual bool IsCairoEngine ()
 Return true if the GAL engine is a Cairo based type. More...
 
void DrawRectangle (const BOX2I &aRect)
 
const VECTOR2IGetScreenPixelSize () const
 Return GAL canvas size in pixels. More...
 
void SetClearColor (const COLOR4D &aColor)
 
const COLOR4DGetClearColor () const
 
virtual void SetIsFill (bool aIsFillEnabled)
 Enable/disable fill. More...
 
virtual void SetIsStroke (bool aIsStrokeEnabled)
 Enable/disable stroked outlines. More...
 
virtual void SetFillColor (const COLOR4D &aColor)
 Set the fill color. More...
 
const COLOR4DGetFillColor () const
 Get the fill color. More...
 
virtual void SetStrokeColor (const COLOR4D &aColor)
 Set the stroke color. More...
 
const COLOR4DGetStrokeColor () const
 Get the stroke color. More...
 
virtual void SetLineWidth (float aLineWidth)
 Set the line width. More...
 
float GetLineWidth () const
 Get the line width. More...
 
virtual void SetLayerDepth (double aLayerDepth)
 Set the depth of the layer (position on the z-axis) More...
 
void ResetTextAttributes ()
 Reset text attributes to default styling. More...
 
void SetGlyphSize (const VECTOR2I aSize)
 
const VECTOR2IGetGlyphSize () const
 
void SetFontBold (const bool aBold)
 
bool IsFontBold () const
 
void SetFontItalic (bool aItalic)
 
bool IsFontItalic () const
 
void SetFontUnderlined (bool aUnderlined)
 
bool IsFontUnderlined () const
 
void SetTextMirrored (const bool aMirrored)
 
bool IsTextMirrored () const
 
void SetHorizontalJustify (const GR_TEXT_H_ALIGN_T aHorizontalJustify)
 
GR_TEXT_H_ALIGN_T GetHorizontalJustify () const
 
void SetVerticalJustify (const GR_TEXT_V_ALIGN_T aVerticalJustify)
 
GR_TEXT_V_ALIGN_T GetVerticalJustify () const
 
const MATRIX3x3DGetWorldScreenMatrix () const
 Get the world <-> screen transformation matrix. More...
 
const MATRIX3x3DGetScreenWorldMatrix () const
 Get the screen <-> world transformation matrix. More...
 
void SetWorldScreenMatrix (const MATRIX3x3D &aMatrix)
 Set the world <-> screen transformation matrix. More...
 
BOX2D GetVisibleWorldExtents () const
 
void SetWorldUnitLength (double aWorldUnitLength)
 Set the unit length. More...
 
void SetScreenSize (const VECTOR2I &aSize)
 
void SetScreenDPI (double aScreenDPI)
 Set the dots per inch of the screen. More...
 
void SetLookAtPoint (const VECTOR2D &aPoint)
 Get/set the Point in world space to look at. More...
 
const VECTOR2DGetLookAtPoint () const
 
void SetZoomFactor (double aZoomFactor)
 
double GetZoomFactor () const
 
void SetRotation (double aRotation)
 Get/set the rotation angle (in radians). More...
 
double GetRotation () const
 
void SetDepthRange (const VECTOR2D &aDepthRange)
 Set the range of the layer depth. More...
 
double GetMinDepth () const
 
double GetMaxDepth () const
 
double GetWorldScale () const
 Get the world scale. More...
 
void SetFlip (bool xAxis, bool yAxis)
 Sets flipping of the screen. More...
 
bool IsFlippedX () const
 
bool IsFlippedY () const
 
virtual void StartNegativesLayer ()
 Begins rendering in a new layer that will be copied to the main layer in EndNegativesLayer(). More...
 
virtual void EndNegativesLayer ()
 Ends rendering of a negatives layer and draws it to the main layer. More...
 
void SetGridVisibility (bool aVisibility)
 Set the visibility setting of the grid. More...
 
bool GetGridVisibility () const
 
bool GetGridSnapping () const
 
void SetGridOrigin (const VECTOR2D &aGridOrigin)
 Set the origin point for the grid. More...
 
const VECTOR2DGetGridOrigin () const
 
void SetGridSize (const VECTOR2D &aGridSize)
 Set the grid size. More...
 
const VECTOR2DGetGridSize () const
 Return the grid size. More...
 
void SetGridColor (const COLOR4D &aGridColor)
 Set the grid color. More...
 
void SetAxesColor (const COLOR4D &aAxesColor)
 Set the axes color. More...
 
void SetAxesEnabled (bool aAxesEnabled)
 Enable drawing the axes. More...
 
void SetCoarseGrid (int aInterval)
 Draw every tick line wider. More...
 
float GetGridLineWidth () const
 Get the grid line width. More...
 
VECTOR2D GetGridPoint (const VECTOR2D &aPoint) const
 For a given point it returns the nearest point belonging to the grid in world coordinates. More...
 
VECTOR2D ToWorld (const VECTOR2D &aPoint) const
 Compute the point position in world coordinates from given screen coordinates. More...
 
VECTOR2D ToScreen (const VECTOR2D &aPoint) const
 Compute the point position in screen coordinates from given world coordinates. More...
 
void SetCursorEnabled (bool aCursorEnabled)
 Enable/disable cursor. More...
 
bool IsCursorEnabled () const
 Return information about cursor visibility. More...
 
void SetCursorColor (const COLOR4D &aCursorColor)
 Set the cursor color. More...
 
void AdvanceDepth ()
 Change the current depth to deeper, so it is possible to draw objects right beneath other. More...
 
void PushDepth ()
 Store current drawing depth on the depth stack. More...
 
void PopDepth ()
 Restore previously stored drawing depth for the depth stack. More...
 
virtual wxSize GetNativePixelSize () const
 
wxPoint GetNativePosition (const wxPoint &aPoint) const
 Convert the given point from client coordinates to native pixel coordinates. More...
 
void SetScaleFactor (double aFactor)
 Set the canvas scale factor, probably for a hi-DPI display. More...
 
double GetScaleFactor () const
 Get the current scale factor. More...
 

Static Public Member Functions

static wxString CheckFeatures (GAL_DISPLAY_OPTIONS &aOptions)
 Checks OpenGL features. More...
 

Protected Member Functions

void computeWorldScale ()
 Compute the scaling factor for the world->screen matrix. More...
 
double computeMinGridSpacing () const
 compute minimum grid spacing from the grid settings More...
 
COLOR4D getCursorColor () const
 Get the actual cursor color to draw. More...
 
void OnGalDisplayOptionsChanged (const GAL_DISPLAY_OPTIONS &aOptions) override
 Handler for observer settings changes. More...
 

Protected Attributes

GAL_DISPLAY_OPTIONSm_options
 
UTIL::LINK m_observerLink
 
std::stack< double > m_depthStack
 Stored depth values. More...
 
VECTOR2I m_screenSize
 Screen size in screen coordinates. More...
 
double m_worldUnitLength
 The unit length of the world coordinates [inch]. More...
 
double m_screenDPI
 The dots per inch of the screen. More...
 
VECTOR2D m_lookAtPoint
 Point to be looked at in world space. More...
 
double m_zoomFactor
 The zoom factor. More...
 
double m_rotation
 Rotation transformation (radians) More...
 
MATRIX3x3D m_worldScreenMatrix
 World transformation. More...
 
MATRIX3x3D m_screenWorldMatrix
 Screen transformation. More...
 
double m_worldScale
 The scale factor world->screen. More...
 
bool m_globalFlipX
 Flag for X axis flipping. More...
 
bool m_globalFlipY
 Flag for Y axis flipping. More...
 
float m_lineWidth
 The line width. More...
 
bool m_isFillEnabled
 Is filling of graphic objects enabled ? More...
 
bool m_isStrokeEnabled
 Are the outlines stroked ? More...
 
COLOR4D m_fillColor
 The fill color. More...
 
COLOR4D m_strokeColor
 The color of the outlines. More...
 
COLOR4D m_clearColor
 
double m_layerDepth
 The actual layer depth. More...
 
VECTOR2D m_depthRange
 Range of the depth. More...
 
bool m_gridVisibility
 Should the grid be shown. More...
 
GRID_STYLE m_gridStyle
 Grid display style. More...
 
VECTOR2D m_gridSize
 The grid size. More...
 
VECTOR2D m_gridOrigin
 The grid origin. More...
 
VECTOR2D m_gridOffset
 The grid offset to compensate cursor position. More...
 
COLOR4D m_gridColor
 Color of the grid. More...
 
COLOR4D m_axesColor
 Color of the axes. More...
 
bool m_axesEnabled
 Should the axes be drawn. More...
 
int m_gridTick
 Every tick line gets the double width. More...
 
float m_gridLineWidth
 Line width of the grid. More...
 
int m_gridMinSpacing
 Minimum screen size of the grid (pixels) below which the grid is not drawn. More...
 
bool m_isCursorEnabled
 Is the cursor enabled? More...
 
bool m_forceDisplayCursor
 Always show cursor. More...
 
COLOR4D m_cursorColor
 Cursor color. More...
 
bool m_fullscreenCursor
 Shape of the cursor (fullscreen or small cross) More...
 
VECTOR2D m_cursorPosition
 Current cursor position (world coordinates) More...
 
KICURSOR m_currentNativeCursor
 Current cursor. More...
 

Static Protected Attributes

static const int MIN_DEPTH = -1024
 Possible depth range. More...
 
static const int MAX_DEPTH = 1023
 
static const int GRID_DEPTH = MAX_DEPTH - 1
 Depth level on which the grid is drawn. More...
 

Private Types

typedef GAL super
 Super class definition. More...
 
typedef std::unordered_map< unsigned int, std::shared_ptr< VERTEX_ITEM > > GROUPS_MAP
 

Private Member Functions

void beginUpdate () override
 
void endUpdate () override
 
bool updatedGalDisplayOptions (const GAL_DISPLAY_OPTIONS &aOptions) override
 Handle updating display options. More...
 
void drawLineQuad (const VECTOR2D &aStartPoint, const VECTOR2D &aEndPoint, bool aReserve=true)
 Draw a quad for the line. More...
 
void reserveLineQuads (const int aLineCount)
 Reserves specified number of line quads. More...
 
void drawSemiCircle (const VECTOR2D &aCenterPoint, double aRadius, double aAngle)
 Draw a semicircle. More...
 
void drawFilledSemiCircle (const VECTOR2D &aCenterPoint, double aRadius, double aAngle)
 Draw a filled semicircle. More...
 
void drawStrokedSemiCircle (const VECTOR2D &aCenterPoint, double aRadius, double aAngle, bool aReserve=true)
 Draw a stroked semicircle. More...
 
void drawCircle (const VECTOR2D &aCenterPoint, double aRadius, bool aReserve=true)
 Internal method for circle drawing. More...
 
void drawPolyline (const std::function< VECTOR2D(int)> &aPointGetter, int aPointCount, bool aReserve=true)
 Generic way of drawing a polyline stored in different containers. More...
 
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. More...
 
void drawSegment (const VECTOR2D &aStartPoint, const VECTOR2D &aEndPoint, double aWidth, bool aReserve=true)
 Internal method for segment drawing. More...
 
void drawPolygon (GLdouble *aPoints, int aPointCount)
 Draw a filled polygon. More...
 
void drawTriangulatedPolyset (const SHAPE_POLY_SET &aPoly, bool aStrokeTriangulation)
 Draw a set of polygons with a cached triangulation. More...
 
int drawBitmapChar (unsigned long aChar, bool aReserve=true)
 Draw a single character using bitmap font. More...
 
void drawBitmapOverbar (double aLength, double aHeight, bool aReserve=true)
 Draw an overbar over the currently drawn text. More...
 
std::pair< VECTOR2D, float > computeBitmapTextSize (const UTF8 &aText) const
 Compute a size of text drawn using bitmap font with current text setting applied. More...
 
void onPaint (wxPaintEvent &aEvent)
 This is the OnPaint event handler. More...
 
void skipMouseEvent (wxMouseEvent &aEvent)
 Skip the mouse event to the parent. More...
 
void onSetNativeCursor (wxSetCursorEvent &aEvent)
 Give the correct cursor image when the native widget asks for it. More...
 
void blitCursor ()
 Blit cursor into the current screen. More...
 
unsigned int getNewGroupNumber ()
 Return a valid key that can be used as a new group number. More...
 
double calcAngleStep (double aRadius) const
 Compute the angle step when drawing arcs/circles approximated with lines. More...
 
double getWorldPixelSize () const
 
VECTOR2D getScreenPixelSize () const
 
void init ()
 Basic OpenGL initialization and feature checks. More...
 

Private Attributes

wxGLContext * m_glPrivContext
 Canvas-specific OpenGL context. More...
 
wxEvtHandler * m_mouseListener
 
wxEvtHandler * m_paintListener
 
GROUPS_MAP m_groups
 Stores information about VBO objects (groups) More...
 
unsigned int m_groupCounter
 Counter used for generating keys for groups. More...
 
VERTEX_MANAGERm_currentManager
 Currently used VERTEX_MANAGER (for storing VERTEX_ITEMs). More...
 
VERTEX_MANAGERm_cachedManager
 Container for storing cached VERTEX_ITEMs. More...
 
VERTEX_MANAGERm_nonCachedManager
 Container for storing non-cached VERTEX_ITEMs. More...
 
VERTEX_MANAGERm_overlayManager
 Container for storing overlaid VERTEX_ITEMs. More...
 
VERTEX_MANAGERm_tempManager
 Container for storing temp (diff mode) VERTEX_ITEMs. More...
 
OPENGL_COMPOSITORm_compositor
 Handles multiple rendering targets. More...
 
unsigned int m_mainBuffer
 Main rendering target. More...
 
unsigned int m_overlayBuffer
 Auxiliary rendering target (for menus etc.) More...
 
unsigned int m_tempBuffer
 Temporary rendering target (for diffing etc.) More...
 
RENDER_TARGET m_currentTarget
 Current rendering target. More...
 
SHADERm_shader
 There is only one shader used for different objects. More...
 
bool m_isFramebufferInitialized
 Are the framebuffers initialized? More...
 
bool m_isBitmapFontInitialized
 Is the shader set to use bitmap fonts? More...
 
bool m_isInitialized
 Basic initialization flag, has to be done when the window is visible. More...
 
bool m_isGrouping
 Was a group started? More...
 
bool m_isContextLocked
 Used for assertion checking. More...
 
int m_lockClientCookie
 
GLint ufm_worldPixelSize
 
GLint ufm_screenPixelSize
 
GLint ufm_pixelSizeMultiplier
 
GLint ufm_antialiasingOffset
 
wxCursor m_currentwxCursor
 wxCursor showing the current native cursor More...
 
std::unique_ptr< GL_BITMAP_CACHEm_bitmapCache
 
GLUtesselator * m_tesselator
 
std::deque< std::shared_ptr< GLdouble > > m_tessIntersects
 
TEXT_ATTRIBUTES m_attributes
 
double m_scale_factor
 The current scale factor (e.g. More...
 

Static Private Attributes

static wxGLContext * m_glMainContext = nullptr
 Parent OpenGL context. More...
 
static int m_instanceCounter = 0
 GL GAL instance counter. More...
 
static GLuint g_fontTexture = 0
 Bitmap font texture handle (shared) More...
 
static bool m_isBitmapFontLoaded = false
 Is the bitmap font texture loaded? More...
 

Detailed Description

OpenGL implementation of the Graphics Abstraction Layer.

This is a direct OpenGL-implementation and uses low-level graphics primitives like triangles and quads. The purpose is to provide a fast graphics interface, that takes advantage of modern graphics card GPUs. All methods here benefit thus from the hardware acceleration.

Definition at line 69 of file opengl_gal.h.

Member Typedef Documentation

◆ GROUPS_MAP

typedef std::unordered_map< unsigned int, std::shared_ptr<VERTEX_ITEM> > KIGFX::OPENGL_GAL::GROUPS_MAP
private

Definition at line 337 of file opengl_gal.h.

◆ super

typedef GAL KIGFX::OPENGL_GAL::super
private

Super class definition.

Definition at line 326 of file opengl_gal.h.

Constructor & Destructor Documentation

◆ OPENGL_GAL()

OPENGL_GAL::OPENGL_GAL ( GAL_DISPLAY_OPTIONS aDisplayOptions,
wxWindow *  aParent,
wxEvtHandler *  aMouseListener = nullptr,
wxEvtHandler *  aPaintListener = nullptr,
const wxString &  aName = wxT( "GLCanvas" ) 
)
Parameters
aParentis the wxWidgets immediate wxWindow parent of this object.
aMouseListeneris the wxEvtHandler that should receive the mouse events, this can be can be any wxWindow, but is often a wxFrame container.
aPaintListeneris the wxEvtHandler that should receive the paint event. This can be any wxWindow, but is often a derived instance of this class or a containing wxFrame. The "paint event" here is a wxCommandEvent holding EVT_GAL_REDRAW, as sent by PostPaint().
aNameis the name of this window for use by wxWindow::FindWindowByName()

Definition at line 214 of file opengl_gal.cpp.

216 :
217 GAL( aDisplayOptions ),
218 HIDPI_GL_CANVAS( aParent, wxID_ANY, (int*) glAttributes, wxDefaultPosition, wxDefaultSize,
219 wxEXPAND, aName ),
220 m_mouseListener( aMouseListener ),
221 m_paintListener( aPaintListener ),
222 m_currentManager( nullptr ),
223 m_cachedManager( nullptr ),
224 m_nonCachedManager( nullptr ),
225 m_overlayManager( nullptr ),
226 m_tempManager( nullptr ),
227 m_mainBuffer( 0 ),
228 m_overlayBuffer( 0 ),
229 m_tempBuffer( 0 ),
230 m_isContextLocked( false ),
232{
233 if( m_glMainContext == nullptr )
234 {
236
238 }
239 else
240 {
242 }
243
244 m_shader = new SHADER();
246
247 m_bitmapCache = std::make_unique<GL_BITMAP_CACHE>();
248
251
252 // Initialize the flags
255 m_isInitialized = false;
256 m_isGrouping = false;
257 m_groupCounter = 0;
258
259 // Connect the native cursor handler
260 Connect( wxEVT_SET_CURSOR, wxSetCursorEventHandler( OPENGL_GAL::onSetNativeCursor ), nullptr,
261 this );
262
263 // Connecting the event handlers
264 Connect( wxEVT_PAINT, wxPaintEventHandler( OPENGL_GAL::onPaint ) );
265
266 // Mouse events are skipped to the parent
267 Connect( wxEVT_MOTION, wxMouseEventHandler( OPENGL_GAL::skipMouseEvent ) );
268 Connect( wxEVT_LEFT_DOWN, wxMouseEventHandler( OPENGL_GAL::skipMouseEvent ) );
269 Connect( wxEVT_LEFT_UP, wxMouseEventHandler( OPENGL_GAL::skipMouseEvent ) );
270 Connect( wxEVT_LEFT_DCLICK, wxMouseEventHandler( OPENGL_GAL::skipMouseEvent ) );
271 Connect( wxEVT_MIDDLE_DOWN, wxMouseEventHandler( OPENGL_GAL::skipMouseEvent ) );
272 Connect( wxEVT_MIDDLE_UP, wxMouseEventHandler( OPENGL_GAL::skipMouseEvent ) );
273 Connect( wxEVT_MIDDLE_DCLICK, wxMouseEventHandler( OPENGL_GAL::skipMouseEvent ) );
274 Connect( wxEVT_RIGHT_DOWN, wxMouseEventHandler( OPENGL_GAL::skipMouseEvent ) );
275 Connect( wxEVT_RIGHT_UP, wxMouseEventHandler( OPENGL_GAL::skipMouseEvent ) );
276 Connect( wxEVT_RIGHT_DCLICK, wxMouseEventHandler( OPENGL_GAL::skipMouseEvent ) );
277 Connect( wxEVT_AUX1_DOWN, wxMouseEventHandler( OPENGL_GAL::skipMouseEvent ) );
278 Connect( wxEVT_AUX1_UP, wxMouseEventHandler( OPENGL_GAL::skipMouseEvent ) );
279 Connect( wxEVT_AUX1_DCLICK, wxMouseEventHandler( OPENGL_GAL::skipMouseEvent ) );
280 Connect( wxEVT_AUX2_DOWN, wxMouseEventHandler( OPENGL_GAL::skipMouseEvent ) );
281 Connect( wxEVT_AUX2_UP, wxMouseEventHandler( OPENGL_GAL::skipMouseEvent ) );
282 Connect( wxEVT_AUX2_DCLICK, wxMouseEventHandler( OPENGL_GAL::skipMouseEvent ) );
283 Connect( wxEVT_MOUSEWHEEL, wxMouseEventHandler( OPENGL_GAL::skipMouseEvent ) );
284#if wxCHECK_VERSION( 3, 1, 0 ) || defined( USE_OSX_MAGNIFY_EVENT )
285 Connect( wxEVT_MAGNIFY, wxMouseEventHandler( OPENGL_GAL::skipMouseEvent ) );
286#endif
287#if defined _WIN32 || defined _WIN64
288 Connect( wxEVT_ENTER_WINDOW, wxMouseEventHandler( OPENGL_GAL::skipMouseEvent ) );
289#endif
290
291 SetSize( aParent->GetClientSize() );
293
294 // Grid color settings are different in Cairo and OpenGL
295 SetGridColor( COLOR4D( 0.8, 0.8, 0.8, 0.1 ) );
297
298 // Tesselator initialization
299 m_tesselator = gluNewTess();
301
302 gluTessProperty( m_tesselator, GLU_TESS_WINDING_RULE, GLU_TESS_WINDING_POSITIVE );
303
305
306 // Avoid uninitialized variables:
311}
static GL_CONTEXT_MANAGER & Get()
Return the GL_CONTEXT_MANAGER instance (singleton).
wxGLContext * CreateCtx(wxGLCanvas *aCanvas, const wxGLContext *aOther=nullptr)
Create a managed OpenGL context.
virtual wxSize GetNativePixelSize() const
HIDPI_GL_CANVAS(wxWindow *parent, wxWindowID id=wxID_ANY, const int *attribList=nullptr, const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxDefaultSize, long style=0, const wxString &name=wxGLCanvasName, const wxPalette &palette=wxNullPalette)
A color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:104
OPENGL_ANTIALIASING_MODE gl_antialiasing_mode
void SetGridColor(const COLOR4D &aGridColor)
Set the grid color.
VECTOR2I m_screenSize
Screen size in screen coordinates.
void SetAxesColor(const COLOR4D &aAxesColor)
Set the axes color.
GAL_DISPLAY_OPTIONS & m_options
GAL(GAL_DISPLAY_OPTIONS &aOptions)
void SetAntialiasingMode(OPENGL_ANTIALIASING_MODE aMode)
void skipMouseEvent(wxMouseEvent &aEvent)
Skip the mouse event to the parent.
unsigned int m_groupCounter
Counter used for generating keys for groups.
Definition: opengl_gal.h:340
VERTEX_MANAGER * m_overlayManager
Container for storing overlaid VERTEX_ITEMs.
Definition: opengl_gal.h:345
bool m_isInitialized
Basic initialization flag, has to be done when the window is visible.
Definition: opengl_gal.h:363
VERTEX_MANAGER * m_currentManager
Currently used VERTEX_MANAGER (for storing VERTEX_ITEMs).
Definition: opengl_gal.h:341
unsigned int m_mainBuffer
Main rendering target.
Definition: opengl_gal.h:350
std::unique_ptr< GL_BITMAP_CACHE > m_bitmapCache
Definition: opengl_gal.h:375
void SetTarget(RENDER_TARGET aTarget) override
Set the target for rendering.
bool m_isBitmapFontInitialized
Is the shader set to use bitmap fonts?
Definition: opengl_gal.h:362
unsigned int m_overlayBuffer
Auxiliary rendering target (for menus etc.)
Definition: opengl_gal.h:351
OPENGL_COMPOSITOR * m_compositor
Handles multiple rendering targets.
Definition: opengl_gal.h:349
VERTEX_MANAGER * m_cachedManager
Container for storing cached VERTEX_ITEMs.
Definition: opengl_gal.h:343
void onPaint(wxPaintEvent &aEvent)
This is the OnPaint event handler.
GLint ufm_worldPixelSize
Definition: opengl_gal.h:368
GLint ufm_antialiasingOffset
Definition: opengl_gal.h:371
wxEvtHandler * m_mouseListener
Definition: opengl_gal.h:331
VERTEX_MANAGER * m_nonCachedManager
Container for storing non-cached VERTEX_ITEMs.
Definition: opengl_gal.h:344
GLUtesselator * m_tesselator
Definition: opengl_gal.h:378
wxEvtHandler * m_paintListener
Definition: opengl_gal.h:332
bool m_isContextLocked
Used for assertion checking.
Definition: opengl_gal.h:366
bool m_isFramebufferInitialized
Are the framebuffers initialized?
Definition: opengl_gal.h:360
bool m_isGrouping
Was a group started?
Definition: opengl_gal.h:365
GLint ufm_screenPixelSize
Definition: opengl_gal.h:369
GLint ufm_pixelSizeMultiplier
Definition: opengl_gal.h:370
VERTEX_MANAGER * m_tempManager
Container for storing temp (diff mode) VERTEX_ITEMs.
Definition: opengl_gal.h:346
void onSetNativeCursor(wxSetCursorEvent &aEvent)
Give the correct cursor image when the native widget asks for it.
SHADER * m_shader
There is only one shader used for different objects.
Definition: opengl_gal.h:356
wxGLContext * m_glPrivContext
Canvas-specific OpenGL context.
Definition: opengl_gal.h:329
static wxGLContext * m_glMainContext
Parent OpenGL context.
Definition: opengl_gal.h:328
unsigned int m_tempBuffer
Temporary rendering target (for diffing etc.)
Definition: opengl_gal.h:352
static int m_instanceCounter
GL GAL instance counter.
Definition: opengl_gal.h:330
Provide the access to the OpenGL shaders.
Definition: shader.h:77
@ BLUE
Definition: color4d.h:56
@ TARGET_NONCACHED
Auxiliary rendering target (noncached)
Definition: definitions.h:49
static void InitTesselatorCallbacks(GLUtesselator *aTesselator)
static const int glAttributes[]
Definition: opengl_gal.cpp:84
VECTOR2< int > VECTOR2I
Definition: vector2d.h:618

References BLUE, GL_CONTEXT_MANAGER::CreateCtx(), GL_CONTEXT_MANAGER::Get(), HIDPI_GL_CANVAS::GetNativePixelSize(), KIGFX::GAL_DISPLAY_OPTIONS::gl_antialiasing_mode, InitTesselatorCallbacks(), m_bitmapCache, m_compositor, m_glMainContext, m_glPrivContext, m_groupCounter, m_instanceCounter, m_isBitmapFontInitialized, m_isFramebufferInitialized, m_isGrouping, m_isInitialized, KIGFX::GAL::m_options, KIGFX::GAL::m_screenSize, m_shader, m_tesselator, onPaint(), onSetNativeCursor(), KIGFX::OPENGL_COMPOSITOR::SetAntialiasingMode(), KIGFX::GAL::SetAxesColor(), KIGFX::GAL::SetGridColor(), SetTarget(), skipMouseEvent(), KIGFX::TARGET_NONCACHED, ufm_antialiasingOffset, ufm_pixelSizeMultiplier, ufm_screenPixelSize, and ufm_worldPixelSize.

◆ ~OPENGL_GAL()

OPENGL_GAL::~OPENGL_GAL ( )

Definition at line 314 of file opengl_gal.cpp.

315{
317
319 glFlush();
320 gluDeleteTess( m_tesselator );
321 ClearCache();
322
323 delete m_compositor;
324
325 if( m_isInitialized )
326 {
327 delete m_cachedManager;
328 delete m_nonCachedManager;
329 delete m_overlayManager;
330 delete m_tempManager;
331 }
332
334
335 // If it was the main context, then it will be deleted
336 // when the last OpenGL GAL instance is destroyed (a few lines below)
339
340 delete m_shader;
341
342 // Are we destroying the last GAL instance?
343 if( m_instanceCounter == 0 )
344 {
346
348 {
349 glDeleteTextures( 1, &g_fontTexture );
350 m_isBitmapFontLoaded = false;
351 }
352
355 m_glMainContext = nullptr;
356 }
357}
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.
void ClearCache() override
Delete all data created during caching of graphic items.
static GLuint g_fontTexture
Bitmap font texture handle (shared)
Definition: opengl_gal.h:334
static bool m_isBitmapFontLoaded
Is the bitmap font texture loaded?
Definition: opengl_gal.h:361

References ClearCache(), GL_CONTEXT_MANAGER::DestroyCtx(), g_fontTexture, GL_CONTEXT_MANAGER::Get(), GL_CONTEXT_MANAGER::LockCtx(), m_cachedManager, m_compositor, m_glMainContext, m_glPrivContext, m_instanceCounter, m_isBitmapFontLoaded, m_isInitialized, m_nonCachedManager, m_overlayManager, m_shader, m_tempManager, m_tesselator, and GL_CONTEXT_MANAGER::UnlockCtx().

Member Function Documentation

◆ AdvanceDepth()

void KIGFX::GAL::AdvanceDepth ( )
inlineinherited

Change the current depth to deeper, so it is possible to draw objects right beneath other.

Definition at line 905 of file graphics_abstraction_layer.h.

906 {
907 m_layerDepth -= 0.05;
908 }
double m_layerDepth
The actual layer depth.

References KIGFX::GAL::m_layerDepth.

Referenced by KIGFX::VIEW_GROUP::ViewDraw().

◆ BeginDrawing()

void OPENGL_GAL::BeginDrawing ( )
overridevirtual

Start/end drawing functions, draw calls can be only made in between the calls to BeginDrawing()/EndDrawing().

Normally you should create a GAL_DRAWING_CONTEXT RAII object, but I'm leaving these functions public for more precise (i.e. timing/profiling) control of the drawing process - Tom Begin the drawing, needs to be called for every new frame. Use GAL_DRAWING_CONTEXT RAII object unless you know what you're doing.

Reimplemented from KIGFX::GAL.

Definition at line 444 of file opengl_gal.cpp.

445{
446#ifdef KICAD_GAL_PROFILE
447 PROF_TIMER totalRealTime( "OPENGL_GAL::beginDrawing()", true );
448#endif /* KICAD_GAL_PROFILE */
449
450 wxASSERT_MSG( m_isContextLocked, "GAL_DRAWING_CONTEXT RAII object should have locked context. "
451 "Calling GAL::beginDrawing() directly is not allowed." );
452
453 wxASSERT_MSG( IsVisible(), "GAL::beginDrawing() must not be entered when GAL is not visible. "
454 "Other drawing routines will expect everything to be initialized "
455 "which will not be the case." );
456
457 if( !m_isInitialized )
458 init();
459
460 // Set up the view port
461 glMatrixMode( GL_PROJECTION );
462 glLoadIdentity();
463
464 // Create the screen transformation (Do the RH-LH conversion here)
465 glOrtho( 0, (GLint) m_screenSize.x, (GLsizei) m_screenSize.y, 0,
467
469 {
470 // Prepare rendering target buffers
474 try
475 {
477 }
478 catch( const std::runtime_error& )
479 {
480 wxLogVerbose( "Could not create a framebuffer for overlays.\n" );
481 m_overlayBuffer = 0;
482 }
483
485 }
486
488
489 // Disable 2D Textures
490 glDisable( GL_TEXTURE_2D );
491
492 glShadeModel( GL_FLAT );
493
494 // Enable the depth buffer
495 glEnable( GL_DEPTH_TEST );
496 glDepthFunc( GL_LESS );
497
498 // Setup blending, required for transparent objects
499 glEnable( GL_BLEND );
500 glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );
501
502 glMatrixMode( GL_MODELVIEW );
503
504 // Set up the world <-> screen transformation
506 GLdouble matrixData[16] = { 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1 };
507 matrixData[0] = m_worldScreenMatrix.m_data[0][0];
508 matrixData[1] = m_worldScreenMatrix.m_data[1][0];
509 matrixData[2] = m_worldScreenMatrix.m_data[2][0];
510 matrixData[4] = m_worldScreenMatrix.m_data[0][1];
511 matrixData[5] = m_worldScreenMatrix.m_data[1][1];
512 matrixData[6] = m_worldScreenMatrix.m_data[2][1];
513 matrixData[12] = m_worldScreenMatrix.m_data[0][2];
514 matrixData[13] = m_worldScreenMatrix.m_data[1][2];
515 matrixData[14] = m_worldScreenMatrix.m_data[2][2];
516 glLoadMatrixd( matrixData );
517
518 // Set defaults
521
522 // Remove all previously stored items
526
531
533 {
534 // Keep bitmap font texture always bound to the second texturing unit
535 const GLint FONT_TEXTURE_UNIT = 2;
536
537 // Either load the font atlas to video memory, or simply bind it to a texture unit
539 {
540 glActiveTexture( GL_TEXTURE0 + FONT_TEXTURE_UNIT );
541 glGenTextures( 1, &g_fontTexture );
542 glBindTexture( GL_TEXTURE_2D, g_fontTexture );
543 glTexImage2D( GL_TEXTURE_2D, 0, GL_RGB8, font_image.width, font_image.height, 0, GL_RGB,
544 GL_UNSIGNED_BYTE, font_image.pixels );
545 glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
546 glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
547 checkGlError( "loading bitmap font", __FILE__, __LINE__ );
548
549 glActiveTexture( GL_TEXTURE0 );
550
552 }
553 else
554 {
555 glActiveTexture( GL_TEXTURE0 + FONT_TEXTURE_UNIT );
556 glBindTexture( GL_TEXTURE_2D, g_fontTexture );
557 glActiveTexture( GL_TEXTURE0 );
558 }
559
560 // Set shader parameter
561 GLint ufm_fontTexture = m_shader->AddParameter( "u_fontTexture" );
562 GLint ufm_fontTextureWidth = m_shader->AddParameter( "u_fontTextureWidth" );
563 ufm_worldPixelSize = m_shader->AddParameter( "u_worldPixelSize" );
564 ufm_screenPixelSize = m_shader->AddParameter( "u_screenPixelSize" );
565 ufm_pixelSizeMultiplier = m_shader->AddParameter( "u_pixelSizeMultiplier" );
566 ufm_antialiasingOffset = m_shader->AddParameter( "u_antialiasingOffset" );
567
568 m_shader->Use();
569 m_shader->SetParameter( ufm_fontTexture, (int) FONT_TEXTURE_UNIT );
570 m_shader->SetParameter( ufm_fontTextureWidth, (int) font_image.width );
572 checkGlError( "setting bitmap font sampler as shader parameter", __FILE__, __LINE__ );
573
575 }
576
577 m_shader->Use();
579 (float) ( getWorldPixelSize() / GetScaleFactor() ) );
580 const VECTOR2D& screenPixelSize = getScreenPixelSize();
581 m_shader->SetParameter( ufm_screenPixelSize, screenPixelSize );
582 double pixelSizeMultiplier = m_compositor->GetAntialiasSupersamplingFactor();
583 m_shader->SetParameter( ufm_pixelSizeMultiplier, (float) pixelSizeMultiplier );
585 renderingOffset.x *= screenPixelSize.x;
586 renderingOffset.y *= screenPixelSize.y;
587 m_shader->SetParameter( ufm_antialiasingOffset, renderingOffset );
589
590 // Something betreen BeginDrawing and EndDrawing seems to depend on
591 // this texture unit being active, but it does not assure it itself.
592 glActiveTexture( GL_TEXTURE0 );
593
594 // Unbind buffers - set compositor for direct drawing
596
597#ifdef KICAD_GAL_PROFILE
598 totalRealTime.Stop();
599 wxLogTrace( traceGalProfile, wxT( "OPENGL_GAL::beginDrawing(): %.1f ms" ),
600 totalRealTime.msecs() );
601#endif /* KICAD_GAL_PROFILE */
602}
double GetScaleFactor() const
Get the current scale factor.
MATRIX3x3D m_worldScreenMatrix
World transformation.
VECTOR2D m_depthRange
Range of the depth.
virtual void SetFillColor(const COLOR4D &aColor)
Set the fill color.
COLOR4D m_fillColor
The fill color.
virtual void SetStrokeColor(const COLOR4D &aColor)
Set the stroke color.
COLOR4D m_strokeColor
The color of the outlines.
VECTOR2D GetAntialiasRenderingOffset() const
virtual void Begin() override
Call this at the beginning of each frame.
static const unsigned int DIRECT_RENDERING
virtual void Initialize() override
Perform primary initialization, necessary to use the object.
int GetAntialiasSupersamplingFactor() const
virtual void SetBuffer(unsigned int aBufferHandle) override
Set the selected buffer as the rendering target.
virtual unsigned int CreateBuffer() override
Prepare a new buffer that may be used as a rendering target.
bool IsVisible() const override
Return true if the GAL canvas is visible on the screen.
Definition: opengl_gal.h:109
double getWorldPixelSize() const
Definition: opengl_gal.cpp:429
void ComputeWorldScreenMatrix() override
Compute the world <-> screen transformation matrix.
VECTOR2D getScreenPixelSize() const
Definition: opengl_gal.cpp:436
void init()
Basic OpenGL initialization and feature checks.
void SetParameter(int aParameterNumber, float aValue) const
Set a parameter of the shader.
Definition: shader.cpp:143
void Use()
Use the shader.
Definition: shader.h:126
int AddParameter(const std::string &aParameterName)
Add a parameter to the parameter queue.
Definition: shader.cpp:130
void Deactivate()
Deactivate the shader and use the default OpenGL program.
Definition: shader.h:135
void Clear() const
Remove all the stored vertices from the container.
void BeginDrawing() const
Prepare buffers and items to start drawing.
T m_data[3][3]
Definition: matrix3x3.h:64
A small class to help profiling.
Definition: profile.h:47
const wxChar *const traceGalProfile
Flag to enable debug output of GAL performance profiling.
FONT_IMAGE_TYPE font_image
unsigned char pixels[1024 *1024 *3]
Definition: gl_resources.h:38
int checkGlError(const std::string &aInfo, const char *aFile, int aLine, bool aThrow)
Check if a recent OpenGL operation has failed.
Definition: utils.cpp:45

References KIGFX::SHADER::AddParameter(), KIGFX::OPENGL_COMPOSITOR::Begin(), KIGFX::VERTEX_MANAGER::BeginDrawing(), checkGlError(), KIGFX::VERTEX_MANAGER::Clear(), ComputeWorldScreenMatrix(), KIGFX::OPENGL_COMPOSITOR::CreateBuffer(), KIGFX::SHADER::Deactivate(), KIGFX::OPENGL_COMPOSITOR::DIRECT_RENDERING, KIGFX::BUILTIN_FONT::font_image, g_fontTexture, KIGFX::OPENGL_COMPOSITOR::GetAntialiasRenderingOffset(), KIGFX::OPENGL_COMPOSITOR::GetAntialiasSupersamplingFactor(), HIDPI_GL_CANVAS::GetScaleFactor(), getScreenPixelSize(), getWorldPixelSize(), KIGFX::BUILTIN_FONT::FONT_IMAGE_TYPE::height, init(), KIGFX::OPENGL_COMPOSITOR::Initialize(), IsVisible(), m_cachedManager, m_compositor, MATRIX3x3< T >::m_data, KIGFX::GAL::m_depthRange, KIGFX::GAL::m_fillColor, m_isBitmapFontInitialized, m_isBitmapFontLoaded, m_isContextLocked, m_isFramebufferInitialized, m_isInitialized, m_mainBuffer, m_nonCachedManager, m_overlayBuffer, m_overlayManager, KIGFX::GAL::m_screenSize, m_shader, KIGFX::GAL::m_strokeColor, m_tempBuffer, m_tempManager, KIGFX::GAL::m_worldScreenMatrix, PROF_TIMER::msecs(), KIGFX::BUILTIN_FONT::FONT_IMAGE_TYPE::pixels, KIGFX::OPENGL_COMPOSITOR::SetBuffer(), KIGFX::GAL::SetFillColor(), KIGFX::SHADER::SetParameter(), KIGFX::GAL::SetStrokeColor(), PROF_TIMER::Stop(), traceGalProfile, ufm_antialiasingOffset, ufm_pixelSizeMultiplier, ufm_screenPixelSize, ufm_worldPixelSize, KIGFX::SHADER::Use(), KIGFX::BUILTIN_FONT::FONT_IMAGE_TYPE::width, VECTOR2< T >::x, and VECTOR2< T >::y.

◆ BeginGroup()

int OPENGL_GAL::BeginGroup ( )
overridevirtual

Begin a group.

A group is a collection of graphic items. Hierarchical groups are possible, attributes and transformations can be used.

Returns
the number of the group.

Reimplemented from KIGFX::GAL.

Definition at line 1822 of file opengl_gal.cpp.

1823{
1824 m_isGrouping = true;
1825
1826 std::shared_ptr<VERTEX_ITEM> newItem = std::make_shared<VERTEX_ITEM>( *m_cachedManager );
1827 int groupNumber = getNewGroupNumber();
1828 m_groups.insert( std::make_pair( groupNumber, newItem ) );
1829
1830 return groupNumber;
1831}
unsigned int getNewGroupNumber()
Return a valid key that can be used as a new group number.
GROUPS_MAP m_groups
Stores information about VBO objects (groups)
Definition: opengl_gal.h:339

References getNewGroupNumber(), m_cachedManager, m_groups, and m_isGrouping.

◆ beginUpdate()

void OPENGL_GAL::beginUpdate ( )
overrideprivatevirtual

Reimplemented from KIGFX::GAL.

Definition at line 687 of file opengl_gal.cpp.

688{
689 wxASSERT_MSG( m_isContextLocked, "GAL_UPDATE_CONTEXT RAII object should have locked context. "
690 "Calling this from anywhere else is not allowed." );
691
692 wxASSERT_MSG( IsVisible(), "GAL::beginUpdate() must not be entered when GAL is not visible. "
693 "Other update routines will expect everything to be initialized "
694 "which will not be the case." );
695
696 if( !m_isInitialized )
697 init();
698
700}
void Map()
Map vertex buffer.

References init(), IsVisible(), m_cachedManager, m_isContextLocked, m_isInitialized, and KIGFX::VERTEX_MANAGER::Map().

◆ BitmapText()

void OPENGL_GAL::BitmapText ( const wxString &  aText,
const VECTOR2I aPosition,
const EDA_ANGLE aAngle 
)
overridevirtual

Draw a text using a bitmap font.

It should be faster than StrokeText(), but can be used only for non-Gerber elements.

Parameters
aTextis the text to be drawn.
aPositionis the text position in world coordinates.
aAngleis the text rotation angle.

Reimplemented from KIGFX::GAL.

Definition at line 1413 of file opengl_gal.cpp.

1415{
1416 // Fallback to generic impl (which uses the stroke font) on cases we don't handle
1417 if( IsTextMirrored()
1418 || aText.Contains( wxT( "^{" ) )
1419 || aText.Contains( wxT( "_{" ) )
1420 || aText.Contains( wxT( "\n" ) ) )
1421 {
1422 return GAL::BitmapText( aText, aPosition, aAngle );
1423 }
1424
1425 const UTF8 text( aText );
1426 VECTOR2D textSize;
1427 float commonOffset;
1428 std::tie( textSize, commonOffset ) = computeBitmapTextSize( text );
1429
1430 const double SCALE = 1.4 * GetGlyphSize().y / textSize.y;
1431 double overbarHeight = textSize.y;
1432
1433 Save();
1434
1436 m_currentManager->Translate( aPosition.x, aPosition.y, m_layerDepth );
1437 m_currentManager->Rotate( aAngle.AsRadians(), 0.0f, 0.0f, -1.0f );
1438
1439 double sx = SCALE * ( m_globalFlipX ? -1.0 : 1.0 );
1440 double sy = SCALE * ( m_globalFlipY ? -1.0 : 1.0 );
1441
1442 m_currentManager->Scale( sx, sy, 0 );
1443 m_currentManager->Translate( 0, -commonOffset, 0 );
1444
1445 switch( GetHorizontalJustify() )
1446 {
1448 Translate( VECTOR2D( -textSize.x / 2.0, 0 ) );
1449 break;
1450
1452 //if( !IsTextMirrored() )
1453 Translate( VECTOR2D( -textSize.x, 0 ) );
1454 break;
1455
1457 //if( IsTextMirrored() )
1458 //Translate( VECTOR2D( -textSize.x, 0 ) );
1459 break;
1460 }
1461
1462 switch( GetVerticalJustify() )
1463 {
1465 break;
1466
1468 Translate( VECTOR2D( 0, -textSize.y / 2.0 ) );
1469 overbarHeight = 0;
1470 break;
1471
1473 Translate( VECTOR2D( 0, -textSize.y ) );
1474 overbarHeight = -textSize.y / 2.0;
1475 break;
1476 }
1477
1478 int overbarLength = 0;
1479 int overbarDepth = -1;
1480 int braceNesting = 0;
1481
1482 auto iterateString =
1483 [&]( std::function<void( int aOverbarLength, int aOverbarHeight )> overbarFn,
1484 std::function<int( unsigned long aChar )> bitmapCharFn )
1485 {
1486 for( UTF8::uni_iter chIt = text.ubegin(), end = text.uend(); chIt < end; ++chIt )
1487 {
1488 wxASSERT_MSG( *chIt != '\n' && *chIt != '\r',
1489 "No support for multiline bitmap text yet" );
1490
1491 if( *chIt == '~' && overbarDepth == -1 )
1492 {
1493 UTF8::uni_iter lookahead = chIt;
1494
1495 if( ++lookahead != end && *lookahead == '{' )
1496 {
1497 chIt = lookahead;
1498 overbarDepth = braceNesting;
1499 braceNesting++;
1500 continue;
1501 }
1502 }
1503 else if( *chIt == '{' )
1504 {
1505 braceNesting++;
1506 }
1507 else if( *chIt == '}' )
1508 {
1509 if( braceNesting > 0 )
1510 braceNesting--;
1511
1512 if( braceNesting == overbarDepth )
1513 {
1514 overbarFn( overbarLength, overbarHeight );
1515 overbarLength = 0;
1516
1517 overbarDepth = -1;
1518 continue;
1519 }
1520 }
1521
1522 if( overbarDepth != -1 )
1523 overbarLength += bitmapCharFn( *chIt );
1524 else
1525 bitmapCharFn( *chIt );
1526 }
1527 };
1528
1529 // First, calculate the amount of characters and overbars to reserve
1530
1531 int charsCount = 0;
1532 int overbarsCount = 0;
1533
1534 iterateString(
1535 [&overbarsCount]( int aOverbarLength, int aOverbarHeight )
1536 {
1537 overbarsCount++;
1538 },
1539 [&charsCount]( unsigned long aChar ) -> int
1540 {
1541 if( aChar != ' ' )
1542 charsCount++;
1543
1544 return 0;
1545 } );
1546
1547 m_currentManager->Reserve( 6 * charsCount + 6 * overbarsCount );
1548
1549 // Now reset the state and actually draw the characters and overbars
1550 overbarLength = 0;
1551 overbarDepth = -1;
1552 braceNesting = 0;
1553
1554 iterateString(
1555 [&]( int aOverbarLength, int aOverbarHeight )
1556 {
1557 drawBitmapOverbar( aOverbarLength, aOverbarHeight, false );
1558 },
1559 [&]( unsigned long aChar ) -> int
1560 {
1561 return drawBitmapChar( aChar, false );
1562 } );
1563
1564 // Handle the case when overbar is active till the end of the drawn text
1565 m_currentManager->Translate( 0, commonOffset, 0 );
1566
1567 if( overbarDepth != -1 && overbarLength > 0 )
1568 drawBitmapOverbar( overbarLength, overbarHeight );
1569
1570 Restore();
1571}
double AsRadians() const
Definition: eda_angle.h:153
double r
Red component.
Definition: color4d.h:384
double g
Green component.
Definition: color4d.h:385
double a
Alpha component.
Definition: color4d.h:387
double b
Blue component.
Definition: color4d.h:386
bool IsTextMirrored() const
GR_TEXT_H_ALIGN_T GetHorizontalJustify() const
const VECTOR2I & GetGlyphSize() const
bool m_globalFlipY
Flag for Y axis flipping.
virtual void BitmapText(const wxString &aText, const VECTOR2I &aPosition, const EDA_ANGLE &aAngle)
Draw a text using a bitmap font.
bool m_globalFlipX
Flag for X axis flipping.
GR_TEXT_V_ALIGN_T GetVerticalJustify() const
std::pair< VECTOR2D, float > computeBitmapTextSize(const UTF8 &aText) const
Compute a size of text drawn using bitmap font with current text setting applied.
void drawBitmapOverbar(double aLength, double aHeight, bool aReserve=true)
Draw an overbar over the currently drawn text.
void Translate(const VECTOR2D &aTranslation) override
Translate the context.
void Restore() override
Restore the context.
int drawBitmapChar(unsigned long aChar, bool aReserve=true)
Draw a single character using bitmap font.
void Save() override
Save the context.
void Color(const COLOR4D &aColor)
Changes currently used color that will be applied to newly added vertices.
bool Reserve(unsigned int aSize)
Allocate space for vertices, so it will be used with subsequent Vertex() calls.
void Rotate(GLfloat aAngle, GLfloat aX, GLfloat aY, GLfloat aZ)
Multiply the current matrix by a rotation matrix, so the newly vertices will be rotated by the given ...
void Scale(GLfloat aX, GLfloat aY, GLfloat aZ)
Multiply the current matrix by a scaling matrix, so the newly vertices will be scaled by the given fa...
void Translate(GLfloat aX, GLfloat aY, GLfloat aZ)
Multiply the current matrix by a translation matrix, so newly vertices will be translated by the give...
uni_iter is a non-mutating iterator that walks through unicode code points in the UTF8 encoded string...
Definition: utf8.h:204
An 8 bit string that is assuredly encoded in UTF8, and supplies special conversion support to and fro...
Definition: utf8.h:71
@ GR_TEXT_H_ALIGN_CENTER
@ GR_TEXT_H_ALIGN_RIGHT
@ GR_TEXT_H_ALIGN_LEFT
@ GR_TEXT_V_ALIGN_BOTTOM
@ GR_TEXT_V_ALIGN_CENTER
@ GR_TEXT_V_ALIGN_TOP
VECTOR2< double > VECTOR2D
Definition: vector2d.h:617

References KIGFX::COLOR4D::a, EDA_ANGLE::AsRadians(), KIGFX::COLOR4D::b, KIGFX::GAL::BitmapText(), KIGFX::VERTEX_MANAGER::Color(), computeBitmapTextSize(), drawBitmapChar(), drawBitmapOverbar(), KIGFX::COLOR4D::g, KIGFX::GAL::GetGlyphSize(), KIGFX::GAL::GetHorizontalJustify(), KIGFX::GAL::GetVerticalJustify(), GR_TEXT_H_ALIGN_CENTER, GR_TEXT_H_ALIGN_LEFT, GR_TEXT_H_ALIGN_RIGHT, GR_TEXT_V_ALIGN_BOTTOM, GR_TEXT_V_ALIGN_CENTER, GR_TEXT_V_ALIGN_TOP, KIGFX::GAL::IsTextMirrored(), m_currentManager, KIGFX::GAL::m_globalFlipX, KIGFX::GAL::m_globalFlipY, KIGFX::GAL::m_layerDepth, KIGFX::GAL::m_strokeColor, KIGFX::COLOR4D::r, KIGFX::VERTEX_MANAGER::Reserve(), Restore(), KIGFX::VERTEX_MANAGER::Rotate(), Save(), KIGFX::VERTEX_MANAGER::Scale(), text, Translate(), KIGFX::VERTEX_MANAGER::Translate(), VECTOR2< T >::x, and VECTOR2< T >::y.

◆ blitCursor()

void OPENGL_GAL::blitCursor ( )
private

Blit cursor into the current screen.

Definition at line 2446 of file opengl_gal.cpp.

2447{
2448 if( !IsCursorEnabled() )
2449 return;
2450
2452
2453 const int cursorSize = m_fullscreenCursor ? 8000 : 80;
2454
2455 VECTOR2D cursorBegin = m_cursorPosition - cursorSize / ( 2 * m_worldScale );
2456 VECTOR2D cursorEnd = m_cursorPosition + cursorSize / ( 2 * m_worldScale );
2457 VECTOR2D cursorCenter = ( cursorBegin + cursorEnd ) / 2;
2458
2459 const COLOR4D cColor = getCursorColor();
2460 const COLOR4D color( cColor.r * cColor.a, cColor.g * cColor.a, cColor.b * cColor.a, 1.0 );
2461
2462 glActiveTexture( GL_TEXTURE0 );
2463 glDisable( GL_TEXTURE_2D );
2464 glLineWidth( 1.0 );
2465 glColor4d( color.r, color.g, color.b, color.a );
2466
2467 glBegin( GL_LINES );
2468 glVertex2d( cursorCenter.x, cursorBegin.y );
2469 glVertex2d( cursorCenter.x, cursorEnd.y );
2470
2471 glVertex2d( cursorBegin.x, cursorCenter.y );
2472 glVertex2d( cursorEnd.x, cursorCenter.y );
2473 glEnd();
2474}
int color
Definition: DXF_plotter.cpp:57
bool IsCursorEnabled() const
Return information about cursor visibility.
COLOR4D getCursorColor() const
Get the actual cursor color to draw.
VECTOR2D m_cursorPosition
Current cursor position (world coordinates)
double m_worldScale
The scale factor world->screen.
bool m_fullscreenCursor
Shape of the cursor (fullscreen or small cross)

References KIGFX::COLOR4D::a, KIGFX::COLOR4D::b, color, KIGFX::OPENGL_COMPOSITOR::DIRECT_RENDERING, KIGFX::COLOR4D::g, KIGFX::GAL::getCursorColor(), KIGFX::GAL::IsCursorEnabled(), m_compositor, KIGFX::GAL::m_cursorPosition, KIGFX::GAL::m_fullscreenCursor, KIGFX::GAL::m_worldScale, KIGFX::COLOR4D::r, KIGFX::OPENGL_COMPOSITOR::SetBuffer(), VECTOR2< T >::x, and VECTOR2< T >::y.

Referenced by EndDrawing().

◆ calcAngleStep()

double KIGFX::OPENGL_GAL::calcAngleStep ( double  aRadius) const
inlineprivate

Compute the angle step when drawing arcs/circles approximated with lines.

Definition at line 563 of file opengl_gal.h.

564 {
565 // Bigger arcs need smaller alpha increment to make them look smooth
566 return std::min( 1e6 / aRadius, 2.0 * M_PI / SEG_PER_CIRCLE_COUNT );
567 }
#define SEG_PER_CIRCLE_COUNT
Definition: opengl_gal.h:52

References SEG_PER_CIRCLE_COUNT.

Referenced by DrawArc().

◆ ChangeGroupColor()

void OPENGL_GAL::ChangeGroupColor ( int  aGroupNumber,
const COLOR4D aNewColor 
)
overridevirtual

Change the color used to draw the group.

Parameters
aGroupNumberis the group number.
aNewColoris the new color.

Reimplemented from KIGFX::GAL.

Definition at line 1850 of file opengl_gal.cpp.

1851{
1852 auto group = m_groups.find( aGroupNumber );
1853
1854 if( group != m_groups.end() )
1855 m_cachedManager->ChangeItemColor( *group->second, aNewColor );
1856}
void ChangeItemColor(const VERTEX_ITEM &aItem, const COLOR4D &aColor) const
Change the color of all vertices owned by an item.

References KIGFX::VERTEX_MANAGER::ChangeItemColor(), group, m_cachedManager, and m_groups.

◆ ChangeGroupDepth()

void OPENGL_GAL::ChangeGroupDepth ( int  aGroupNumber,
int  aDepth 
)
overridevirtual

Change the depth (Z-axis position) of the group.

Parameters
aGroupNumberis the group number.
aDepthis the new depth.

Reimplemented from KIGFX::GAL.

Definition at line 1859 of file opengl_gal.cpp.

1860{
1861 auto group = m_groups.find( aGroupNumber );
1862
1863 if( group != m_groups.end() )
1864 m_cachedManager->ChangeItemDepth( *group->second, aDepth );
1865}
void ChangeItemDepth(const VERTEX_ITEM &aItem, GLfloat aDepth) const
Change the depth of all vertices owned by an item.

References KIGFX::VERTEX_MANAGER::ChangeItemDepth(), group, m_cachedManager, and m_groups.

◆ CheckFeatures()

wxString OPENGL_GAL::CheckFeatures ( GAL_DISPLAY_OPTIONS aOptions)
static

Checks OpenGL features.

Parameters
aOptions
Returns
wxEmptyString if OpenGL 2.1 or greater is available, otherwise returns error message

Definition at line 360 of file opengl_gal.cpp.

361{
362 wxString retVal = wxEmptyString;
363
364 wxFrame* testFrame = new wxFrame( nullptr, wxID_ANY, wxT( "" ), wxDefaultPosition,
365 wxSize( 1, 1 ), wxFRAME_TOOL_WINDOW | wxNO_BORDER );
366
367 KIGFX::OPENGL_GAL* opengl_gal = nullptr;
368
369 try
370 {
371 opengl_gal = new KIGFX::OPENGL_GAL( aOptions, testFrame );
372
373 testFrame->Raise();
374 testFrame->Show();
375
376 GAL_CONTEXT_LOCKER lock( opengl_gal );
377 opengl_gal->init();
378 }
379 catch( std::runtime_error& err )
380 {
381 //Test failed
382 retVal = wxString( err.what() );
383 }
384
385 delete opengl_gal;
386 delete testFrame;
387
388 return retVal;
389}
OpenGL implementation of the Graphics Abstraction Layer.
Definition: opengl_gal.h:70

References init().

Referenced by EDA_DRAW_PANEL_GAL::SwitchBackend().

◆ ClearCache()

void OPENGL_GAL::ClearCache ( )
overridevirtual

Delete all data created during caching of graphic items.

Reimplemented from KIGFX::GAL.

Definition at line 1875 of file opengl_gal.cpp.

1876{
1877 m_bitmapCache = std::make_unique<GL_BITMAP_CACHE>();
1878
1879 m_groups.clear();
1880
1881 if( m_isInitialized )
1883}

References KIGFX::VERTEX_MANAGER::Clear(), m_bitmapCache, m_cachedManager, m_groups, and m_isInitialized.

Referenced by ~OPENGL_GAL().

◆ ClearScreen()

void OPENGL_GAL::ClearScreen ( )
overridevirtual

Clear the screen.

Parameters
aColoris the color used for clearing.

Reimplemented from KIGFX::GAL.

Definition at line 1763 of file opengl_gal.cpp.

1764{
1765 // Clear screen
1767
1768 // NOTE: Black used here instead of m_clearColor; it will be composited later
1769 glClearColor( 0, 0, 0, 1 );
1770 glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT );
1771}

References KIGFX::OPENGL_COMPOSITOR::DIRECT_RENDERING, m_compositor, and KIGFX::OPENGL_COMPOSITOR::SetBuffer().

◆ ClearTarget()

void OPENGL_GAL::ClearTarget ( RENDER_TARGET  aTarget)
overridevirtual

Clear the target for rendering.

Parameters
aTargetis the target to be cleared.

Reimplemented from KIGFX::GAL.

Definition at line 1907 of file opengl_gal.cpp.

1908{
1909 // Save the current state
1910 unsigned int oldTarget = m_compositor->GetBuffer();
1911
1912 switch( aTarget )
1913 {
1914 // Cached and noncached items are rendered to the same buffer
1915 default:
1916 case TARGET_CACHED:
1917 case TARGET_NONCACHED:
1919 break;
1920
1921 case TARGET_TEMP:
1923 break;
1924
1925 case TARGET_OVERLAY:
1926 if( m_overlayBuffer )
1928 break;
1929 }
1930
1931 if( aTarget != TARGET_OVERLAY )
1933 else if( m_overlayBuffer )
1935
1936 // Restore the previous state
1937 m_compositor->SetBuffer( oldTarget );
1938}
static const COLOR4D BLACK
Definition: color4d.h:394
virtual unsigned int GetBuffer() const override
Return currently used buffer handle.
virtual void ClearBuffer(const COLOR4D &aColor) override
Clear the selected buffer (set by the SetBuffer() function).
@ TARGET_TEMP
Temporary target for drawing in separate layer.
Definition: definitions.h:51
@ TARGET_CACHED
Main rendering target (cached)
Definition: definitions.h:48
@ TARGET_OVERLAY
Items that may change while the view stays the same (noncached)
Definition: definitions.h:50

References KIGFX::COLOR4D::BLACK, KIGFX::OPENGL_COMPOSITOR::ClearBuffer(), KIGFX::OPENGL_COMPOSITOR::GetBuffer(), KIGFX::GAL::m_clearColor, m_compositor, m_mainBuffer, m_overlayBuffer, m_tempBuffer, KIGFX::OPENGL_COMPOSITOR::SetBuffer(), KIGFX::TARGET_CACHED, KIGFX::TARGET_NONCACHED, KIGFX::TARGET_OVERLAY, and KIGFX::TARGET_TEMP.

Referenced by StartDiffLayer().

◆ computeBitmapTextSize()

std::pair< VECTOR2D, float > OPENGL_GAL::computeBitmapTextSize ( const UTF8 aText) const
private

Compute a size of text drawn using bitmap font with current text setting applied.

Parameters
aTextis the text to be drawn.
Returns
Pair containing text bounding box and common Y axis offset. The values are expressed as a number of pixels on the bitmap font texture and need to be scaled before drawing.

Definition at line 2372 of file opengl_gal.cpp.

2373{
2374 static const FONT_GLYPH_TYPE* defaultGlyph = LookupGlyph( '(' ); // for strange chars
2375
2376 VECTOR2D textSize( 0, 0 );
2377 float commonOffset = std::numeric_limits<float>::max();
2378 float charHeight = font_information.max_y - defaultGlyph->miny;
2379 int overbarDepth = -1;
2380 int braceNesting = 0;
2381
2382 for( UTF8::uni_iter chIt = aText.ubegin(), end = aText.uend(); chIt < end; ++chIt )
2383 {
2384 if( *chIt == '~' && overbarDepth == -1 )
2385 {
2386 UTF8::uni_iter lookahead = chIt;
2387
2388 if( ++lookahead != end && *lookahead == '{' )
2389 {
2390 chIt = lookahead;
2391 overbarDepth = braceNesting;
2392 braceNesting++;
2393 continue;
2394 }
2395 }
2396 else if( *chIt == '{' )
2397 {
2398 braceNesting++;
2399 }
2400 else if( *chIt == '}' )
2401 {
2402 if( braceNesting > 0 )
2403 braceNesting--;
2404
2405 if( braceNesting == overbarDepth )
2406 {
2407 overbarDepth = -1;
2408 continue;
2409 }
2410 }
2411
2412 const FONT_GLYPH_TYPE* glyph = LookupGlyph( *chIt );
2413
2414 if( !glyph // Not coded in font
2415 || *chIt == '-' || *chIt == '_' ) // Strange size of these 2 chars
2416 {
2417 glyph = defaultGlyph;
2418 }
2419
2420 if( glyph )
2421 textSize.x += glyph->advance;
2422 }
2423
2424 textSize.y = std::max<float>( textSize.y, charHeight );
2425 commonOffset = std::min<float>( font_information.max_y - defaultGlyph->maxy, commonOffset );
2426 textSize.y -= commonOffset;
2427
2428 return std::make_pair( textSize, commonOffset );
2429}
uni_iter uend() const
Return a uni_iter initialized to the end of "this" UTF8 byte sequence.
Definition: utf8.h:287
uni_iter ubegin() const
Returns a uni_iter initialized to the start of "this" UTF8 byte sequence.
Definition: utf8.h:279
const FONT_GLYPH_TYPE * LookupGlyph(unsigned int aCodepoint)
FONT_INFO_TYPE font_information

References KIGFX::BUILTIN_FONT::FONT_GLYPH_TYPE::advance, KIGFX::BUILTIN_FONT::font_information, KIGFX::BUILTIN_FONT::LookupGlyph(), KIGFX::BUILTIN_FONT::FONT_INFO_TYPE::max_y, KIGFX::BUILTIN_FONT::FONT_GLYPH_TYPE::maxy, KIGFX::BUILTIN_FONT::FONT_GLYPH_TYPE::miny, UTF8::ubegin(), UTF8::uend(), VECTOR2< T >::x, and VECTOR2< T >::y.

Referenced by BitmapText().

◆ computeMinGridSpacing()

double GAL::computeMinGridSpacing ( ) const
protectedinherited

compute minimum grid spacing from the grid settings

Returns
the minimum spacing to use for drawing the grid

Definition at line 214 of file graphics_abstraction_layer.cpp.

215{
216 // just return the current value. This could be cleverer and take
217 // into account other settings in future
218 return m_gridMinSpacing;
219}
int m_gridMinSpacing
Minimum screen size of the grid (pixels) below which the grid is not drawn.

References KIGFX::GAL::m_gridMinSpacing.

Referenced by KIGFX::CAIRO_GAL_BASE::DrawGrid(), and DrawGrid().

◆ computeWorldScale()

void KIGFX::GAL::computeWorldScale ( )
inlineprotectedinherited

Compute the scaling factor for the world->screen matrix.

Definition at line 968 of file graphics_abstraction_layer.h.

969 {
971 }
double m_zoomFactor
The zoom factor.
double m_worldUnitLength
The unit length of the world coordinates [inch].
double m_screenDPI
The dots per inch of the screen.

References KIGFX::GAL::m_screenDPI, KIGFX::GAL::m_worldScale, KIGFX::GAL::m_worldUnitLength, and KIGFX::GAL::m_zoomFactor.

Referenced by KIGFX::GAL::ComputeWorldScreenMatrix(), ComputeWorldScreenMatrix(), and KIGFX::GAL::GAL().

◆ ComputeWorldScreenMatrix()

void OPENGL_GAL::ComputeWorldScreenMatrix ( )
overridevirtual

Compute the world <-> screen transformation matrix.

Reimplemented from KIGFX::GAL.

Definition at line 2649 of file opengl_gal.cpp.

2650{
2652 auto pixelSize = m_worldScale;
2653
2654 // we need -m_lookAtPoint == -k * pixelSize + 0.5 * pixelSize for OpenGL
2655 // meaning m_lookAtPoint = (k-0.5)*pixelSize with integer k
2658
2660}
void computeWorldScale()
Compute the scaling factor for the world->screen matrix.
virtual void ComputeWorldScreenMatrix()
Compute the world <-> screen transformation matrix.
VECTOR2D m_lookAtPoint
Point to be looked at in world space.
double round_to_half_pixel(double f, double r)

References KIGFX::GAL::computeWorldScale(), KIGFX::GAL::ComputeWorldScreenMatrix(), KIGFX::GAL::m_lookAtPoint, KIGFX::GAL::m_worldScale, round_to_half_pixel(), VECTOR2< T >::x, and VECTOR2< T >::y.

Referenced by BeginDrawing().

◆ DeleteGroup()

void OPENGL_GAL::DeleteGroup ( int  aGroupNumber)
overridevirtual

Delete the group from the memory.

Parameters
aGroupNumberis the group number.

Reimplemented from KIGFX::GAL.

Definition at line 1868 of file opengl_gal.cpp.

1869{
1870 // Frees memory in the container as well
1871 m_groups.erase( aGroupNumber );
1872}

References m_groups.

◆ DrawArc()

void OPENGL_GAL::DrawArc ( const VECTOR2D aCenterPoint,
double  aRadius,
const EDA_ANGLE aStartAngle,
const EDA_ANGLE aEndAngle 
)
overridevirtual

Draw an arc.

Parameters
aCenterPointis the center point of the arc.
aRadiusis the arc radius.
aStartAngleis the start angle of the arc.
aEndAngleis the end angle of the arc.

Reimplemented from KIGFX::GAL.

Definition at line 852 of file opengl_gal.cpp.

854{
855 if( aRadius <= 0 )
856 return;
857
858 double startAngle = aStartAngle.AsRadians();
859 double endAngle = aEndAngle.AsRadians();
860
861 // Swap the angles, if start angle is greater than end angle
862 SWAP( startAngle, >, endAngle );
863
864 const double alphaIncrement = calcAngleStep( aRadius );
865
866 Save();
867 m_currentManager->Translate( aCenterPoint.x, aCenterPoint.y, 0.0 );
868
869 if( m_isFillEnabled )
870 {
871 double alpha;
874
875 // Triangle fan
876 for( alpha = startAngle; ( alpha + alphaIncrement ) < endAngle; )
877 {
880 m_currentManager->Vertex( cos( alpha ) * aRadius, sin( alpha ) * aRadius,
881 m_layerDepth );
882 alpha += alphaIncrement;
883 m_currentManager->Vertex( cos( alpha ) * aRadius, sin( alpha ) * aRadius,
884 m_layerDepth );
885 }
886
887 // The last missing triangle
888 const VECTOR2D endPoint( cos( endAngle ) * aRadius, sin( endAngle ) * aRadius );
889
892 m_currentManager->Vertex( cos( alpha ) * aRadius, sin( alpha ) * aRadius, m_layerDepth );
893 m_currentManager->Vertex( endPoint.x, endPoint.y, m_layerDepth );
894 }
895
897 {
900
901 VECTOR2D p( cos( startAngle ) * aRadius, sin( startAngle ) * aRadius );
902 double alpha;
903
904 for( alpha = startAngle + alphaIncrement; alpha <= endAngle; alpha += alphaIncrement )
905 {
906 VECTOR2D p_next( cos( alpha ) * aRadius, sin( alpha ) * aRadius );
907 DrawLine( p, p_next );
908
909 p = p_next;
910 }
911
912 // Draw the last missing part
913 if( alpha != endAngle )
914 {
915 VECTOR2D p_last( cos( endAngle ) * aRadius, sin( endAngle ) * aRadius );
916 DrawLine( p, p_last );
917 }
918 }
919
920 Restore();
921}
bool m_isFillEnabled
Is filling of graphic objects enabled ?
bool m_isStrokeEnabled
Are the outlines stroked ?
void DrawLine(const VECTOR2D &aStartPoint, const VECTOR2D &aEndPoint) override
Draw a line.
Definition: opengl_gal.cpp:712
double calcAngleStep(double aRadius) const
Compute the angle step when drawing arcs/circles approximated with lines.
Definition: opengl_gal.h:563
bool Vertex(const VERTEX &aVertex)
Add a vertex with the given coordinates to the currently set item.
void Shader(GLfloat aShaderType, GLfloat aParam1=0.0f, GLfloat aParam2=0.0f, GLfloat aParam3=0.0f)
Change currently used shader and its parameters that will be applied to newly added vertices.
#define SWAP(varA, condition, varB)
Swap the variables if a condition is met.
Definition: definitions.h:31
@ SHADER_NONE
Definition: vertex_common.h:47

References KIGFX::COLOR4D::a, EDA_ANGLE::AsRadians(), KIGFX::COLOR4D::b, calcAngleStep(), KIGFX::VERTEX_MANAGER::Color(), DrawLine(), KIGFX::COLOR4D::g, m_currentManager, KIGFX::GAL::m_fillColor, KIGFX::GAL::m_isFillEnabled, KIGFX::GAL::m_isStrokeEnabled, KIGFX::GAL::m_layerDepth, KIGFX::GAL::m_strokeColor, KIGFX::COLOR4D::r, KIGFX::VERTEX_MANAGER::Reserve(), Restore(), Save(), KIGFX::VERTEX_MANAGER::Shader(), KIGFX::SHADER_NONE, SWAP, KIGFX::VERTEX_MANAGER::Translate(), KIGFX::VERTEX_MANAGER::Vertex(), VECTOR2< T >::x, and VECTOR2< T >::y.

◆ DrawArcSegment()

void OPENGL_GAL::DrawArcSegment ( const VECTOR2D aCenterPoint,
double  aRadius,
const EDA_ANGLE aStartAngle,
const EDA_ANGLE aEndAngle,
double  aWidth,
double  aMaxError 
)
overridevirtual

Draw an arc segment.

This method differs from DrawArc() in what happens when fill/stroke are on or off. DrawArc() draws a "pie piece" when fill is turned on, and a thick stroke when fill is off. DrawArcSegment() with fill on behaves like DrawArc() with fill off. DrawArcSegment() with fill off draws the outline of what it would have drawn with fill on.

TODO: Unify Arc routines

Parameters
aCenterPointis the center point of the arc.
aRadiusis the arc radius.
aStartAngleis the start angle of the arc.
aEndAngleis the end angle of the arc.
aWidthis the thickness of the arc (pen size).
aMaxErroris the max allowed error to create segments to approximate a circle. It has meaning only for back ends that can't draw a true arc, and use segments to approximate.

Reimplemented from KIGFX::GAL.

Definition at line 924 of file opengl_gal.cpp.

927{
928 if( aRadius <= 0 )
929 {
930 // Arcs of zero radius are a circle of aWidth diameter
931 if( aWidth > 0 )
932 DrawCircle( aCenterPoint, aWidth / 2.0 );
933
934 return;
935 }
936
937 double startAngle = aStartAngle.AsRadians();
938 double endAngle = aEndAngle.AsRadians();
939
940 // Swap the angles, if start angle is greater than end angle
941 SWAP( startAngle, >, endAngle );
942
943 // Calculate the seg count to approximate the arc with aMaxError or less
944 int segCount360 = GetArcToSegmentCount( aRadius, aMaxError, FULL_CIRCLE );
945 segCount360 = std::max( SEG_PER_CIRCLE_COUNT, segCount360 );
946 double alphaIncrement = 2.0 * M_PI / segCount360;
947
948 // Refinement: Use a segment count multiple of 2, because we have a control point
949 // on the middle of the arc, and the look is better if it is on a segment junction
950 // because there is no approx error
951 int seg_count = KiROUND( ( endAngle - startAngle ) / alphaIncrement );
952
953 if( seg_count % 2 != 0 )
954 seg_count += 1;
955
956 // Recalculate alphaIncrement with a even integer number of segment
957 if( seg_count )
958 alphaIncrement = ( endAngle - startAngle ) / seg_count;
959
960 Save();
961 m_currentManager->Translate( aCenterPoint.x, aCenterPoint.y, 0.0 );
962
964 {
967
968 double width = aWidth / 2.0;
969 VECTOR2D startPoint( cos( startAngle ) * aRadius, sin( startAngle ) * aRadius );
970 VECTOR2D endPoint( cos( endAngle ) * aRadius, sin( endAngle ) * aRadius );
971
972 drawStrokedSemiCircle( startPoint, width, startAngle + M_PI );
973 drawStrokedSemiCircle( endPoint, width, endAngle );
974
975 VECTOR2D pOuter( cos( startAngle ) * ( aRadius + width ),
976 sin( startAngle ) * ( aRadius + width ) );
977
978 VECTOR2D pInner( cos( startAngle ) * ( aRadius - width ),
979 sin( startAngle ) * ( aRadius - width ) );
980
981 double alpha;
982
983 for( alpha = startAngle + alphaIncrement; alpha <= endAngle; alpha += alphaIncrement )
984 {
985 VECTOR2D pNextOuter( cos( alpha ) * ( aRadius + width ),
986 sin( alpha ) * ( aRadius + width ) );
987 VECTOR2D pNextInner( cos( alpha ) * ( aRadius - width ),
988 sin( alpha ) * ( aRadius - width ) );
989
990 DrawLine( pOuter, pNextOuter );
991 DrawLine( pInner, pNextInner );
992
993 pOuter = pNextOuter;
994 pInner = pNextInner;
995 }
996
997 // Draw the last missing part
998 if( alpha != endAngle )
999 {
1000 VECTOR2D pLastOuter( cos( endAngle ) * ( aRadius + width ),
1001 sin( endAngle ) * ( aRadius + width ) );
1002 VECTOR2D pLastInner( cos( endAngle ) * ( aRadius - width ),
1003 sin( endAngle ) * ( aRadius - width ) );
1004
1005 DrawLine( pOuter, pLastOuter );
1006 DrawLine( pInner, pLastInner );
1007 }
1008 }
1009
1010 if( m_isFillEnabled )
1011 {
1013 SetLineWidth( aWidth );
1014
1015 VECTOR2D p( cos( startAngle ) * aRadius, sin( startAngle ) * aRadius );
1016 double alpha;
1017
1018 int lineCount = 0;
1019
1020 for( alpha = startAngle + alphaIncrement; alpha <= endAngle; alpha += alphaIncrement )
1021 {
1022 lineCount++;
1023 }
1024
1025 // The last missing part
1026 if( alpha != endAngle )
1027 {
1028 lineCount++;
1029 }
1030
1031 reserveLineQuads( lineCount );
1032
1033 for( alpha = startAngle + alphaIncrement; alpha <= endAngle; alpha += alphaIncrement )
1034 {
1035 VECTOR2D p_next( cos( alpha ) * aRadius, sin( alpha ) * aRadius );
1036 drawLineQuad( p, p_next, false );
1037
1038 p = p_next;
1039 }
1040
1041 // Draw the last missing part
1042 if( alpha != endAngle )
1043 {
1044 VECTOR2D p_last( cos( endAngle ) * aRadius, sin( endAngle ) * aRadius );
1045 drawLineQuad( p, p_last, false );
1046 }
1047 }
1048
1049 Restore();
1050}
virtual void SetLineWidth(float aLineWidth)
Set the line width.
void DrawCircle(const VECTOR2D &aCenterPoint, double aRadius) override
Draw a circle using world coordinates.
Definition: opengl_gal.cpp:785
void drawStrokedSemiCircle(const VECTOR2D &aCenterPoint, double aRadius, double aAngle, bool aReserve=true)
Draw a stroked semicircle.
void reserveLineQuads(const int aLineCount)
Reserves specified number of line quads.
void drawLineQuad(const VECTOR2D &aStartPoint, const VECTOR2D &aEndPoint, bool aReserve=true)
Draw a quad for the line.
static constexpr EDA_ANGLE & FULL_CIRCLE
Definition: eda_angle.h:410
int GetArcToSegmentCount(int aRadius, int aErrorMax, const EDA_ANGLE &aArcAngle)
constexpr ret_type KiROUND(fp_type v)
Round a floating point number to an integer using "round halfway cases away from zero".
Definition: util.h:85

References KIGFX::COLOR4D::a, EDA_ANGLE::AsRadians(), KIGFX::COLOR4D::b, KIGFX::VERTEX_MANAGER::Color(), DrawCircle(), DrawLine(), drawLineQuad(), drawStrokedSemiCircle(), FULL_CIRCLE, KIGFX::COLOR4D::g, GetArcToSegmentCount(), KiROUND(), m_currentManager, KIGFX::GAL::m_fillColor, KIGFX::GAL::m_isFillEnabled, KIGFX::GAL::m_isStrokeEnabled, KIGFX::GAL::m_strokeColor, KIGFX::COLOR4D::r, reserveLineQuads(), Restore(), Save(), SEG_PER_CIRCLE_COUNT, KIGFX::GAL::SetLineWidth(), SWAP, KIGFX::VERTEX_MANAGER::Translate(), VECTOR2< T >::x, and VECTOR2< T >::y.

◆ DrawBitmap()

void OPENGL_GAL::DrawBitmap ( const BITMAP_BASE aBitmap,
double  alphaBlend = 1.0 
)
overridevirtual

Draw a bitmap image.

Reimplemented from KIGFX::GAL.

Definition at line 1360 of file opengl_gal.cpp.

1361{
1362 GLfloat alpha = std::clamp( alphaBlend, 0.0, 1.0 );
1363
1364 // We have to calculate the pixel size in users units to draw the image.
1365 // m_worldUnitLength is a factor used for converting IU to inches
1366 double scale = 1.0 / ( aBitmap.GetPPI() * m_worldUnitLength );
1367 double w = (double) aBitmap.GetSizePixels().x * scale;
1368 double h = (double) aBitmap.GetSizePixels().y * scale;
1369
1370 auto xform = m_currentManager->GetTransformation();
1371
1372 glm::vec4 v0 = xform * glm::vec4( -w / 2, -h / 2, 0.0, 0.0 );
1373 glm::vec4 v1 = xform * glm::vec4( w / 2, h / 2, 0.0, 0.0 );
1374 glm::vec4 trans = xform[3];
1375
1376 auto texture_id = m_bitmapCache->RequestBitmap( &aBitmap );
1377
1378 if( !glIsTexture( texture_id ) ) // ensure the bitmap texture is still valid
1379 return;
1380
1381 glPushMatrix();
1382 glTranslated( trans.x, trans.y, trans.z );
1383
1384 glEnable( GL_TEXTURE_2D );
1385 glActiveTexture( GL_TEXTURE0 );
1386 glBindTexture( GL_TEXTURE_2D, texture_id );
1387
1388 glBegin( GL_QUADS );
1389 glColor4f( 1.0, 1.0, 1.0, alpha );
1390 glTexCoord2f( 0.0, 0.0 );
1391 glVertex3f( v0.x, v0.y, m_layerDepth );
1392 glColor4f( 1.0, 1.0, 1.0, alpha );
1393 glTexCoord2f( 1.0, 0.0 );
1394 glVertex3f( v1.x, v0.y, m_layerDepth );
1395 glColor4f( 1.0, 1.0, 1.0, alpha );
1396 glTexCoord2f( 1.0, 1.0 );
1397 glVertex3f( v1.x, v1.y, m_layerDepth );
1398 glColor4f( 1.0, 1.0, 1.0, alpha );
1399 glTexCoord2f( 0.0, 1.0 );
1400 glVertex3f( v0.x, v1.y, m_layerDepth );
1401 glEnd();
1402
1403 glBindTexture( GL_TEXTURE_2D, 0 );
1404
1405#ifdef DISABLE_BITMAP_CACHE
1406 glDeleteTextures( 1, &texture_id );
1407#endif
1408
1409 glPopMatrix();
1410}
wxSize GetSizePixels() const
Definition: bitmap_base.h:123
int GetPPI() const
Definition: bitmap_base.h:134
const glm::mat4 & GetTransformation() const
const int scale
v1

References BITMAP_BASE::GetPPI(), BITMAP_BASE::GetSizePixels(), KIGFX::VERTEX_MANAGER::GetTransformation(), m_bitmapCache, m_currentManager, KIGFX::GAL::m_layerDepth, KIGFX::GAL::m_worldUnitLength, scale, and v1.

◆ drawBitmapChar()

int OPENGL_GAL::drawBitmapChar ( unsigned long  aChar,
bool  aReserve = true 
)
private

Draw a single character using bitmap font.

Its main purpose is to be used in BitmapText() function.

Parameters
aCharis the character to be drawn.
Returns
Width of the drawn glyph.
Parameters
aReserveif set to false, reserve 6 vertices for each character.

Definition at line 2262 of file opengl_gal.cpp.

2263{
2264 const float TEX_X = font_image.width;
2265 const float TEX_Y = font_image.height;
2266
2267 // handle space
2268 if( aChar == ' ' )
2269 {
2270 const FONT_GLYPH_TYPE* g = LookupGlyph( 'x' );
2271 wxCHECK( g, 0 );
2272
2273 // Match stroke font as well as possible
2274 double spaceWidth = g->advance * 0.74;
2275
2276 Translate( VECTOR2D( spaceWidth, 0 ) );
2277 return KiROUND( spaceWidth );
2278 }
2279
2280 const FONT_GLYPH_TYPE* glyph = LookupGlyph( aChar );
2281
2282 // If the glyph is not found (happens for many esoteric unicode chars)
2283 // shows a '?' instead.
2284 if( !glyph )
2285 glyph = LookupGlyph( '?' );
2286
2287 if( !glyph ) // Should not happen.
2288 return 0;
2289
2290 const float X = glyph->atlas_x + font_information.smooth_pixels;
2291 const float Y = glyph->atlas_y + font_information.smooth_pixels;
2292 const float XOFF = glyph->minx;
2293
2294 // adjust for height rounding
2295 const float round_adjust = ( glyph->maxy - glyph->miny )
2296 - float( glyph->atlas_h - font_information.smooth_pixels * 2 );
2297 const float top_adjust = font_information.max_y - glyph->maxy;
2298 const float YOFF = round_adjust + top_adjust;
2299 const float W = glyph->atlas_w - font_information.smooth_pixels * 2;
2300 const float H = glyph->atlas_h - font_information.smooth_pixels * 2;
2301 const float B = 0;
2302
2303 if( aReserve )
2305
2306 Translate( VECTOR2D( XOFF, YOFF ) );
2307
2308 /* Glyph:
2309 * v0 v1
2310 * +--+
2311 * | /|
2312 * |/ |
2313 * +--+
2314 * v2 v3
2315 */
2316 m_currentManager->Shader( SHADER_FONT, X / TEX_X, ( Y + H ) / TEX_Y );
2317 m_currentManager->Vertex( -B, -B, 0 ); // v0
2318
2319 m_currentManager->Shader( SHADER_FONT, ( X + W ) / TEX_X, ( Y + H ) / TEX_Y );
2320 m_currentManager->Vertex( W + B, -B, 0 ); // v1
2321
2322 m_currentManager->Shader( SHADER_FONT, X / TEX_X, Y / TEX_Y );
2323 m_currentManager->Vertex( -B, H + B, 0 ); // v2
2324
2325
2326 m_currentManager->Shader( SHADER_FONT, ( X + W ) / TEX_X, ( Y + H ) / TEX_Y );
2327 m_currentManager->Vertex( W + B, -B, 0 ); // v1
2328
2329 m_currentManager->Shader( SHADER_FONT, X / TEX_X, Y / TEX_Y );
2330 m_currentManager->Vertex( -B, H + B, 0 ); // v2
2331
2332 m_currentManager->Shader( SHADER_FONT, ( X + W ) / TEX_X, Y / TEX_Y );
2333 m_currentManager->Vertex( W + B, H + B, 0 ); // v3
2334
2335 Translate( VECTOR2D( -XOFF + glyph->advance, -YOFF ) );
2336
2337 return glyph->advance;
2338}
#define H(x, y, z)
Definition: md5_hash.cpp:17
@ SHADER_FONT
Definition: vertex_common.h:50
#define X()

References KIGFX::BUILTIN_FONT::FONT_GLYPH_TYPE::advance, KIGFX::BUILTIN_FONT::FONT_GLYPH_TYPE::atlas_h, KIGFX::BUILTIN_FONT::FONT_GLYPH_TYPE::atlas_w, KIGFX::BUILTIN_FONT::FONT_GLYPH_TYPE::atlas_x, KIGFX::BUILTIN_FONT::FONT_GLYPH_TYPE::atlas_y, KIGFX::BUILTIN_FONT::font_image, KIGFX::BUILTIN_FONT::font_information, H, KIGFX::BUILTIN_FONT::FONT_IMAGE_TYPE::height, KiROUND(), KIGFX::BUILTIN_FONT::LookupGlyph(), m_currentManager, KIGFX::BUILTIN_FONT::FONT_INFO_TYPE::max_y, KIGFX::BUILTIN_FONT::FONT_GLYPH_TYPE::maxy, KIGFX::BUILTIN_FONT::FONT_GLYPH_TYPE::minx, KIGFX::BUILTIN_FONT::FONT_GLYPH_TYPE::miny, KIGFX::VERTEX_MANAGER::Reserve(), KIGFX::VERTEX_MANAGER::Shader(), KIGFX::SHADER_FONT, KIGFX::BUILTIN_FONT::FONT_INFO_TYPE::smooth_pixels, Translate(), KIGFX::VERTEX_MANAGER::Vertex(), KIGFX::BUILTIN_FONT::FONT_IMAGE_TYPE::width, and X.

Referenced by BitmapText().

◆ drawBitmapOverbar()

void OPENGL_GAL::drawBitmapOverbar ( double  aLength,
double  aHeight,
bool  aReserve = true 
)
private

Draw an overbar over the currently drawn text.

Its main purpose is to be used in BitmapText() function. This method requires appropriate scaling to be applied (as is done in BitmapText() function). The current X coordinate will be the overbar ending.

Parameters
aLengthis the width of the overbar.
aHeightis the height for the overbar.
aReserveif set to false, reserve 6 vertices for each overbar.

Definition at line 2341 of file opengl_gal.cpp.

2342{
2343 // To draw an overbar, simply draw an overbar
2344 const FONT_GLYPH_TYPE* glyph = LookupGlyph( '_' );
2345 wxCHECK( glyph, /* void */ );
2346
2347 const float H = glyph->maxy - glyph->miny;
2348
2349 Save();
2350
2351 Translate( VECTOR2D( -aLength, -aHeight ) );
2352
2353 if( aReserve )
2355
2357
2359
2360 m_currentManager->Vertex( 0, 0, 0 ); // v0
2361 m_currentManager->Vertex( aLength, 0, 0 ); // v1
2362 m_currentManager->Vertex( 0, H, 0 ); // v2
2363
2364 m_currentManager->Vertex( aLength, 0, 0 ); // v1
2365 m_currentManager->Vertex( 0, H, 0 ); // v2
2366 m_currentManager->Vertex( aLength, H, 0 ); // v3
2367
2368 Restore();
2369}

References KIGFX::COLOR4D::a, KIGFX::COLOR4D::b, KIGFX::VERTEX_MANAGER::Color(), KIGFX::COLOR4D::g, H, KIGFX::BUILTIN_FONT::LookupGlyph(), m_currentManager, KIGFX::GAL::m_strokeColor, KIGFX::BUILTIN_FONT::FONT_GLYPH_TYPE::maxy, KIGFX::BUILTIN_FONT::FONT_GLYPH_TYPE::miny, KIGFX::COLOR4D::r, KIGFX::VERTEX_MANAGER::Reserve(), Restore(), Save(), KIGFX::VERTEX_MANAGER::Shader(), Translate(), and KIGFX::VERTEX_MANAGER::Vertex().

Referenced by BitmapText().

◆ DrawCircle()

void OPENGL_GAL::DrawCircle ( const VECTOR2D aCenterPoint,
double  aRadius 
)
overridevirtual

Draw a circle using world coordinates.

Parameters
aCenterPointis the center point of the circle.
aRadiusis the radius of the circle.

Reimplemented from KIGFX::GAL.

Definition at line 785 of file opengl_gal.cpp.

786{
787 drawCircle( aCenterPoint, aRadius );
788}
void drawCircle(const VECTOR2D &aCenterPoint, double aRadius, bool aReserve=true)
Internal method for circle drawing.
Definition: opengl_gal.cpp:791

References drawCircle().

Referenced by DrawArcSegment().

◆ drawCircle()

void OPENGL_GAL::drawCircle ( const VECTOR2D aCenterPoint,
double  aRadius,
bool  aReserve = true 
)
private

Internal method for circle drawing.

Parameters
aReserveif set to false, reserve 3 vertices for each circle.

Definition at line 791 of file opengl_gal.cpp.

792{
793 if( m_isFillEnabled )
794 {
795 if( aReserve )
797
799
800 /* Draw a triangle that contains the circle, then shade it leaving only the circle.
801 * Parameters given to Shader() are indices of the triangle's vertices
802 * (if you want to understand more, check the vertex shader source [shader.vert]).
803 * Shader uses this coordinates to determine if fragments are inside the circle or not.
804 * Does the calculations in the vertex shader now (pixel alignment)
805 * v2
806 * /\
807 * //\\
808 * v0 /_\/_\ v1
809 */
811 m_currentManager->Vertex( aCenterPoint.x, aCenterPoint.y, m_layerDepth );
812
814 m_currentManager->Vertex( aCenterPoint.x, aCenterPoint.y, m_layerDepth );
815
817 m_currentManager->Vertex( aCenterPoint.x, aCenterPoint.y, m_layerDepth );
818 }
820 {
821 if( aReserve )
823
826
827 /* Draw a triangle that contains the circle, then shade it leaving only the circle.
828 * Parameters given to Shader() are indices of the triangle's vertices
829 * (if you want to understand more, check the vertex shader source [shader.vert]).
830 * and the line width. Shader uses this coordinates to determine if fragments are
831 * inside the circle or not.
832 * v2
833 * /\
834 * //\\
835 * v0 /_\/_\ v1
836 */
838 m_currentManager->Vertex( aCenterPoint.x, // v0
839 aCenterPoint.y, m_layerDepth );
840
842 m_currentManager->Vertex( aCenterPoint.x, // v1
843 aCenterPoint.y, m_layerDepth );
844
846 m_currentManager->Vertex( aCenterPoint.x, aCenterPoint.y, // v2
847 m_layerDepth );
848 }
849}
float m_lineWidth
The line width.
@ SHADER_STROKED_CIRCLE
Definition: vertex_common.h:49
@ SHADER_FILLED_CIRCLE
Definition: vertex_common.h:48

References KIGFX::COLOR4D::a, KIGFX::COLOR4D::b, KIGFX::VERTEX_MANAGER::Color(), KIGFX::COLOR4D::g, m_currentManager, KIGFX::GAL::m_fillColor, KIGFX::GAL::m_isFillEnabled, KIGFX::GAL::m_isStrokeEnabled, KIGFX::GAL::m_layerDepth, KIGFX::GAL::m_lineWidth, KIGFX::GAL::m_strokeColor, KIGFX::COLOR4D::r, KIGFX::VERTEX_MANAGER::Reserve(), KIGFX::VERTEX_MANAGER::Shader(), KIGFX::SHADER_FILLED_CIRCLE, KIGFX::SHADER_STROKED_CIRCLE, KIGFX::VERTEX_MANAGER::Vertex(), VECTOR2< T >::x, and VECTOR2< T >::y.

Referenced by DrawCircle(), and drawSegment().

◆ DrawCursor()

void OPENGL_GAL::DrawCursor ( const VECTOR2D aCursorPosition)
overridevirtual

Draw the cursor.

Parameters
aCursorPositionis the cursor position in screen coordinates.

Reimplemented from KIGFX::GAL.

Definition at line 1993 of file opengl_gal.cpp.

1994{
1995 // Now we should only store the position of the mouse cursor
1996 // The real drawing routines are in blitCursor()
1997 //VECTOR2D screenCursor = m_worldScreenMatrix * aCursorPosition;
1998 //m_cursorPosition = m_screenWorldMatrix * VECTOR2D( screenCursor.x, screenCursor.y );
1999 m_cursorPosition = aCursorPosition;
2000}

References KIGFX::GAL::m_cursorPosition.

◆ DrawCurve()

void OPENGL_GAL::DrawCurve ( const VECTOR2D startPoint,
const VECTOR2D controlPointA,
const VECTOR2D controlPointB,
const VECTOR2D endPoint,
double  aFilterValue = 0.0 
)
overridevirtual

Draw a cubic bezier spline.

Parameters
startPointis the start point of the spline.
controlPointAis the first control point.
controlPointBis the second control point.
endPointis the end point of the spline.
aFilterValueis used by Bezier to segments approximation, if the Bezier curve is not supported and needs a curve to polyline conversion. aFilterValue = 0 means no filtering.

Reimplemented from KIGFX::GAL.

Definition at line 1341 of file opengl_gal.cpp.

1344{
1345 std::vector<VECTOR2D> output;
1346 std::vector<VECTOR2D> pointCtrl;
1347
1348 pointCtrl.push_back( aStartPoint );
1349 pointCtrl.push_back( aControlPointA );
1350 pointCtrl.push_back( aControlPointB );
1351 pointCtrl.push_back( aEndPoint );
1352
1353 BEZIER_POLY converter( pointCtrl );
1354 converter.GetPoly( output, aFilterValue );
1355
1356 DrawPolyline( &output[0], output.size() );
1357}
Bezier curves to polygon converter.
Definition: bezier_curves.h:36
void DrawPolyline(const std::deque< VECTOR2D > &aPointList) override
Draw a polyline.

References DrawPolyline(), and BEZIER_POLY::GetPoly().

◆ drawFilledSemiCircle()

void OPENGL_GAL::drawFilledSemiCircle ( const VECTOR2D aCenterPoint,
double  aRadius,
double  aAngle 
)
private

Draw a filled semicircle.

Parameters
aCenterPointis the center point.
aRadiusis the radius of the semicircle.
aAngleis the angle of the semicircle.

Definition at line 2075 of file opengl_gal.cpp.

2076{
2077 Save();
2078
2080 m_currentManager->Translate( aCenterPoint.x, aCenterPoint.y, 0.0f );
2081 m_currentManager->Rotate( aAngle, 0.0f, 0.0f, 1.0f );
2082
2083 /* Draw a triangle that contains the semicircle, then shade it to leave only
2084 * the semicircle. Parameters given to Shader() are indices of the triangle's vertices
2085 * (if you want to understand more, check the vertex shader source [shader.vert]).
2086 * Shader uses these coordinates to determine if fragments are inside the semicircle or not.
2087 * v2
2088 * /\
2089 * /__\
2090 * v0 //__\\ v1
2091 */
2093 m_currentManager->Vertex( -aRadius * 3.0f / sqrt( 3.0f ), 0.0f, m_layerDepth ); // v0
2094
2096 m_currentManager->Vertex( aRadius * 3.0f / sqrt( 3.0f ), 0.0f, m_layerDepth ); // v1
2097
2099 m_currentManager->Vertex( 0.0f, aRadius * 2.0f, m_layerDepth ); // v2
2100
2101 Restore();
2102}

References m_currentManager, KIGFX::GAL::m_layerDepth, KIGFX::VERTEX_MANAGER::Reserve(), Restore(), KIGFX::VERTEX_MANAGER::Rotate(), Save(), KIGFX::VERTEX_MANAGER::Shader(), KIGFX::SHADER_FILLED_CIRCLE, KIGFX::VERTEX_MANAGER::Translate(), KIGFX::VERTEX_MANAGER::Vertex(), VECTOR2< T >::x, and VECTOR2< T >::y.

Referenced by drawSemiCircle().

◆ DrawGlyph()

void OPENGL_GAL::DrawGlyph ( const KIFONT::GLYPH aGlyph,
int  aNth,
int  aTotal 
)
overridevirtual

Draw a polygon representing a font glyph.

Reimplemented from KIGFX::GAL.

Definition at line 2663 of file opengl_gal.cpp.

2664{
2665 if( aGlyph.IsStroke() )
2666 {
2667 const auto& strokeGlyph = static_cast<const KIFONT::STROKE_GLYPH&>( aGlyph );
2668
2669 DrawPolylines( strokeGlyph );
2670 }
2671 else if( aGlyph.IsOutline() )
2672 {
2673 const auto& outlineGlyph = static_cast<const KIFONT::OUTLINE_GLYPH&>( aGlyph );
2674
2677
2678 outlineGlyph.Triangulate(
2679 [&]( const VECTOR2D& aPt1, const VECTOR2D& aPt2, const VECTOR2D& aPt3 )
2680 {
2682
2683 m_currentManager->Vertex( aPt1.x, aPt1.y, m_layerDepth );
2684 m_currentManager->Vertex( aPt2.x, aPt2.y, m_layerDepth );
2685 m_currentManager->Vertex( aPt3.x, aPt3.y, m_layerDepth );
2686 } );
2687 }
2688}
virtual bool IsStroke() const
Definition: glyph.h:52
virtual bool IsOutline() const
Definition: glyph.h:51
void DrawPolylines(const std::vector< std::vector< VECTOR2D > > &aPointLists) override
Draw multiple polylines.

References KIGFX::VERTEX_MANAGER::Color(), DrawPolylines(), KIFONT::GLYPH::IsOutline(), KIFONT::GLYPH::IsStroke(), m_currentManager, KIGFX::GAL::m_fillColor, KIGFX::GAL::m_layerDepth, KIGFX::VERTEX_MANAGER::Reserve(), KIGFX::VERTEX_MANAGER::Shader(), KIGFX::SHADER_NONE, KIGFX::VERTEX_MANAGER::Vertex(), VECTOR2< T >::x, and VECTOR2< T >::y.

Referenced by DrawGlyphs().

◆ DrawGlyphs()

void OPENGL_GAL::DrawGlyphs ( const std::vector< std::unique_ptr< KIFONT::GLYPH > > &  aGlyphs)
overridevirtual

Draw polygons representing font glyphs.

Reimplemented from KIGFX::GAL.

Definition at line 2691 of file opengl_gal.cpp.

2692{
2693 if( aGlyphs.empty() )
2694 return;
2695
2696 bool allGlyphsAreStroke = true;
2697 bool allGlyphsAreOutline = true;
2698
2699 for( const std::unique_ptr<KIFONT::GLYPH>& glyph : aGlyphs )
2700 {
2701 if( !glyph->IsStroke() )
2702 {
2703 allGlyphsAreStroke = false;
2704 break;
2705 }
2706 }
2707
2708 for( const std::unique_ptr<KIFONT::GLYPH>& glyph : aGlyphs )
2709 {
2710 if( !glyph->IsOutline() )
2711 {
2712 allGlyphsAreOutline = false;
2713 break;
2714 }
2715 }
2716
2717 if( allGlyphsAreStroke )
2718 {
2719 // Optimized path for stroke fonts that pre-reserves line quads.
2720 int lineQuadCount = 0;
2721
2722 for( const std::unique_ptr<KIFONT::GLYPH>& glyph : aGlyphs )
2723 {
2724 const auto& strokeGlyph = static_cast<const KIFONT::STROKE_GLYPH&>( *glyph );
2725
2726 for( const std::vector<VECTOR2D>& points : strokeGlyph )
2727 lineQuadCount += points.size() - 1;
2728 }
2729
2730 reserveLineQuads( lineQuadCount );
2731
2732 for( const std::unique_ptr<KIFONT::GLYPH>& glyph : aGlyphs )
2733 {
2734 const auto& strokeGlyph = static_cast<const KIFONT::STROKE_GLYPH&>( *glyph );
2735
2736 for( const std::vector<VECTOR2D>& points : strokeGlyph )
2737 {
2739 [&]( int idx )
2740 {
2741 return points[idx];
2742 },
2743 points.size(), false );
2744 }
2745 }
2746
2747 return;
2748 }
2749 else if( allGlyphsAreOutline )
2750 {
2751 // Optimized path for stroke fonts that pre-reserves glyph triangles.
2752 int triangleCount = 0;
2753
2754 for( const std::unique_ptr<KIFONT::GLYPH>& glyph : aGlyphs )
2755 {
2756 const auto& outlineGlyph = static_cast<const KIFONT::OUTLINE_GLYPH&>( *glyph );
2757
2758 // Only call CacheTriangulation if it has never been done before. Otherwise we'll hash
2759 // the triangulation to see if it has been edited, and glyphs after creation are read-only.
2760 if( outlineGlyph.TriangulatedPolyCount() == 0 )
2761 const_cast<KIFONT::OUTLINE_GLYPH&>( outlineGlyph ).CacheTriangulation( false );
2762
2763 for( unsigned int i = 0; i < outlineGlyph.TriangulatedPolyCount(); i++ )
2764 {
2766 outlineGlyph.TriangulatedPolygon( i );
2767
2768 triangleCount += polygon->GetTriangleCount();
2769 }
2770 }
2771
2774
2775 m_currentManager->Reserve( 3 * triangleCount );
2776
2777 for( const std::unique_ptr<KIFONT::GLYPH>& glyph : aGlyphs )
2778 {
2779 const auto& outlineGlyph = static_cast<const KIFONT::OUTLINE_GLYPH&>( *glyph );
2780
2781 for( unsigned int i = 0; i < outlineGlyph.TriangulatedPolyCount(); i++ )
2782 {
2784 outlineGlyph.TriangulatedPolygon( i );
2785
2786 for( size_t j = 0; j < polygon->GetTriangleCount(); j++ )
2787 {
2788 VECTOR2I a, b, c;
2789 polygon->GetTriangle( j, a, b, c );
2790
2794 }
2795 }
2796 }
2797 }
2798 else
2799 {
2800 // Regular path
2801 for( size_t i = 0; i < aGlyphs.size(); i++ )
2802 DrawGlyph( *aGlyphs[i], i, aGlyphs.size() );
2803 }
2804}
virtual void DrawGlyph(const KIFONT::GLYPH &aGlyph, int aNth, int aTotal) override
Draw a polygon representing a font glyph.
void drawPolyline(const std::function< VECTOR2D(int)> &aPointGetter, int aPointCount, bool aReserve=true)
Generic way of drawing a polyline stored in different containers.
void GetTriangle(int index, VECTOR2I &a, VECTOR2I &b, VECTOR2I &c) const

References KIGFX::VERTEX_MANAGER::Color(), DrawGlyph(), drawPolyline(), SHAPE_POLY_SET::TRIANGULATED_POLYGON::GetTriangle(), SHAPE_POLY_SET::TRIANGULATED_POLYGON::GetTriangleCount(), m_currentManager, KIGFX::GAL::m_fillColor, KIGFX::GAL::m_layerDepth, KIGFX::VERTEX_MANAGER::Reserve(), reserveLineQuads(), KIGFX::VERTEX_MANAGER::Shader(), KIGFX::SHADER_NONE, KIGFX::VERTEX_MANAGER::Vertex(), VECTOR2< T >::x, and VECTOR2< T >::y.

◆ DrawGrid()

void OPENGL_GAL::DrawGrid ( )
overridevirtual

Reimplemented from KIGFX::GAL.

Definition at line 1574 of file opengl_gal.cpp.

1575{
1578
1580
1581 // sub-pixel lines all render the same
1582 float minorLineWidth = std::fmax( 1.0f,
1584 float majorLineWidth = minorLineWidth * 2.0f;
1585
1586 // Draw the axis and grid
1587 // For the drawing the start points, end points and increments have
1588 // to be calculated in world coordinates
1589 VECTOR2D worldStartPoint = m_screenWorldMatrix * VECTOR2D( 0.0, 0.0 );
1591
1592 // Draw axes if desired
1593 if( m_axesEnabled )
1594 {
1595 SetLineWidth( minorLineWidth );
1597
1598 DrawLine( VECTOR2D( worldStartPoint.x, 0 ), VECTOR2D( worldEndPoint.x, 0 ) );
1599 DrawLine( VECTOR2D( 0, worldStartPoint.y ), VECTOR2D( 0, worldEndPoint.y ) );
1600 }
1601
1602 // force flush
1604
1605 if( !m_gridVisibility || m_gridSize.x == 0 || m_gridSize.y == 0 )
1606 return;
1607
1608 VECTOR2D gridScreenSize( m_gridSize );
1609
1610 double gridThreshold = computeMinGridSpacing() / m_worldScale;
1611
1613 gridThreshold *= 2.0;
1614
1615 // If we cannot display the grid density, scale down by a tick size and
1616 // try again. Eventually, we get some representation of the grid
1617 while( std::min( gridScreenSize.x, gridScreenSize.y ) <= gridThreshold )
1618 {
1619 gridScreenSize = gridScreenSize * static_cast<double>( m_gridTick );
1620 }
1621
1622 // Compute grid starting and ending indexes to draw grid points on the
1623 // visible screen area
1624 // Note: later any point coordinate will be offsetted by m_gridOrigin
1625 int gridStartX = KiROUND( ( worldStartPoint.x - m_gridOrigin.x ) / gridScreenSize.x );
1626 int gridEndX = KiROUND( ( worldEndPoint.x - m_gridOrigin.x ) / gridScreenSize.x );
1627 int gridStartY = KiROUND( ( worldStartPoint.y - m_gridOrigin.y ) / gridScreenSize.y );
1628 int gridEndY = KiROUND( ( worldEndPoint.y - m_gridOrigin.y ) / gridScreenSize.y );
1629
1630 // Ensure start coordinate > end coordinate
1631 SWAP( gridStartX, >, gridEndX );
1632 SWAP( gridStartY, >, gridEndY );
1633
1634 // Ensure the grid fills the screen
1635 --gridStartX;
1636 ++gridEndX;
1637 --gridStartY;
1638 ++gridEndY;
1639
1640 glDisable( GL_DEPTH_TEST );
1641 glDisable( GL_TEXTURE_2D );
1642
1644 {
1645 glEnable( GL_STENCIL_TEST );
1646 glStencilFunc( GL_ALWAYS, 1, 1 );
1647 glStencilOp( GL_KEEP, GL_KEEP, GL_INCR );
1648 glColor4d( 0.0, 0.0, 0.0, 0.0 );
1649 SetStrokeColor( COLOR4D( 0.0, 0.0, 0.0, 0.0 ) );
1650 }
1651 else
1652 {
1655 }
1656
1658 {
1659 // Vertical positions
1660 for( int j = gridStartY; j <= gridEndY; j++ )
1661 {
1662 bool tickY = ( j % m_gridTick == 0 );
1663 const double posY = j * gridScreenSize.y + m_gridOrigin.y;
1664
1665 // Horizontal positions
1666 for( int i = gridStartX; i <= gridEndX; i++ )
1667 {
1668 bool tickX = ( i % m_gridTick == 0 );
1669 SetLineWidth( ( ( tickX && tickY ) ? majorLineWidth : minorLineWidth ) );
1670 auto lineLen = 2.0 * GetLineWidth();
1671 auto posX = i * gridScreenSize.x + m_gridOrigin.x;
1672
1673 DrawLine( VECTOR2D( posX - lineLen, posY ), VECTOR2D( posX + lineLen, posY ) );
1674 DrawLine( VECTOR2D( posX, posY - lineLen ), VECTOR2D( posX, posY + lineLen ) );
1675 }
1676 }
1677
1679 }
1680 else
1681 {
1682 // Vertical lines
1683 for( int j = gridStartY; j <= gridEndY; j++ )
1684 {
1685 const double y = j * gridScreenSize.y + m_gridOrigin.y;
1686
1687 // If axes are drawn, skip the lines that would cover them
1688 if( m_axesEnabled && y == 0.0 )
1689 continue;
1690
1691 SetLineWidth( ( j % m_gridTick == 0 ) ? majorLineWidth : minorLineWidth );
1692 VECTOR2D a( gridStartX * gridScreenSize.x + m_gridOrigin.x, y );
1693 VECTOR2D b( gridEndX * gridScreenSize.x + m_gridOrigin.x, y );
1694
1695 DrawLine( a, b );
1696 }
1697
1699
1701 {
1702 glStencilFunc( GL_NOTEQUAL, 0, 1 );
1705 }
1706
1707 // Horizontal lines
1708 for( int i = gridStartX; i <= gridEndX; i++ )
1709 {
1710 const double x = i * gridScreenSize.x + m_gridOrigin.x;
1711
1712 // If axes are drawn, skip the lines that would cover them
1713 if( m_axesEnabled && x == 0.0 )
1714 continue;
1715
1716 SetLineWidth( ( i % m_gridTick == 0 ) ? majorLineWidth : minorLineWidth );
1717 VECTOR2D a( x, gridStartY * gridScreenSize.y + m_gridOrigin.y );
1718 VECTOR2D b( x, gridEndY * gridScreenSize.y + m_gridOrigin.y );
1719 DrawLine( a, b );
1720 }
1721
1723
1725 glDisable( GL_STENCIL_TEST );
1726 }
1727
1728 glEnable( GL_DEPTH_TEST );
1729 glEnable( GL_TEXTURE_2D );
1730}
MATRIX3x3D m_screenWorldMatrix
Screen transformation.
bool m_axesEnabled
Should the axes be drawn.
float m_gridLineWidth
Line width of the grid.
GRID_STYLE m_gridStyle
Grid display style.
COLOR4D m_axesColor
Color of the axes.
VECTOR2D m_gridSize
The grid size.
int m_gridTick
Every tick line gets the double width.
VECTOR2D m_gridOrigin
The grid origin.
COLOR4D m_gridColor
Color of the grid.
double computeMinGridSpacing() const
compute minimum grid spacing from the grid settings
bool m_gridVisibility
Should the grid be shown.
float GetLineWidth() const
Get the line width.
void EndDrawing() const
Finish drawing operations.
void EnableDepthTest(bool aEnabled)
Enable/disable Z buffer depth test.
@ SMALL_CROSS
Use small cross instead of dots for the grid.
@ DOTS
Use dots for the grid.

References KIGFX::COLOR4D::a, KIGFX::COLOR4D::b, KIGFX::GAL::computeMinGridSpacing(), KIGFX::DOTS, DrawLine(), KIGFX::VERTEX_MANAGER::EnableDepthTest(), KIGFX::VERTEX_MANAGER::EndDrawing(), KIGFX::COLOR4D::g, KIGFX::GAL::GetLineWidth(), HIDPI_GL_CANVAS::GetScaleFactor(), getWorldPixelSize(), KiROUND(), KIGFX::GAL::m_axesColor, KIGFX::GAL::m_axesEnabled, m_compositor, KIGFX::GAL::m_gridColor, KIGFX::GAL::m_gridLineWidth, KIGFX::GAL::m_gridOrigin, KIGFX::GAL::m_gridSize, KIGFX::GAL::m_gridStyle, KIGFX::GAL::m_gridTick, KIGFX::GAL::m_gridVisibility, m_mainBuffer, m_nonCachedManager, KIGFX::GAL::m_screenSize, KIGFX::GAL::m_screenWorldMatrix, KIGFX::GAL::m_worldScale, KIGFX::COLOR4D::r, KIGFX::OPENGL_COMPOSITOR::SetBuffer(), KIGFX::GAL::SetLineWidth(), KIGFX::GAL::SetStrokeColor(), SetTarget(), KIGFX::SMALL_CROSS, SWAP, KIGFX::TARGET_NONCACHED, VECTOR2< T >::x, and VECTOR2< T >::y.

◆ DrawGroup()

void OPENGL_GAL::DrawGroup ( int  aGroupNumber)
overridevirtual

Draw the stored group.

Parameters
aGroupNumberis the group number.

Reimplemented from KIGFX::GAL.

Definition at line 1841 of file opengl_gal.cpp.

1842{
1843 auto group = m_groups.find( aGroupNumber );
1844
1845 if( group != m_groups.end() )
1846 m_cachedManager->DrawItem( *group->second );
1847}
void DrawItem(const VERTEX_ITEM &aItem) const
Draw an item to the buffer.

References KIGFX::VERTEX_MANAGER::DrawItem(), group, m_cachedManager, and m_groups.

◆ DrawLine()

void OPENGL_GAL::DrawLine ( const VECTOR2D aStartPoint,
const VECTOR2D aEndPoint 
)
overridevirtual

Draw a line.

Start and end points are defined as 2D-Vectors.

Parameters
aStartPointis the start point of the line.
aEndPointis the end point of the line.

Reimplemented from KIGFX::GAL.

Definition at line 712 of file opengl_gal.cpp.

713{
715
716 drawLineQuad( aStartPoint, aEndPoint );
717}

References KIGFX::COLOR4D::a, KIGFX::COLOR4D::b, KIGFX::VERTEX_MANAGER::Color(), drawLineQuad(), KIGFX::COLOR4D::g, m_currentManager, KIGFX::GAL::m_strokeColor, and KIGFX::COLOR4D::r.

Referenced by DrawArc(), DrawArcSegment(), DrawGrid(), and drawTriangulatedPolyset().

◆ drawLineQuad()

void OPENGL_GAL::drawLineQuad ( const VECTOR2D aStartPoint,
const VECTOR2D aEndPoint,
bool  aReserve = true 
)
private

Draw a quad for the line.

Parameters
aStartPointis the start point of the line.
aEndPointis the end point of the line.
aReserveif set to false, call reserveLineQuads beforehand to reserve the right amount of vertices.

Definition at line 2003 of file opengl_gal.cpp.

2005{
2006 /* Helper drawing: ____--- v3 ^
2007 * ____---- ... \ \
2008 * ____---- ... \ end \
2009 * v1 ____---- ... ____---- \ width
2010 * ---- ...___---- \ \
2011 * \ ___...-- \ v
2012 * \ ____----... ____---- v2
2013 * ---- ... ____----
2014 * start \ ... ____----
2015 * \... ____----
2016 * ----
2017 * v0
2018 * dots mark triangles' hypotenuses
2019 */
2020
2022 * glm::vec4( aStartPoint.x, aStartPoint.y, 0.0, 0.0 );
2024 * glm::vec4( aEndPoint.x, aEndPoint.y, 0.0, 0.0 );
2025
2026 VECTOR2D vs( v2.x - v1.x, v2.y - v1.y );
2027
2028 if( aReserve )
2029 reserveLineQuads( 1 );
2030
2031 // Line width is maintained by the vertex shader
2033 m_currentManager->Vertex( aStartPoint, m_layerDepth );
2034
2036 m_currentManager->Vertex( aStartPoint, m_layerDepth );
2037
2039 m_currentManager->Vertex( aEndPoint, m_layerDepth );
2040
2042 m_currentManager->Vertex( aEndPoint, m_layerDepth );
2043
2045 m_currentManager->Vertex( aEndPoint, m_layerDepth );
2046
2048 m_currentManager->Vertex( aStartPoint, m_layerDepth );
2049}
@ SHADER_LINE_C
Definition: vertex_common.h:53
@ SHADER_LINE_B
Definition: vertex_common.h:52
@ SHADER_LINE_F
Definition: vertex_common.h:56
@ SHADER_LINE_E
Definition: vertex_common.h:55
@ SHADER_LINE_A
Definition: vertex_common.h:51
@ SHADER_LINE_D
Definition: vertex_common.h:54
VECTOR2I v2(1, 0)
Test suite for KiCad math code.

References KIGFX::VERTEX_MANAGER::GetTransformation(), m_currentManager, KIGFX::GAL::m_layerDepth, KIGFX::GAL::m_lineWidth, reserveLineQuads(), KIGFX::VERTEX_MANAGER::Shader(), KIGFX::SHADER_LINE_A, KIGFX::SHADER_LINE_B, KIGFX::SHADER_LINE_C, KIGFX::SHADER_LINE_D, KIGFX::SHADER_LINE_E, KIGFX::SHADER_LINE_F, v1, v2, KIGFX::VERTEX_MANAGER::Vertex(), VECTOR2< T >::x, and VECTOR2< T >::y.

Referenced by DrawArcSegment(), DrawLine(), drawPolyline(), and drawSegment().

◆ DrawPolygon() [1/4]

void OPENGL_GAL::DrawPolygon ( const SHAPE_LINE_CHAIN aPolySet)
overridevirtual

Reimplemented from KIGFX::GAL.

Definition at line 1321 of file opengl_gal.cpp.

1322{
1323 wxCHECK( aPolygon.PointCount() >= 2, /* void */ );
1324
1325 const int pointCount = aPolygon.SegmentCount() + 1;
1326 std::unique_ptr<GLdouble[]> points( new GLdouble[3 * pointCount] );
1327 GLdouble* ptr = points.get();
1328
1329 for( int i = 0; i < pointCount; ++i )
1330 {
1331 const VECTOR2I& p = aPolygon.CPoint( i );
1332 *ptr++ = p.x;
1333 *ptr++ = p.y;
1334 *ptr++ = m_layerDepth;
1335 }
1336
1337 drawPolygon( points.get(), pointCount );
1338}
void drawPolygon(GLdouble *aPoints, int aPointCount)
Draw a filled polygon.

References SHAPE_LINE_CHAIN::CPoint(), drawPolygon(), KIGFX::GAL::m_layerDepth, SHAPE_LINE_CHAIN::PointCount(), SHAPE_LINE_CHAIN::SegmentCount(), VECTOR2< T >::x, and VECTOR2< T >::y.

◆ DrawPolygon() [2/4]

void OPENGL_GAL::DrawPolygon ( const SHAPE_POLY_SET aPolySet,
bool  aStrokeTriangulation = false 
)
overridevirtual

Reimplemented from KIGFX::GAL.

Definition at line 1305 of file opengl_gal.cpp.

1306{
1307 if( aPolySet.IsTriangulationUpToDate() )
1308 {
1309 drawTriangulatedPolyset( aPolySet, aStrokeTriangulation );
1310 return;
1311 }
1312
1313 for( int j = 0; j < aPolySet.OutlineCount(); ++j )
1314 {
1315 const SHAPE_LINE_CHAIN& outline = aPolySet.COutline( j );
1316 DrawPolygon( outline );
1317 }
1318}
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.
Represent a polyline containing arcs as well as line segments: A chain of connected line and/or arc s...
bool IsTriangulationUpToDate() const
int OutlineCount() const
Return the number of vertices in a given outline/hole.
const SHAPE_LINE_CHAIN & COutline(int aIndex) const

References SHAPE_POLY_SET::COutline(), DrawPolygon(), drawTriangulatedPolyset(), SHAPE_POLY_SET::IsTriangulationUpToDate(), and SHAPE_POLY_SET::OutlineCount().

◆ DrawPolygon() [3/4]

void OPENGL_GAL::DrawPolygon ( const std::deque< VECTOR2D > &  aPointList)
overridevirtual

Draw a polygon.

Parameters
aPointListis the list of the polygon points.

Reimplemented from KIGFX::GAL.

Definition at line 1189 of file opengl_gal.cpp.

1190{
1191 wxCHECK( aPointList.size() >= 2, /* void */ );
1192 auto points = std::unique_ptr<GLdouble[]>( new GLdouble[3 * aPointList.size()] );
1193 GLdouble* ptr = points.get();
1194
1195 for( const VECTOR2D& p : aPointList )
1196 {
1197 *ptr++ = p.x;
1198 *ptr++ = p.y;
1199 *ptr++ = m_layerDepth;
1200 }
1201
1202 drawPolygon( points.get(), aPointList.size() );
1203}

References drawPolygon(), and KIGFX::GAL::m_layerDepth.

Referenced by DrawPolygon().

◆ DrawPolygon() [4/4]

void OPENGL_GAL::DrawPolygon ( const VECTOR2D  aPointList[],
int  aListSize 
)
overridevirtual

Reimplemented from KIGFX::GAL.

Definition at line 1206 of file opengl_gal.cpp.

1207{
1208 wxCHECK( aListSize >= 2, /* void */ );
1209 auto points = std::unique_ptr<GLdouble[]>( new GLdouble[3 * aListSize] );
1210 GLdouble* target = points.get();
1211 const VECTOR2D* src = aPointList;
1212
1213 for( int i = 0; i < aListSize; ++i )
1214 {
1215 *target++ = src->x;
1216 *target++ = src->y;
1217 *target++ = m_layerDepth;
1218 ++src;
1219 }
1220
1221 drawPolygon( points.get(), aListSize );
1222}

References drawPolygon(), KIGFX::GAL::m_layerDepth, VECTOR2< T >::x, and VECTOR2< T >::y.

◆ drawPolygon()

void OPENGL_GAL::drawPolygon ( GLdouble *  aPoints,
int  aPointCount 
)
private

Draw a filled polygon.

It does not need the last point to have the same coordinates as the first one.

Parameters
aPointsis the vertices data (3 coordinates: x, y, z).
aPointCountis the number of points.

Definition at line 2141 of file opengl_gal.cpp.

2142{
2143 if( m_isFillEnabled )
2144 {
2147
2148 // Any non convex polygon needs to be tesselated
2149 // for this purpose the GLU standard functions are used
2150 TessParams params = { m_currentManager, m_tessIntersects };
2151 gluTessBeginPolygon( m_tesselator, &params );
2152 gluTessBeginContour( m_tesselator );
2153
2154 GLdouble* point = aPoints;
2155
2156 for( int i = 0; i < aPointCount; ++i )
2157 {
2158 gluTessVertex( m_tesselator, point, point );
2159 point += 3; // 3 coordinates
2160 }
2161
2162 gluTessEndContour( m_tesselator );
2163 gluTessEndPolygon( m_tesselator );
2164
2165 // Free allocated intersecting points
2166 m_tessIntersects.clear();
2167 }
2168
2169 if( m_isStrokeEnabled )
2170 {
2172 [&]( int idx )
2173 {
2174 return VECTOR2D( aPoints[idx * 3], aPoints[idx * 3 + 1] );
2175 },
2176 aPointCount );
2177 }
2178}
std::deque< std::shared_ptr< GLdouble > > m_tessIntersects
Definition: opengl_gal.h:379

References KIGFX::COLOR4D::a, KIGFX::COLOR4D::b, KIGFX::VERTEX_MANAGER::Color(), drawPolyline(), KIGFX::COLOR4D::g, m_currentManager, KIGFX::GAL::m_fillColor, KIGFX::GAL::m_isFillEnabled, KIGFX::GAL::m_isStrokeEnabled, m_tesselator, m_tessIntersects, KIGFX::COLOR4D::r, KIGFX::VERTEX_MANAGER::Shader(), and KIGFX::SHADER_NONE.

Referenced by DrawPolygon().

◆ DrawPolyline() [1/4]

void OPENGL_GAL::DrawPolyline ( const SHAPE_LINE_CHAIN aLineChain)
overridevirtual

Reimplemented from KIGFX::GAL.

Definition at line 1152 of file opengl_gal.cpp.

1153{
1154 auto numPoints = aLineChain.PointCount();
1155
1156 if( aLineChain.IsClosed() )
1157 numPoints += 1;
1158
1160 [&]( int idx )
1161 {
1162 return aLineChain.CPoint( idx );
1163 },
1164 numPoints );
1165}
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.

References SHAPE_LINE_CHAIN::CPoint(), drawPolyline(), SHAPE_LINE_CHAIN::IsClosed(), and SHAPE_LINE_CHAIN::PointCount().

◆ DrawPolyline() [2/4]

void OPENGL_GAL::DrawPolyline ( const std::deque< VECTOR2D > &  aPointList)
overridevirtual

Draw a polyline.

Parameters
aPointListis a list of 2D-Vectors containing the polyline points.

Reimplemented from KIGFX::GAL.

Definition at line 1119 of file opengl_gal.cpp.

1120{
1122 [&]( int idx )
1123 {
1124 return aPointList[idx];
1125 },
1126 aPointList.size() );
1127}

References drawPolyline().

Referenced by DrawCurve(), DrawRectangle(), and drawTriangulatedPolyset().

◆ drawPolyline()

void OPENGL_GAL::drawPolyline ( const std::function< VECTOR2D(int)> &  aPointGetter,
int  aPointCount,
bool  aReserve = true 
)
private

Generic way of drawing a polyline stored in different containers.

Parameters
aPointGetteris a function to obtain coordinates of n-th vertex.
aPointCountis the number of points to be drawn.
aReserveif set to false, reserve aPointCount - 1 line quads.

Definition at line 2181 of file opengl_gal.cpp.

2183{
2184 wxCHECK( aPointCount > 0, /* return */ );
2185
2187
2188 if( aPointCount == 1 )
2189 {
2190 drawLineQuad( aPointGetter( 0 ), aPointGetter( 0 ), aReserve );
2191 return;
2192 }
2193
2194 if( aReserve )
2195 {
2196 reserveLineQuads( aPointCount - 1 );
2197 }
2198
2199 for( int i = 1; i < aPointCount; ++i )
2200 {
2201 auto start = aPointGetter( i - 1 );
2202 auto end = aPointGetter( i );
2203
2204 drawLineQuad( start, end, false );
2205 }
2206}

References KIGFX::COLOR4D::a, KIGFX::COLOR4D::b, KIGFX::VERTEX_MANAGER::Color(), drawLineQuad(), KIGFX::COLOR4D::g, m_currentManager, KIGFX::GAL::m_strokeColor, KIGFX::COLOR4D::r, and reserveLineQuads().

Referenced by DrawGlyphs(), drawPolygon(), DrawPolyline(), and DrawPolylines().

◆ DrawPolyline() [3/4]

void OPENGL_GAL::DrawPolyline ( const std::vector< VECTOR2D > &  aPointList)
overridevirtual

Reimplemented from KIGFX::GAL.

Definition at line 1130 of file opengl_gal.cpp.

1131{
1133 [&]( int idx )
1134 {
1135 return aPointList[idx];
1136 },
1137 aPointList.size() );
1138}

References drawPolyline().

◆ DrawPolyline() [4/4]

void OPENGL_GAL::DrawPolyline ( const VECTOR2D  aPointList[],
int  aListSize 
)
overridevirtual

Reimplemented from KIGFX::GAL.

Definition at line 1141 of file opengl_gal.cpp.

1142{
1144 [&]( int idx )
1145 {
1146 return aPointList[idx];
1147 },
1148 aListSize );
1149}

References drawPolyline().

◆ DrawPolylines()

void OPENGL_GAL::DrawPolylines ( const std::vector< std::vector< VECTOR2D > > &  aPointLists)
overridevirtual

Draw multiple polylines.

Parameters
aPointListsare lists of 2D-Vectors containing the polyline points.

Reimplemented from KIGFX::GAL.

Definition at line 1168 of file opengl_gal.cpp.

1169{
1170 int lineQuadCount = 0;
1171
1172 for( const std::vector<VECTOR2D>& points : aPointList )
1173 lineQuadCount += points.size() - 1;
1174
1175 reserveLineQuads( lineQuadCount );
1176
1177 for( const std::vector<VECTOR2D>& points : aPointList )
1178 {
1180 [&]( int idx )
1181 {
1182 return points[idx];
1183 },
1184 points.size(), false );
1185 }
1186}

References drawPolyline(), and reserveLineQuads().

Referenced by DrawGlyph().

◆ DrawRectangle() [1/2]

void KIGFX::GAL::DrawRectangle ( const BOX2I aRect)
inlineinherited

Definition at line 186 of file graphics_abstraction_layer.h.

187 {
188 DrawRectangle( aRect.GetOrigin(), aRect.GetEnd() );
189 }
const Vec & GetOrigin() const
Definition: box2.h:183
const Vec GetEnd() const
Definition: box2.h:185
virtual void DrawRectangle(const VECTOR2D &aStartPoint, const VECTOR2D &aEndPoint)
Draw a rectangle.

References KIGFX::GAL::DrawRectangle(), BOX2< Vec >::GetEnd(), and BOX2< Vec >::GetOrigin().

◆ DrawRectangle() [2/2]

void OPENGL_GAL::DrawRectangle ( const VECTOR2D aStartPoint,
const VECTOR2D aEndPoint 
)
overridevirtual

Draw a rectangle.

Parameters
aStartPointis the start point of the rectangle.
aEndPointis the end point of the rectangle.

Reimplemented from KIGFX::GAL.

Definition at line 1053 of file opengl_gal.cpp.

1054{
1055 // Compute the diagonal points of the rectangle
1056 VECTOR2D diagonalPointA( aEndPoint.x, aStartPoint.y );
1057 VECTOR2D diagonalPointB( aStartPoint.x, aEndPoint.y );
1058
1059 // Fill the rectangle
1060 if( m_isFillEnabled )
1061 {
1065
1066 m_currentManager->Vertex( aStartPoint.x, aStartPoint.y, m_layerDepth );
1067 m_currentManager->Vertex( diagonalPointA.x, diagonalPointA.y, m_layerDepth );
1068 m_currentManager->Vertex( aEndPoint.x, aEndPoint.y, m_layerDepth );
1069
1070 m_currentManager->Vertex( aStartPoint.x, aStartPoint.y, m_layerDepth );
1071 m_currentManager->Vertex( aEndPoint.x, aEndPoint.y, m_layerDepth );
1072 m_currentManager->Vertex( diagonalPointB.x, diagonalPointB.y, m_layerDepth );
1073 }
1074
1075 // Stroke the outline
1076 if( m_isStrokeEnabled )
1077 {
1079 m_strokeColor.a );
1080
1081 std::deque<VECTOR2D> pointList;
1082 pointList.push_back( aStartPoint );
1083 pointList.push_back( diagonalPointA );
1084 pointList.push_back( aEndPoint );
1085 pointList.push_back( diagonalPointB );
1086 pointList.push_back( aStartPoint );
1087 DrawPolyline( pointList );
1088 }
1089}

References KIGFX::COLOR4D::a, KIGFX::COLOR4D::b, KIGFX::VERTEX_MANAGER::Color(), DrawPolyline(), KIGFX::COLOR4D::g, m_currentManager, KIGFX::GAL::m_fillColor, KIGFX::GAL::m_isFillEnabled, KIGFX::GAL::m_isStrokeEnabled, KIGFX::GAL::m_layerDepth, KIGFX::GAL::m_strokeColor, KIGFX::COLOR4D::r, KIGFX::VERTEX_MANAGER::Reserve(), KIGFX::VERTEX_MANAGER::Shader(), KIGFX::SHADER_NONE, KIGFX::VERTEX_MANAGER::Vertex(), VECTOR2< T >::x, and VECTOR2< T >::y.

◆ DrawSegment()

void OPENGL_GAL::DrawSegment ( const VECTOR2D aStartPoint,
const VECTOR2D aEndPoint,
double  aWidth 
)
overridevirtual

Draw a rounded segment.

Start and end points are defined as 2D-Vectors.

Parameters
aStartPointis the start point of the segment.
aEndPointis the end point of the segment.
aWidthis a width of the segment

Reimplemented from KIGFX::GAL.

Definition at line 720 of file opengl_gal.cpp.

722{
723 drawSegment( aStartPoint, aEndPoint, aWidth );
724}
void drawSegment(const VECTOR2D &aStartPoint, const VECTOR2D &aEndPoint, double aWidth, bool aReserve=true)
Internal method for segment drawing.
Definition: opengl_gal.cpp:727

References drawSegment().

◆ drawSegment()

void OPENGL_GAL::drawSegment ( const VECTOR2D aStartPoint,
const VECTOR2D aEndPoint,
double  aWidth,
bool  aReserve = true 
)
private

Internal method for segment drawing.

Definition at line 727 of file opengl_gal.cpp.

729{
730 VECTOR2D startEndVector = aEndPoint - aStartPoint;
731 double lineLength = startEndVector.EuclideanNorm();
732
733 float startx = aStartPoint.x;
734 float starty = aStartPoint.y;
735 float endx = aStartPoint.x + lineLength;
736 float endy = aStartPoint.y + lineLength;
737
738 // Be careful about floating point rounding. As we draw segments in larger and larger
739 // coordinates, the shader (which uses floats) will lose precision and stop drawing small
740 // segments. In this case, we need to draw a circle for the minimal segment.
741 if( startx == endx || starty == endy )
742 {
743 drawCircle( aStartPoint, aWidth / 2, aReserve );
744 return;
745 }
746
747 if( m_isFillEnabled || aWidth == 1.0 )
748 {
750
751 SetLineWidth( aWidth );
752 drawLineQuad( aStartPoint, aEndPoint, aReserve );
753 }
754 else
755 {
756 EDA_ANGLE lineAngle( startEndVector );
757 // Outlined tracks
758
759 SetLineWidth( 1.0 );
762
763 Save();
764
765 if( aReserve )
766 m_currentManager->Reserve( 6 + 6 + 3 + 3 ); // Two line quads and two semicircles
767
768 m_currentManager->Translate( aStartPoint.x, aStartPoint.y, 0.0 );
769 m_currentManager->Rotate( lineAngle.AsRadians(), 0.0f, 0.0f, 1.0f );
770
771 drawLineQuad( VECTOR2D( 0.0, aWidth / 2.0 ), VECTOR2D( lineLength, aWidth / 2.0 ), false );
772
773 drawLineQuad( VECTOR2D( 0.0, -aWidth / 2.0 ), VECTOR2D( lineLength, -aWidth / 2.0 ),
774 false );
775
776 // Draw line caps
777 drawStrokedSemiCircle( VECTOR2D( 0.0, 0.0 ), aWidth / 2, M_PI / 2, false );
778 drawStrokedSemiCircle( VECTOR2D( lineLength, 0.0 ), aWidth / 2, -M_PI / 2, false );
779
780 Restore();
781 }
782}
T EuclideanNorm() const
Compute the Euclidean norm of the vector, which is defined as sqrt(x ** 2 + y ** 2).
Definition: vector2d.h:293

References KIGFX::COLOR4D::a, EDA_ANGLE::AsRadians(), KIGFX::COLOR4D::b, KIGFX::VERTEX_MANAGER::Color(), drawCircle(), drawLineQuad(), drawStrokedSemiCircle(), VECTOR2< T >::EuclideanNorm(), KIGFX::COLOR4D::g, m_currentManager, KIGFX::GAL::m_fillColor, KIGFX::GAL::m_isFillEnabled, KIGFX::GAL::m_strokeColor, KIGFX::COLOR4D::r, KIGFX::VERTEX_MANAGER::Reserve(), Restore(), KIGFX::VERTEX_MANAGER::Rotate(), Save(), KIGFX::GAL::SetLineWidth(), KIGFX::VERTEX_MANAGER::Translate(), VECTOR2< T >::x, and VECTOR2< T >::y.

Referenced by DrawSegment(), and drawSegmentChain().

◆ DrawSegmentChain() [1/2]

void OPENGL_GAL::DrawSegmentChain ( const SHAPE_LINE_CHAIN aLineChain,
double  aWidth 
)
overridevirtual

Reimplemented from KIGFX::GAL.

Definition at line 1103 of file opengl_gal.cpp.

1104{
1105 auto numPoints = aLineChain.PointCount();
1106
1107 if( aLineChain.IsClosed() )
1108 numPoints += 1;
1109
1111 [&]( int idx )
1112 {
1113 return aLineChain.CPoint( idx );
1114 },
1115 numPoints, aWidth );
1116}
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.

References SHAPE_LINE_CHAIN::CPoint(), drawSegmentChain(), SHAPE_LINE_CHAIN::IsClosed(), and SHAPE_LINE_CHAIN::PointCount().

◆ drawSegmentChain()

void OPENGL_GAL::drawSegmentChain ( const std::function< VECTOR2D(int)> &  aPointGetter,
int  aPointCount,
double  aWidth,
bool  aReserve = true 
)
private

Generic way of drawing a chain of segments stored in different containers.

Parameters
aPointGetteris a function to obtain coordinates of n-th vertex.
aPointCountis the number of points to be drawn.
aReserveif set to false, do not reserve vertices internally.

Definition at line 2209 of file opengl_gal.cpp.

2211{
2212 wxCHECK( aPointCount >= 2, /* return */ );
2213
2215
2216 int vertices = 0;
2217
2218 for( int i = 1; i < aPointCount; ++i )
2219 {
2220 auto start = aPointGetter( i - 1 );
2221 auto end = aPointGetter( i );
2222
2223 VECTOR2D startEndVector = start - end;
2224 double lineLength = startEndVector.EuclideanNorm();
2225
2226 float startx = start.x;
2227 float starty = end.y;
2228 float endx = start.x + lineLength;
2229 float endy = end.y + lineLength;
2230
2231 // Be careful about floating point rounding. As we draw segments in larger and larger
2232 // coordinates, the shader (which uses floats) will lose precision and stop drawing small
2233 // segments. In this case, we need to draw a circle for the minimal segment.
2234 if( startx == endx || starty == endy )
2235 {
2236 vertices += 3; // One circle
2237 continue;
2238 }
2239
2240 if( m_isFillEnabled || aWidth == 1.0 )
2241 {
2242 vertices += 6; // One line
2243 }
2244 else
2245 {
2246 vertices += 6 + 6 + 3 + 3; // Two lines and two half-circles
2247 }
2248 }
2249
2250 m_currentManager->Reserve( vertices );
2251
2252 for( int i = 1; i < aPointCount; ++i )
2253 {
2254 auto start = aPointGetter( i - 1 );
2255 auto end = aPointGetter( i );
2256
2257 drawSegment( start, end, aWidth, false );
2258 }
2259}

References KIGFX::COLOR4D::a, KIGFX::COLOR4D::b, KIGFX::VERTEX_MANAGER::Color(), drawSegment(), VECTOR2< T >::EuclideanNorm(), KIGFX::COLOR4D::g, m_currentManager, KIGFX::GAL::m_isFillEnabled, KIGFX::GAL::m_strokeColor, KIGFX::COLOR4D::r, and KIGFX::VERTEX_MANAGER::Reserve().

Referenced by DrawSegmentChain().

◆ DrawSegmentChain() [2/2]

void OPENGL_GAL::DrawSegmentChain ( const std::vector< VECTOR2D > &  aPointList,
double  aWidth 
)
overridevirtual

Draw a chain of rounded segments.

Parameters
aPointListis a list of 2D-Vectors containing the chain points.
aWidthis a width of the segments

Reimplemented from KIGFX::GAL.

Definition at line 1092 of file opengl_gal.cpp.

1093{
1095 [&]( int idx )
1096 {
1097 return aPointList[idx];
1098 },
1099 aPointList.size(), aWidth );
1100}

References drawSegmentChain().

◆ drawSemiCircle()

void OPENGL_GAL::drawSemiCircle ( const VECTOR2D aCenterPoint,
double  aRadius,
double  aAngle 
)
private

Draw a semicircle.

Depending on settings (m_isStrokeEnabled & isFilledEnabled) it runs the proper function (drawStrokedSemiCircle or drawFilledSemiCircle).

Parameters
aCenterPointis the center point.
aRadiusis the radius of the semicircle.
aAngleis the angle of the semicircle.

Definition at line 2058 of file opengl_gal.cpp.

2059{
2060 if( m_isFillEnabled )
2061 {
2063 drawFilledSemiCircle( aCenterPoint, aRadius, aAngle );
2064 }
2065
2066 if( m_isStrokeEnabled )
2067 {
2069 m_strokeColor.a );
2070 drawStrokedSemiCircle( aCenterPoint, aRadius, aAngle );
2071 }
2072}
void drawFilledSemiCircle(const VECTOR2D &aCenterPoint, double aRadius, double aAngle)
Draw a filled semicircle.

References KIGFX::COLOR4D::a, KIGFX::COLOR4D::b, KIGFX::VERTEX_MANAGER::Color(), drawFilledSemiCircle(), drawStrokedSemiCircle(), KIGFX::COLOR4D::g, m_currentManager, KIGFX::GAL::m_fillColor, KIGFX::GAL::m_isFillEnabled, KIGFX::GAL::m_isStrokeEnabled, KIGFX::GAL::m_strokeColor, and KIGFX::COLOR4D::r.

◆ drawStrokedSemiCircle()

void OPENGL_GAL::drawStrokedSemiCircle ( const VECTOR2D aCenterPoint,
double  aRadius,
double  aAngle,
bool  aReserve = true 
)
private

Draw a stroked semicircle.

Parameters
aCenterPointis the center point.
aRadiusis the radius of the semicircle.
aAngleis the angle of the semicircle.
aReserveif set to false, reserve 3 vertices for each semicircle.

Definition at line 2105 of file opengl_gal.cpp.

2107{
2108 double outerRadius = aRadius + ( m_lineWidth / 2 );
2109
2110 Save();
2111
2112 if( aReserve )
2114
2115 m_currentManager->Translate( aCenterPoint.x, aCenterPoint.y, 0.0f );
2116 m_currentManager->Rotate( aAngle, 0.0f, 0.0f, 1.0f );
2117
2118 /* Draw a triangle that contains the semicircle, then shade it to leave only
2119 * the semicircle. Parameters given to Shader() are indices of the triangle's vertices
2120 * (if you want to understand more, check the vertex shader source [shader.vert]), the
2121 * radius and the line width. Shader uses these coordinates to determine if fragments are
2122 * inside the semicircle or not.
2123 * v2
2124 * /\
2125 * /__\
2126 * v0 //__\\ v1
2127 */
2129 m_currentManager->Vertex( -outerRadius * 3.0f / sqrt( 3.0f ), 0.0f, m_layerDepth ); // v0
2130
2132 m_currentManager->Vertex( outerRadius * 3.0f / sqrt( 3.0f ), 0.0f, m_layerDepth ); // v1
2133
2135 m_currentManager->Vertex( 0.0f, outerRadius * 2.0f, m_layerDepth ); // v2
2136
2137 Restore();
2138}

References m_currentManager, KIGFX::GAL::m_layerDepth, KIGFX::GAL::m_lineWidth, KIGFX::VERTEX_MANAGER::Reserve(), Restore(), KIGFX::VERTEX_MANAGER::Rotate(), Save(), KIGFX::VERTEX_MANAGER::Shader(), KIGFX::SHADER_STROKED_CIRCLE, KIGFX::VERTEX_MANAGER::Translate(), KIGFX::VERTEX_MANAGER::Vertex(), VECTOR2< T >::x, and VECTOR2< T >::y.

Referenced by DrawArcSegment(), drawSegment(), and drawSemiCircle().

◆ drawTriangulatedPolyset()

void OPENGL_GAL::drawTriangulatedPolyset ( const SHAPE_POLY_SET aPoly,
bool  aStrokeTriangulation 
)
private

Draw a set of polygons with a cached triangulation.

Way faster than drawPolygon.

Parameters
aStrokeTriangulationindicates the triangulation should be stroked rather than filled. Used for debugging.

Definition at line 1225 of file opengl_gal.cpp.

1227{
1230
1231 if( m_isFillEnabled )
1232 {
1233 int totalTriangleCount = 0;
1234
1235 for( unsigned int j = 0; j < aPolySet.TriangulatedPolyCount(); ++j )
1236 {
1237 auto triPoly = aPolySet.TriangulatedPolygon( j );
1238
1239 totalTriangleCount += triPoly->GetTriangleCount();
1240 }
1241
1242 m_currentManager->Reserve( 3 * totalTriangleCount );
1243
1244 for( unsigned int j = 0; j < aPolySet.TriangulatedPolyCount(); ++j )
1245 {
1246 auto triPoly = aPolySet.TriangulatedPolygon( j );
1247
1248 for( size_t i = 0; i < triPoly->GetTriangleCount(); i++ )
1249 {
1250 VECTOR2I a, b, c;
1251 triPoly->GetTriangle( i, a, b, c );
1255 }
1256 }
1257 }
1258
1259 if( m_isStrokeEnabled )
1260 {
1261 for( int j = 0; j < aPolySet.OutlineCount(); ++j )
1262 {
1263 const auto& poly = aPolySet.Polygon( j );
1264
1265 for( const auto& lc : poly )
1266 {
1267 DrawPolyline( lc );
1268 }
1269 }
1270 }
1271
1272 if( ADVANCED_CFG::GetCfg().m_DrawTriangulationOutlines )
1273 {
1274 aStrokeTriangulation = true;
1275 SetStrokeColor( COLOR4D( 0.0, 1.0, 0.2, 1.0 ) );
1276 }
1277
1278 if( aStrokeTriangulation )
1279 {
1280 COLOR4D oldStrokeColor = m_strokeColor;
1281 double oldLayerDepth = m_layerDepth;
1282
1284
1285 for( unsigned int j = 0; j < aPolySet.TriangulatedPolyCount(); ++j )
1286 {
1287 auto triPoly = aPolySet.TriangulatedPolygon( j );
1288
1289 for( size_t i = 0; i < triPoly->GetTriangleCount(); i++ )
1290 {
1291 VECTOR2I a, b, c;
1292 triPoly->GetTriangle( i, a, b, c );
1293 DrawLine( a, b );
1294 DrawLine( b, c );
1295 DrawLine( c, a );
1296 }
1297 }
1298
1299 SetStrokeColor( oldStrokeColor );
1300 SetLayerDepth( oldLayerDepth );
1301 }
1302}
static const ADVANCED_CFG & GetCfg()
Get the singleton instance's config, which is shared by all consumers.
virtual void SetLayerDepth(double aLayerDepth)
Set the depth of the layer (position on the z-axis)

References KIGFX::COLOR4D::a, KIGFX::COLOR4D::b, KIGFX::VERTEX_MANAGER::Color(), DrawLine(), DrawPolyline(), KIGFX::COLOR4D::g, ADVANCED_CFG::GetCfg(), SHAPE_POLY_SET::TRIANGULATED_POLYGON::GetTriangleCount(), m_currentManager, KIGFX::GAL::m_fillColor, KIGFX::GAL::m_isFillEnabled, KIGFX::GAL::m_isStrokeEnabled, KIGFX::GAL::m_layerDepth, KIGFX::GAL::m_strokeColor, SHAPE_POLY_SET::OutlineCount(), SHAPE_POLY_SET::Polygon(), KIGFX::COLOR4D::r, KIGFX::VERTEX_MANAGER::Reserve(), KIGFX::GAL::SetLayerDepth(), KIGFX::GAL::SetStrokeColor(), KIGFX::VERTEX_MANAGER::Shader(), KIGFX::SHADER_NONE, SHAPE_POLY_SET::TriangulatedPolyCount(), SHAPE_POLY_SET::TriangulatedPolygon(), KIGFX::VERTEX_MANAGER::Vertex(), VECTOR2< T >::x, and VECTOR2< T >::y.

Referenced by DrawPolygon().

◆ EnableDepthTest()

void OPENGL_GAL::EnableDepthTest ( bool  aEnabled = false)
overridevirtual

Reimplemented from KIGFX::GAL.

Definition at line 2635 of file opengl_gal.cpp.

2636{
2637 m_cachedManager->EnableDepthTest( aEnabled );
2639 m_overlayManager->EnableDepthTest( aEnabled );
2640}

References KIGFX::VERTEX_MANAGER::EnableDepthTest(), m_cachedManager, m_nonCachedManager, and m_overlayManager.

◆ EndDiffLayer()

void OPENGL_GAL::EndDiffLayer ( )
overridevirtual

Ends rendering of a differential layer.

Objects drawn after the StartDiffLayer() will be drawn and composited with a differential blend mode, then drawing is returned to normal.

Reimplemented from KIGFX::GAL.

Definition at line 1962 of file opengl_gal.cpp.

1963{
1964 glBlendEquation( GL_MAX );
1966 glBlendEquation( GL_FUNC_ADD );
1967
1969}
virtual void DrawBuffer(unsigned int aBufferHandle) override
Draw the selected buffer to the output buffer.

References KIGFX::OPENGL_COMPOSITOR::DrawBuffer(), KIGFX::VERTEX_MANAGER::EndDrawing(), m_compositor, m_currentManager, m_mainBuffer, and m_tempBuffer.

◆ EndDrawing()

void OPENGL_GAL::EndDrawing ( )
overridevirtual

End the drawing, needs to be called for every new frame.

Use GAL_DRAWING_CONTEXT RAII object unless you know what you're doing. Parameters passed to the GLU tesselator

Reimplemented from KIGFX::GAL.

Definition at line 605 of file opengl_gal.cpp.

606{
607 wxASSERT_MSG( m_isContextLocked, "What happened to the context lock?" );
608
609 PROF_TIMER cntTotal("gl-end-total");
610 PROF_TIMER cntEndCached("gl-end-cached");
611 PROF_TIMER cntEndNoncached("gl-end-noncached");
612 PROF_TIMER cntEndOverlay("gl-end-overlay");
613 PROF_TIMER cntComposite("gl-composite");
614 PROF_TIMER cntSwap("gl-swap");
615
616 cntTotal.Start();
617 // Cached & non-cached containers are rendered to the same buffer
619
620 cntEndNoncached.Start();
622 cntEndNoncached.Stop();
623
624 cntEndCached.Start();
626 cntEndCached.Stop();
627
628 cntEndOverlay.Start();
629 // Overlay container is rendered to a different buffer
630 if( m_overlayBuffer )
632
634 cntEndOverlay.Stop();
635
636 cntComposite.Start();
637 // Be sure that the framebuffer is not colorized (happens on specific GPU&drivers combinations)
638 glColor4d( 1.0, 1.0, 1.0, 1.0 );
639
640 // Draw the remaining contents, blit the rendering targets to the screen, swap the buffers
642
643 if( m_overlayBuffer )
645
647 blitCursor();
648
649 cntComposite.Stop();
650
651 cntSwap.Start();
652 SwapBuffers();
653 cntSwap.Stop();
654
655 cntTotal.Stop();
656
657 KI_TRACE( traceGalProfile, "Timing: %s %s %s %s %s %s\n", cntTotal.to_string(),
658 cntEndCached.to_string(), cntEndNoncached.to_string(), cntEndOverlay.to_string(),
659 cntComposite.to_string(), cntSwap.to_string() );
660}
virtual void Present() override
Call this to present the output buffer to the screen.
void blitCursor()
Blit cursor into the current screen.
#define KI_TRACE(aWhat,...)

References blitCursor(), KIGFX::OPENGL_COMPOSITOR::DrawBuffer(), KIGFX::VERTEX_MANAGER::EndDrawing(), KI_TRACE, m_cachedManager, m_compositor, m_isContextLocked, m_mainBuffer, m_nonCachedManager, m_overlayBuffer, m_overlayManager, KIGFX::OPENGL_COMPOSITOR::Present(), KIGFX::OPENGL_COMPOSITOR::SetBuffer(), PROF_TIMER::Start(), PROF_TIMER::Stop(), PROF_TIMER::to_string(), and traceGalProfile.

◆ EndGroup()

void OPENGL_GAL::EndGroup ( )
overridevirtual

End the group.

Reimplemented from KIGFX::GAL.

Definition at line 1834 of file opengl_gal.cpp.

1835{
1837 m_isGrouping = false;
1838}
void FinishItem() const
Clean after adding an item.

References KIGFX::VERTEX_MANAGER::FinishItem(), m_cachedManager, and m_isGrouping.

◆ EndNegativesLayer()

virtual void KIGFX::GAL::EndNegativesLayer ( )
inlinevirtualinherited

Ends rendering of a negatives layer and draws it to the main layer.

No-op in OpenGL.

Reimplemented in KIGFX::CAIRO_GAL.

Definition at line 702 of file graphics_abstraction_layer.h.

702{};

Referenced by KIGFX::VIEW::redrawRect().

◆ endUpdate()

void OPENGL_GAL::endUpdate ( )
overrideprivatevirtual

Update handler for OpenGL settings

Reimplemented from KIGFX::GAL.

Definition at line 703 of file opengl_gal.cpp.

704{
705 if( !m_isInitialized )
706 return;
707
709}
void Unmap()
Unmap vertex buffer.

References m_cachedManager, m_isInitialized, and KIGFX::VERTEX_MANAGER::Unmap().

◆ Flush()

void OPENGL_GAL::Flush ( )
overridevirtual

Force all remaining objects to be drawn.

Reimplemented from KIGFX::GAL.

Definition at line 1757 of file opengl_gal.cpp.

1758{
1759 glFlush();
1760}

◆ GetClearColor()

const COLOR4D & KIGFX::GAL::GetClearColor ( ) const
inlineinherited

Definition at line 260 of file graphics_abstraction_layer.h.

261 {
262 return m_clearColor;
263 }

References KIGFX::GAL::m_clearColor.

Referenced by EDIT_POINTS::ViewDraw().

◆ getCursorColor()

COLOR4D GAL::getCursorColor ( ) const
protectedinherited

Get the actual cursor color to draw.

Definition at line 244 of file graphics_abstraction_layer.cpp.

245{
247
248 // dim the cursor if it's only on because it was forced
249 // (this helps to provide a hint for active tools)
250 if( !m_isCursorEnabled )
251 color.a = color.a * 0.5;
252
253 return color;
254}
bool m_isCursorEnabled
Is the cursor enabled?
COLOR4D m_cursorColor
Cursor color.

References color, KIGFX::GAL::m_cursorColor, and KIGFX::GAL::m_isCursorEnabled.

Referenced by blitCursor(), and KIGFX::CAIRO_GAL_BASE::blitCursor().

◆ GetFillColor()

const COLOR4D & KIGFX::GAL::GetFillColor ( ) const
inlineinherited

Get the fill color.

Returns
the color for filling a outline.

Definition at line 311 of file graphics_abstraction_layer.h.

312 {
313 return m_fillColor;
314 }

References KIGFX::GAL::m_fillColor.

◆ GetGlyphSize()

const VECTOR2I & KIGFX::GAL::GetGlyphSize ( ) const
inlineinherited

Definition at line 393 of file graphics_abstraction_layer.h.

393{ return m_attributes.m_Size; }
TEXT_ATTRIBUTES m_attributes

References KIGFX::GAL::m_attributes, and TEXT_ATTRIBUTES::m_Size.

Referenced by BitmapText().

◆ GetGridLineWidth()

float KIGFX::GAL::GetGridLineWidth ( ) const
inlineinherited

Get the grid line width.

Returns
the grid line width Draw the grid

Definition at line 818 of file graphics_abstraction_layer.h.

References KIGFX::GAL::m_gridLineWidth.

◆ GetGridOrigin()

const VECTOR2D & KIGFX::GAL::GetGridOrigin ( ) const
inlineinherited

Definition at line 743 of file graphics_abstraction_layer.h.

744 {
745 return m_gridOrigin;
746 }

References KIGFX::GAL::m_gridOrigin.

Referenced by GRID_HELPER::GetOrigin().

◆ GetGridPoint()

VECTOR2D GAL::GetGridPoint ( const VECTOR2D aPoint) const
inherited

For a given point it returns the nearest point belonging to the grid in world coordinates.

Parameters
aPointis the point for which the grid point is searched.
Returns
The nearest grid point in world coordinates.

Definition at line 222 of file graphics_abstraction_layer.cpp.

223{
224#if 0
225 // This old code expects a non zero grid size, which can be wrong here.
226 return VECTOR2D( KiROUND( ( aPoint.x - m_gridOffset.x ) / m_gridSize.x ) * m_gridSize.x + m_gridOffset.x,
227 KiROUND( ( aPoint.y - m_gridOffset.y ) / m_gridSize.y ) * m_gridSize.y + m_gridOffset.y );
228#else
229 // if grid size == 0.0 there is no grid, so use aPoint as grid reference position
230 double cx = m_gridSize.x > 0.0 ? KiROUND( ( aPoint.x - m_gridOffset.x ) / m_gridSize.x ) * m_gridSize.x + m_gridOffset.x
231 : aPoint.x;
232 double cy = m_gridSize.y > 0.0 ? KiROUND( ( aPoint.y - m_gridOffset.y ) / m_gridSize.y ) * m_gridSize.y + m_gridOffset.y
233 : aPoint.y;
234
235 return VECTOR2D( cx, cy );
236#endif
237}
VECTOR2D m_gridOffset
The grid offset to compensate cursor position.

References KiROUND(), KIGFX::GAL::m_gridOffset, KIGFX::GAL::m_gridSize, VECTOR2< T >::x, and VECTOR2< T >::y.

Referenced by KIGFX::WX_VIEW_CONTROLS::GetRawCursorPosition().

◆ GetGridSize()

◆ GetGridSnapping()

◆ GetGridVisibility()

bool KIGFX::GAL::GetGridVisibility ( ) const
inlineinherited

Definition at line 715 of file graphics_abstraction_layer.h.

715{ return m_gridVisibility; }

References KIGFX::GAL::m_gridVisibility.

Referenced by EDA_DRAW_PANEL_GAL::SwitchBackend().

◆ GetHorizontalJustify()

GR_TEXT_H_ALIGN_T KIGFX::GAL::GetHorizontalJustify ( ) const
inlineinherited

Definition at line 412 of file graphics_abstraction_layer.h.

412{ return m_attributes.m_Halign; }
GR_TEXT_H_ALIGN_T m_Halign

References KIGFX::GAL::m_attributes, and TEXT_ATTRIBUTES::m_Halign.

Referenced by BitmapText().

◆ GetLineWidth()

float KIGFX::GAL::GetLineWidth ( ) const
inlineinherited

Get the line width.

Returns
the actual line width.

Definition at line 351 of file graphics_abstraction_layer.h.

352 {
353 return m_lineWidth;
354 }

References KIGFX::GAL::m_lineWidth.

Referenced by KIGFX::GAL::BitmapText(), CALLBACK_GAL::DrawGlyph(), and DrawGrid().

◆ GetLookAtPoint()

const VECTOR2D & KIGFX::GAL::GetLookAtPoint ( ) const
inlineinherited

Definition at line 579 of file graphics_abstraction_layer.h.

579{ return m_lookAtPoint; }

References KIGFX::GAL::m_lookAtPoint.

Referenced by KIGFX::GAL::GetVisibleWorldExtents().

◆ GetMaxDepth()

double KIGFX::GAL::GetMaxDepth ( ) const
inlineinherited

◆ GetMinDepth()

double KIGFX::GAL::GetMinDepth ( ) const
inlineinherited

◆ GetNativePixelSize()

wxSize HIDPI_GL_CANVAS::GetNativePixelSize ( ) const
virtualinherited

Definition at line 41 of file hidpi_gl_canvas.cpp.

42{
43 wxSize size = wxGLCanvas::GetClientSize();
44
45 const double scaleFactor = GetScaleFactor();
46 size.x *= scaleFactor;
47 size.y *= scaleFactor;
48
49 return size;
50}

References HIDPI_GL_CANVAS::GetScaleFactor().

Referenced by EDA_3D_CANVAS::DoRePaint(), EDA_3D_MODEL_VIEWER::OnMouseMove(), HIDPI_GL_3D_CANVAS::OnMouseMoveCamera(), EDA_3D_MODEL_VIEWER::OnPaint(), and OPENGL_GAL().

◆ GetNativePosition()

wxPoint HIDPI_GL_CANVAS::GetNativePosition ( const wxPoint &  aPoint) const
inherited

Convert the given point from client coordinates to native pixel coordinates.

Definition at line 53 of file hidpi_gl_canvas.cpp.

54{
55 wxPoint nativePoint = aPoint;
56
57 const double scaleFactor = GetScaleFactor();
58 nativePoint.x *= scaleFactor;
59 nativePoint.y *= scaleFactor;
60
61 return nativePoint;
62}

References HIDPI_GL_CANVAS::GetScaleFactor().

Referenced by EDA_3D_MODEL_VIEWER::OnMouseMove(), HIDPI_GL_3D_CANVAS::OnMouseMoveCamera(), and HIDPI_GL_3D_CANVAS::OnMouseWheelCamera().

◆ getNewGroupNumber()

unsigned int OPENGL_GAL::getNewGroupNumber ( )
private

Return a valid key that can be used as a new group number.

Returns
An unique group number that is not used by any other group.

Definition at line 2477 of file opengl_gal.cpp.

2478{
2479 wxASSERT_MSG( m_groups.size() < std::numeric_limits<unsigned int>::max(),
2480 wxT( "There are no free slots to store a group" ) );
2481
2482 while( m_groups.find( m_groupCounter ) != m_groups.end() )
2484
2485 return m_groupCounter++;
2486}

References m_groupCounter, and m_groups.

Referenced by BeginGroup().

◆ GetRotation()

double KIGFX::GAL::GetRotation ( ) const
inlineinherited

Definition at line 588 of file graphics_abstraction_layer.h.

588{ return m_rotation; }
double m_rotation
Rotation transformation (radians)

References KIGFX::GAL::m_rotation.

◆ GetScaleFactor()

double HIDPI_GL_CANVAS::GetScaleFactor ( ) const
inherited

◆ GetScreenPixelSize()

◆ getScreenPixelSize()

VECTOR2D OPENGL_GAL::getScreenPixelSize ( ) const
private

Definition at line 436 of file opengl_gal.cpp.

437{
438 double sf = GetScaleFactor();
439 return VECTOR2D( 2.0 / (double) ( m_screenSize.x * sf ), 2.0 /
440 (double) ( m_screenSize.y * sf ) );
441}

References HIDPI_GL_CANVAS::GetScaleFactor(), KIGFX::GAL::m_screenSize, VECTOR2< T >::x, and VECTOR2< T >::y.

Referenced by BeginDrawing().

◆ GetScreenWorldMatrix()

const MATRIX3x3D & KIGFX::GAL::GetScreenWorldMatrix ( ) const
inlineinherited

Get the screen <-> world transformation matrix.

Returns
the transformation matrix.

Definition at line 534 of file graphics_abstraction_layer.h.

535 {
536 return m_screenWorldMatrix;
537 }

References KIGFX::GAL::m_screenWorldMatrix.

Referenced by KIGFX::PCB_PAINTER::draw(), KIGFX::SCH_PAINTER::getShadowWidth(), KIGFX::GAL::GetVisibleWorldExtents(), getWorldPixelSize(), screenSpaceCircle(), screenSpaceLine(), and KIGFX::VIEW::ToWorld().

◆ GetStrokeColor()

const COLOR4D & KIGFX::GAL::GetStrokeColor ( ) const
inlineinherited

Get the stroke color.

Returns
the color for stroking the outline.

Definition at line 331 of file graphics_abstraction_layer.h.

332 {
333 return m_strokeColor;
334 }

References KIGFX::GAL::m_strokeColor.

Referenced by KIGFX::PREVIEW::DrawTextNextToCursor(), and KIGFX::PREVIEW::RULER_ITEM::ViewDraw().

◆ GetTarget()

RENDER_TARGET OPENGL_GAL::GetTarget ( ) const
overridevirtual

Get the currently used target for rendering.

Returns
The current rendering target.

Reimplemented from KIGFX::GAL.

Definition at line 1901 of file opengl_gal.cpp.

1902{
1903 return m_currentTarget;
1904}
RENDER_TARGET m_currentTarget
Current rendering target.
Definition: opengl_gal.h:353

References m_currentTarget.

◆ GetVerticalJustify()

GR_TEXT_V_ALIGN_T KIGFX::GAL::GetVerticalJustify ( ) const
inlineinherited

Definition at line 419 of file graphics_abstraction_layer.h.

419{ return m_attributes.m_Valign; }
GR_TEXT_V_ALIGN_T m_Valign

References KIGFX::GAL::m_attributes, and TEXT_ATTRIBUTES::m_Valign.

Referenced by BitmapText().

◆ GetVisibleWorldExtents()

BOX2D GAL::GetVisibleWorldExtents ( ) const
inherited
Returns
the bounding box of the world that is displayed on screen at the moment

Definition at line 199 of file graphics_abstraction_layer.cpp.

200{
201 const MATRIX3x3D& matrix = GetScreenWorldMatrix();
202
203 VECTOR2D halfSize = VECTOR2D( matrix.GetScale().x * m_screenSize.x * 0.5,
204 matrix.GetScale().y * m_screenSize.y * 0.5 );
205
206 BOX2D extents;
207 extents.SetOrigin( GetLookAtPoint() - halfSize );
208 extents.SetSize( halfSize * 2 );
209
210 return extents;
211}
void SetOrigin(const Vec &pos)
Definition: box2.h:202
void SetSize(const Vec &size)
Definition: box2.h:213
const VECTOR2D & GetLookAtPoint() const
const MATRIX3x3D & GetScreenWorldMatrix() const
Get the screen <-> world transformation matrix.
VECTOR2< T > GetScale() const
Get the scale components of the matrix.
Definition: matrix3x3.h:265

References KIGFX::GAL::GetLookAtPoint(), MATRIX3x3< T >::GetScale(), KIGFX::GAL::GetScreenWorldMatrix(), KIGFX::GAL::m_screenSize, BOX2< Vec >::SetOrigin(), BOX2< Vec >::SetSize(), VECTOR2< T >::x, and VECTOR2< T >::y.

Referenced by ROUTER_TOOL::handleCommonEvents(), and ROUTER_TOOL::InlineDrag().

◆ getWorldPixelSize()

double OPENGL_GAL::getWorldPixelSize ( ) const
private

Definition at line 429 of file opengl_gal.cpp.

430{
432 return std::min( std::abs( matrix.GetScale().x ), std::abs( matrix.GetScale().y ) );
433}
EDA_ANGLE abs(const EDA_ANGLE &aAngle)
Definition: eda_angle.h:401

References std::abs(), MATRIX3x3< T >::GetScale(), KIGFX::GAL::GetScreenWorldMatrix(), VECTOR2< T >::x, and VECTOR2< T >::y.

Referenced by BeginDrawing(), and DrawGrid().

◆ GetWorldScale()

◆ GetWorldScreenMatrix()

const MATRIX3x3D & KIGFX::GAL::GetWorldScreenMatrix ( ) const
inlineinherited

Get the world <-> screen transformation matrix.

Returns
the transformation matrix.

Definition at line 524 of file graphics_abstraction_layer.h.

525 {
526 return m_worldScreenMatrix;
527 }

References KIGFX::GAL::m_worldScreenMatrix.

Referenced by KIGFX::VIEW::ToScreen().

◆ GetZoomFactor()

◆ HasTarget()

bool OPENGL_GAL::HasTarget ( RENDER_TARGET  aTarget)
overridevirtual

Return true if the target exists.

Parameters
aTargetis the target to be checked.

Reimplemented from KIGFX::GAL.

Definition at line 1941 of file opengl_gal.cpp.

1942{
1943 switch( aTarget )
1944 {
1945 default:
1946 case TARGET_TEMP:
1947 case TARGET_CACHED:
1948 case TARGET_NONCACHED: return true;
1949 case TARGET_OVERLAY: return ( m_overlayBuffer != 0 );
1950 }
1951}

References m_overlayBuffer, KIGFX::TARGET_CACHED, KIGFX::TARGET_NONCACHED, KIGFX::TARGET_OVERLAY, and KIGFX::TARGET_TEMP.

◆ init()

void OPENGL_GAL::init ( )
private

Basic OpenGL initialization and feature checks.

Exceptions
std::runtime_errorif any of the OpenGL feature checks failed

Definition at line 2489 of file opengl_gal.cpp.

2490{
2491 wxASSERT( IsShownOnScreen() );
2492
2493 wxASSERT_MSG( m_isContextLocked, "This should only be called from within a locked context." );
2494
2495// IsDisplayAttr() handles WX_GL_{MAJOR,MINOR}_VERSION correctly only in 3.0.4
2496// starting with 3.1.0 one should use wxGLContext::IsOk() (done by GL_CONTEXT_MANAGER)
2497#if wxCHECK_VERSION( 3, 0, 3 ) and !wxCHECK_VERSION( 3, 1, 0 )
2498 const int attr[] = { WX_GL_MAJOR_VERSION, 2, WX_GL_MINOR_VERSION, 1, 0 };
2499
2500 if( !IsDisplaySupported( attr ) )
2501 throw std::runtime_error( "OpenGL 2.1 or higher is required!" );
2502#endif /* wxCHECK_VERSION( 3, 0, 3 ) */
2503
2504 // Check correct initialization from the constructor
2505 if( !m_glMainContext )
2506 throw std::runtime_error( "Could not create the main OpenGL context" );
2507
2508 if( !m_glPrivContext )
2509 throw std::runtime_error( "Could not create a private OpenGL context" );
2510
2511 if( m_tesselator == nullptr )
2512 throw std::runtime_error( "Could not create the m_tesselator" );
2513 // End initialization checks
2514
2515 GLenum err = glewInit();
2516
2517 if( GLEW_OK != err )
2518 throw std::runtime_error( (const char*) glewGetErrorString( err ) );
2519
2520 // Check the OpenGL version (minimum 2.1 is required)
2521 if( !GLEW_VERSION_2_1 )
2522 throw std::runtime_error( "OpenGL 2.1 or higher is required!" );
2523
2524#if defined( __LINUX__ ) // calling enableGlDebug crashes opengl on some OS (OSX and some Windows)
2525#ifdef DEBUG
2526 if( GLEW_ARB_debug_output )
2527 enableGlDebug( true );
2528#endif
2529#endif
2530
2531 // Framebuffers have to be supported
2532 if( !GLEW_EXT_framebuffer_object )
2533 throw std::runtime_error( "Framebuffer objects are not supported!" );
2534
2535 // Vertex buffer has to be supported
2536 if( !GLEW_ARB_vertex_buffer_object )
2537 throw std::runtime_error( "Vertex buffer objects are not supported!" );
2538
2539 // Prepare shaders
2540 if( !m_shader->IsLinked()
2542 BUILTIN_SHADERS::glsl_kicad_vert ) )
2543 {
2544 throw std::runtime_error( "Cannot compile vertex shader!" );
2545 }
2546
2547 if( !m_shader->IsLinked()
2549 BUILTIN_SHADERS::glsl_kicad_frag ) )
2550 {
2551 throw std::runtime_error( "Cannot compile fragment shader!" );
2552 }
2553
2554 if( !m_shader->IsLinked() && !m_shader->Link() )
2555 throw std::runtime_error( "Cannot link the shaders!" );
2556
2557 // Check if video card supports textures big enough to fit the font atlas
2558 int maxTextureSize;
2559 glGetIntegerv( GL_MAX_TEXTURE_SIZE, &maxTextureSize );
2560
2561 if( maxTextureSize < (int) font_image.width || maxTextureSize < (int) font_image.height )
2562 {
2563 // TODO implement software texture scaling
2564 // for bitmap fonts and use a higher resolution texture?
2565 throw std::runtime_error( "Requested texture size is not supported" );
2566 }
2567
2569
2570 m_cachedManager = new VERTEX_MANAGER( true );
2571 m_nonCachedManager = new VERTEX_MANAGER( false );
2572 m_overlayManager = new VERTEX_MANAGER( false );
2573 m_tempManager = new VERTEX_MANAGER( false );
2574
2575 // Make VBOs use shaders
2580
2581 m_isInitialized = true;
2582}
static int SetSwapInterval(int aVal)
Attempts to set the OpenGL swap interval.
Definition: gl_utils.h:42
bool IsLinked() const
Return true if shaders are linked correctly.
Definition: shader.h:118
bool Link()
Link the shaders.
Definition: shader.cpp:101
bool LoadShaderFromStrings(SHADER_TYPE aShaderType, Args &&... aArgs)
Add a shader and compile the shader sources.
Definition: shader.h:93
Class to control vertex container and GPU with possibility of emulating old-style OpenGL 1....
void SetShader(SHADER &aShader) const
Set a shader program that is going to be used during rendering.
@ SHADER_TYPE_VERTEX
Vertex shader.
Definition: shader.h:46
@ SHADER_TYPE_FRAGMENT
Fragment shader.
Definition: shader.h:47
void enableGlDebug(bool aEnable)
Enable or disable OpenGL driver messages output.
Definition: utils.cpp:183

References enableGlDebug(), KIGFX::BUILTIN_FONT::font_image, KIGFX::BUILTIN_FONT::FONT_IMAGE_TYPE::height, KIGFX::SHADER::IsLinked(), KIGFX::SHADER::Link(), KIGFX::SHADER::LoadShaderFromStrings(), m_cachedManager, m_glMainContext, m_glPrivContext, m_isContextLocked, m_isInitialized, m_nonCachedManager, m_overlayManager, m_shader, m_tempManager, m_tesselator, KIGFX::VERTEX_MANAGER::SetShader(), GL_UTILS::SetSwapInterval(), KIGFX::SHADER_TYPE_FRAGMENT, KIGFX::SHADER_TYPE_VERTEX, and KIGFX::BUILTIN_FONT::FONT_IMAGE_TYPE::width.

Referenced by BeginDrawing(), beginUpdate(), and CheckFeatures().

◆ IsCairoEngine()

virtual bool KIGFX::GAL::IsCairoEngine ( )
inlinevirtualinherited

Return true if the GAL engine is a Cairo based type.

Reimplemented in KIGFX::CAIRO_GAL_BASE.

Definition at line 80 of file graphics_abstraction_layer.h.

80{ return false; }

Referenced by getShadowLayer().

◆ IsContextLocked()

bool KIGFX::OPENGL_GAL::IsContextLocked ( )
inlineoverridevirtual

Checks the state of the context lock.

Returns
True if the context is currently locked

Reimplemented from KIGFX::GAL.

Definition at line 299 of file opengl_gal.h.

300 {
301 return m_isContextLocked;
302 }

References m_isContextLocked.

◆ IsCursorEnabled()

bool KIGFX::GAL::IsCursorEnabled ( ) const
inlineinherited

Return information about cursor visibility.

Returns
True if cursor is visible.

Definition at line 879 of file graphics_abstraction_layer.h.

880 {
882 }
bool m_forceDisplayCursor
Always show cursor.

References KIGFX::GAL::m_forceDisplayCursor, and KIGFX::GAL::m_isCursorEnabled.

Referenced by blitCursor(), and KIGFX::CAIRO_GAL_BASE::blitCursor().

◆ IsFlippedX()

◆ IsFlippedY()

bool KIGFX::GAL::IsFlippedY ( ) const
inlineinherited

Definition at line 622 of file graphics_abstraction_layer.h.

622{ return m_globalFlipY; }

References KIGFX::GAL::m_globalFlipY.

◆ IsFontBold()

bool KIGFX::GAL::IsFontBold ( ) const
inlineinherited

◆ IsFontItalic()

bool KIGFX::GAL::IsFontItalic ( ) const
inlineinherited

◆ IsFontUnderlined()

bool KIGFX::GAL::IsFontUnderlined ( ) const
inlineinherited

◆ IsInitialized()

bool KIGFX::OPENGL_GAL::IsInitialized ( ) const
inlineoverridevirtual

Return the initialization status for the canvas.

Return true if the GAL canvas is visible on the screen.

Reimplemented from KIGFX::GAL.

Definition at line 102 of file opengl_gal.h.

◆ IsOpenGlEngine()

bool KIGFX::OPENGL_GAL::IsOpenGlEngine ( )
inlineoverridevirtual

Return true if the GAL engine is a OpenGL based type.

Reimplemented from KIGFX::GAL.

Definition at line 99 of file opengl_gal.h.

99{ return true; }

◆ IsTextMirrored()

bool KIGFX::GAL::IsTextMirrored ( ) const
inlineinherited

Definition at line 405 of file graphics_abstraction_layer.h.

405{ return m_attributes.m_Mirrored; }

References KIGFX::GAL::m_attributes, and TEXT_ATTRIBUTES::m_Mirrored.

Referenced by BitmapText().

◆ IsVisible()

bool KIGFX::OPENGL_GAL::IsVisible ( ) const
inlineoverridevirtual

Return true if the GAL canvas is visible on the screen.

Reimplemented from KIGFX::GAL.

Definition at line 109 of file opengl_gal.h.

110 {
111 return IsShownOnScreen() && !GetClientRect().IsEmpty();
112 }

Referenced by BeginDrawing(), and beginUpdate().

◆ LockContext()

void OPENGL_GAL::LockContext ( int  aClientCookie)
overridevirtual

Use GAL_CONTEXT_LOCKER RAII object unless you know what you're doing.

Reimplemented from KIGFX::GAL.

Definition at line 663 of file opengl_gal.cpp.

664{
665 wxASSERT_MSG( !m_isContextLocked, "Context already locked." );
666 m_isContextLocked = true;
667 m_lockClientCookie = aClientCookie;
668
670}

References GL_CONTEXT_MANAGER::Get(), GL_CONTEXT_MANAGER::LockCtx(), m_glPrivContext, m_isContextLocked, and m_lockClientCookie.

◆ OnGalDisplayOptionsChanged()

void GAL::OnGalDisplayOptionsChanged ( const GAL_DISPLAY_OPTIONS aOptions)
overrideprotectedvirtualinherited

Handler for observer settings changes.

Implements KIGFX::GAL_DISPLAY_OPTIONS_OBSERVER.

Definition at line 99 of file graphics_abstraction_layer.cpp.

100{
101 // defer to the child class first
102 updatedGalDisplayOptions( aOptions );
103
104 // there is no refresh to do at this level
105}
virtual bool updatedGalDisplayOptions(const GAL_DISPLAY_OPTIONS &aOptions)
Handle updating display options.

References KIGFX::GAL::updatedGalDisplayOptions().

◆ onPaint()

void OPENGL_GAL::onPaint ( wxPaintEvent &  aEvent)
private

This is the OnPaint event handler.

Parameters
aEventis the OnPaint event.

Definition at line 2432 of file opengl_gal.cpp.

2433{
2434 PostPaint( aEvent );
2435}
void PostPaint(wxPaintEvent &aEvent)
Function PostPaint posts an event to m_paint_listener.
Definition: opengl_gal.cpp:392

References PostPaint().

Referenced by OPENGL_GAL().

◆ onSetNativeCursor()

void OPENGL_GAL::onSetNativeCursor ( wxSetCursorEvent &  aEvent)
private

Give the correct cursor image when the native widget asks for it.

Parameters
aEventis the cursor event to plac the cursor into.

Definition at line 1987 of file opengl_gal.cpp.

1988{
1989 aEvent.SetCursor( m_currentwxCursor );
1990}
wxCursor m_currentwxCursor
wxCursor showing the current native cursor
Definition: opengl_gal.h:373

References m_currentwxCursor.

Referenced by OPENGL_GAL().

◆ PopDepth()

void KIGFX::GAL::PopDepth ( )
inlineinherited

Restore previously stored drawing depth for the depth stack.

Definition at line 921 of file graphics_abstraction_layer.h.

922 {
924 m_depthStack.pop();
925 }
std::stack< double > m_depthStack
Stored depth values.

References KIGFX::GAL::m_depthStack, and KIGFX::GAL::m_layerDepth.

Referenced by EDIT_POINTS::ViewDraw(), KIGFX::PREVIEW::RULER_ITEM::ViewDraw(), and KIGFX::VIEW_GROUP::ViewDraw().

◆ PostPaint()

void OPENGL_GAL::PostPaint ( wxPaintEvent &  aEvent)

Function PostPaint posts an event to m_paint_listener.

A post is used so that the actual drawing function can use a device context type that is not specific to the wxEVT_PAINT event, just by changing the PostPaint code.

Definition at line 392 of file opengl_gal.cpp.

393{
394 // posts an event to m_paint_listener to ask for redraw the canvas.
395 if( m_paintListener )
396 wxPostEvent( m_paintListener, aEvent );
397}

References m_paintListener.

Referenced by onPaint().

◆ PushDepth()

void KIGFX::GAL::PushDepth ( )
inlineinherited

Store current drawing depth on the depth stack.

Definition at line 913 of file graphics_abstraction_layer.h.

914 {
916 }

References KIGFX::GAL::m_depthStack, and KIGFX::GAL::m_layerDepth.

Referenced by EDIT_POINTS::ViewDraw(), KIGFX::PREVIEW::RULER_ITEM::ViewDraw(), KIGFX::VIEW_GROUP::ViewDraw(), and KIGFX::VIEW_OVERLAY::ViewDraw().

◆ reserveLineQuads()

void OPENGL_GAL::reserveLineQuads ( const int  aLineCount)
private

Reserves specified number of line quads.

Parameters
aLineCountthe number of line quads to reserve.

Definition at line 2052 of file opengl_gal.cpp.

2053{
2054 m_currentManager->Reserve( 6 * aLineCount );
2055}

References m_currentManager, and KIGFX::VERTEX_MANAGER::Reserve().

Referenced by DrawArcSegment(), DrawGlyphs(), drawLineQuad(), drawPolyline(), and DrawPolylines().

◆ ResetTextAttributes()

void GAL::ResetTextAttributes ( )
inherited

Reset text attributes to default styling.

FONT TODO: do we need any of this in GAL anymore?

Normally, custom attributes will be set individually after this, otherwise you can use SetTextAttributes()

Definition at line 153 of file graphics_abstraction_layer.cpp.

154{
155 // Tiny but non-zero - this will always need setting
156 // there is no built-in default
157 SetGlyphSize( { 1, 1 } );
158
161
162 SetFontBold( false );
163 SetFontItalic( false );
164 SetFontUnderlined( false );
165 SetTextMirrored( false );
166}
void SetVerticalJustify(const GR_TEXT_V_ALIGN_T aVerticalJustify)
void SetFontBold(const bool aBold)
void SetFontUnderlined(bool aUnderlined)
void SetHorizontalJustify(const GR_TEXT_H_ALIGN_T aHorizontalJustify)
void SetTextMirrored(const bool aMirrored)
void SetGlyphSize(const VECTOR2I aSize)
void SetFontItalic(bool aItalic)

References GR_TEXT_H_ALIGN_CENTER, GR_TEXT_V_ALIGN_CENTER, KIGFX::GAL::SetFontBold(), KIGFX::GAL::SetFontItalic(), KIGFX::GAL::SetFontUnderlined(), KIGFX::GAL::SetGlyphSize(), KIGFX::GAL::SetHorizontalJustify(), KIGFX::GAL::SetTextMirrored(), and KIGFX::GAL::SetVerticalJustify().

Referenced by KIGFX::PCB_PAINTER::draw(), KIGFX::GAL::GAL(), KIGFX::PREVIEW::ARC_ASSISTANT::ViewDraw(), KIGFX::PREVIEW::RULER_ITEM::ViewDraw(), and KIGFX::PREVIEW::TWO_POINT_ASSISTANT::ViewDraw().

◆ ResizeScreen()

void OPENGL_GAL::ResizeScreen ( int  aWidth,
int  aHeight 
)
overridevirtual

Resizes the canvas.

Reimplemented from KIGFX::GAL.

Definition at line 1733 of file opengl_gal.cpp.

1734{
1735 m_screenSize = VECTOR2I( aWidth, aHeight );
1736
1737 // Resize framebuffers
1738 const float scaleFactor = GetScaleFactor();
1739 m_compositor->Resize( aWidth * scaleFactor, aHeight * scaleFactor );
1741
1742 wxGLCanvas::SetSize( aWidth, aHeight );
1743}
virtual void Resize(unsigned int aWidth, unsigned int aHeight) override
Clear the state of COMPOSITOR, so it has to be reinitialized again with the new dimensions.

References HIDPI_GL_CANVAS::GetScaleFactor(), m_compositor, m_isFramebufferInitialized, KIGFX::GAL::m_screenSize, and KIGFX::OPENGL_COMPOSITOR::Resize().

◆ Restore()

void OPENGL_GAL::Restore ( )
overridevirtual

Restore the context.

Reimplemented from KIGFX::GAL.

Definition at line 1816 of file opengl_gal.cpp.

1817{
1819}
void PopMatrix()
Pop the current transformation matrix stack.

References m_currentManager, and KIGFX::VERTEX_MANAGER::PopMatrix().

Referenced by BitmapText(), DrawArc(), DrawArcSegment(), drawBitmapOverbar(), drawFilledSemiCircle(), drawSegment(), and drawStrokedSemiCircle().

◆ Rotate()

void OPENGL_GAL::Rotate ( double  aAngle)
overridevirtual

Rotate the context.

Parameters
aAngleis the rotation angle in radians.

Reimplemented from KIGFX::GAL.

Definition at line 1792 of file opengl_gal.cpp.

1793{
1794 m_currentManager->Rotate( aAngle, 0.0f, 0.0f, 1.0f );
1795}

References m_currentManager, and KIGFX::VERTEX_MANAGER::Rotate().

◆ Save()

void OPENGL_GAL::Save ( )
overridevirtual

Save the context.

Reimplemented from KIGFX::GAL.

Definition at line 1810 of file opengl_gal.cpp.

1811{
1813}
void PushMatrix()
Push the current transformation matrix stack.

References m_currentManager, and KIGFX::VERTEX_MANAGER::PushMatrix().

Referenced by BitmapText(), DrawArc(), DrawArcSegment(), drawBitmapOverbar(), drawFilledSemiCircle(), drawSegment(), and drawStrokedSemiCircle().

◆ Scale()

void OPENGL_GAL::Scale ( const VECTOR2D aScale)
overridevirtual

Scale the context.

Parameters
aScaleis the scale factor for the x- and y-axis.

Reimplemented from KIGFX::GAL.

Definition at line 1804 of file opengl_gal.cpp.

1805{
1806 m_currentManager->Scale( aScale.x, aScale.y, 0.0f );
1807}

References m_currentManager, KIGFX::VERTEX_MANAGER::Scale(), VECTOR2< T >::x, and VECTOR2< T >::y.

◆ SetAxesColor()

void KIGFX::GAL::SetAxesColor ( const COLOR4D aAxesColor)
inlineinherited

◆ SetAxesEnabled()

◆ SetClearColor()

◆ SetCoarseGrid()

void KIGFX::GAL::SetCoarseGrid ( int  aInterval)
inlineinherited

Draw every tick line wider.

Parameters
aIntervalincrease the width of every aInterval line, if 0 do not use this feature.

Definition at line 808 of file graphics_abstraction_layer.h.

809 {
810 m_gridTick = aInterval;
811 }

References KIGFX::GAL::m_gridTick.

Referenced by KIGFX::GAL::GAL().

◆ SetCursorColor()

void KIGFX::GAL::SetCursorColor ( const COLOR4D aCursorColor)
inlineinherited

Set the cursor color.

Parameters
aCursorColoris the color of the cursor.

Definition at line 889 of file graphics_abstraction_layer.h.

890 {
891 m_cursorColor = aCursorColor;
892 }

References KIGFX::GAL::m_cursorColor.

Referenced by EDA_DRAW_PANEL_GAL::DoRePaint(), KIGFX::GAL::GAL(), and PCB_DRAW_PANEL_GAL::UpdateColors().

◆ SetCursorEnabled()

void KIGFX::GAL::SetCursorEnabled ( bool  aCursorEnabled)
inlineinherited

Enable/disable cursor.

Parameters
aCursorEnabledis true if the cursor should be drawn, else false.

Definition at line 869 of file graphics_abstraction_layer.h.

870 {
871 m_isCursorEnabled = aCursorEnabled;
872 }

References KIGFX::GAL::m_isCursorEnabled.

Referenced by KIGFX::GAL::GAL(), SCH_PREVIEW_PANEL::SCH_PREVIEW_PANEL(), and KIGFX::VIEW_CONTROLS::ShowCursor().

◆ SetDepthRange()

void KIGFX::GAL::SetDepthRange ( const VECTOR2D aDepthRange)
inlineinherited

Set the range of the layer depth.

Usually required for the OpenGL implementation, any object outside this range is not drawn.

The MinDepth (x) is closest to the clipping plane (top) while the MaxDepth (y) is farthest from the clipping plane (bottom).

Definition at line 598 of file graphics_abstraction_layer.h.

598{ m_depthRange = aDepthRange; }

References KIGFX::GAL::m_depthRange.

Referenced by KIGFX::GAL::GAL().

◆ SetFillColor()

virtual void KIGFX::GAL::SetFillColor ( const COLOR4D aColor)
inlinevirtualinherited

◆ SetFlip()

void KIGFX::GAL::SetFlip ( bool  xAxis,
bool  yAxis 
)
inlineinherited

Sets flipping of the screen.

Parameters
xAxisis the flip flag for the X axis.
yAxisis the flip flag for the Y axis.

Definition at line 615 of file graphics_abstraction_layer.h.

616 {
617 m_globalFlipX = xAxis;
618 m_globalFlipY = yAxis;
619 }

References KIGFX::GAL::m_globalFlipX, and KIGFX::GAL::m_globalFlipY.

Referenced by KIGFX::GAL::GAL(), KIGFX::VIEW::SetMirror(), and BOARD_PRINTOUT::setupGal().

◆ SetFontBold()

void KIGFX::GAL::SetFontBold ( const bool  aBold)
inlineinherited

◆ SetFontItalic()

void KIGFX::GAL::SetFontItalic ( bool  aItalic)
inlineinherited

◆ SetFontUnderlined()

void KIGFX::GAL::SetFontUnderlined ( bool  aUnderlined)
inlineinherited

◆ SetGlyphSize()

◆ SetGridColor()

void KIGFX::GAL::SetGridColor ( const COLOR4D aGridColor)
inlineinherited

Set the grid color.

Parameters
aGridColoris the grid color, it should have a low alpha value for the best effect.

Definition at line 780 of file graphics_abstraction_layer.h.

781 {
782 m_gridColor = aGridColor;
783 }

References KIGFX::GAL::m_gridColor.

Referenced by GERBVIEW_FRAME::ActivateGalCanvas(), KIGFX::CAIRO_GAL_BASE::CAIRO_GAL_BASE(), EDA_DRAW_PANEL_GAL::DoRePaint(), OPENGL_GAL(), SCH_PREVIEW_PANEL::SCH_PREVIEW_PANEL(), GERBVIEW_FRAME::SetGridColor(), PCB_EDIT_FRAME::SetGridColor(), and PCB_DRAW_PANEL_GAL::UpdateColors().

◆ SetGridOrigin()

void KIGFX::GAL::SetGridOrigin ( const VECTOR2D aGridOrigin)
inlineinherited

Set the origin point for the grid.

Parameters
aGridOriginis a vector containing the grid origin point, in world coordinates.

Definition at line 728 of file graphics_abstraction_layer.h.

729 {
730 m_gridOrigin = aGridOrigin;
731
732 if( m_gridSize.x == 0.0 || m_gridSize.y == 0.0 )
733 {
734 m_gridOffset = VECTOR2D( 0.0, 0.0);
735 }
736 else
737 {
738 m_gridOffset = VECTOR2D( (long) m_gridOrigin.x % (long) m_gridSize.x,
739 (long) m_gridOrigin.y % (long) m_gridSize.y );
740 }
741 }

References KIGFX::GAL::m_gridOffset, KIGFX::GAL::m_gridOrigin, KIGFX::GAL::m_gridSize, VECTOR2< T >::x, and VECTOR2< T >::y.

Referenced by PCB_CONTROL::DoSetGridOrigin(), Refresh(), and PCB_BASE_EDIT_FRAME::SetBoard().

◆ SetGridSize()

void KIGFX::GAL::SetGridSize ( const VECTOR2D aGridSize)
inlineinherited

Set the grid size.

Parameters
aGridSizeis a vector containing the grid size in x and y direction.

Definition at line 753 of file graphics_abstraction_layer.h.

754 {
755 m_gridSize = aGridSize;
756
757 // Avoid stupid grid size values: a grid size should be >= 1 in internal units
758 m_gridSize.x = std::max( 1.0, m_gridSize.x );
759 m_gridSize.y = std::max( 1.0, m_gridSize.y );
760
761 m_gridOffset = VECTOR2D( (long) m_gridOrigin.x % (long) m_gridSize.x,
762 (long) m_gridOrigin.y % (long) m_gridSize.y );
763 }

References KIGFX::GAL::m_gridOffset, KIGFX::GAL::m_gridOrigin, KIGFX::GAL::m_gridSize, VECTOR2< T >::x, and VECTOR2< T >::y.

Referenced by COMMON_TOOLS::OnGridChanged(), DIALOG_PAD_PROPERTIES::prepareCanvas(), SCH_PREVIEW_PANEL::SCH_PREVIEW_PANEL(), and EDA_DRAW_PANEL_GAL::SwitchBackend().

◆ SetGridVisibility()

void KIGFX::GAL::SetGridVisibility ( bool  aVisibility)
inlineinherited

◆ SetHorizontalJustify()

void KIGFX::GAL::SetHorizontalJustify ( const GR_TEXT_H_ALIGN_T  aHorizontalJustify)
inlineinherited

◆ SetIsFill()

◆ SetIsStroke()

◆ SetLayerDepth()

virtual void KIGFX::GAL::SetLayerDepth ( double  aLayerDepth)
inlinevirtualinherited

Set the depth of the layer (position on the z-axis)

Parameters
aLayerDepththe layer depth for the objects.

Reimplemented in KIGFX::CAIRO_GAL_BASE.

Definition at line 361 of file graphics_abstraction_layer.h.

362 {
363 assert( aLayerDepth <= m_depthRange.y );
364 assert( aLayerDepth >= m_depthRange.x );
365
366 m_layerDepth = aLayerDepth;
367 }

References KIGFX::GAL::m_depthRange, KIGFX::GAL::m_layerDepth, VECTOR2< T >::x, and VECTOR2< T >::y.

Referenced by KIGFX::VIEW::draw(), ROUTER_PREVIEW_ITEM::drawShape(), drawTriangulatedPolyset(), KIGFX::GAL::GAL(), KIGFX::VIEW::redrawRect(), KIGFX::CAIRO_GAL_BASE::SetLayerDepth(), KIGFX::VIEW::updateItemGeometry(), EDIT_POINTS::ViewDraw(), ROUTER_PREVIEW_ITEM::ViewDraw(), and KIGFX::PREVIEW::RULER_ITEM::ViewDraw().

◆ SetLineWidth()

◆ SetLookAtPoint()

void KIGFX::GAL::SetLookAtPoint ( const VECTOR2D aPoint)
inlineinherited

Get/set the Point in world space to look at.

This point corresponds with the center of the actual drawing area.

Definition at line 578 of file graphics_abstraction_layer.h.

578{ m_lookAtPoint = aPoint; }

References KIGFX::GAL::m_lookAtPoint.

Referenced by BOARD_PRINTOUT::DrawPage(), KIGFX::GAL::GAL(), and KIGFX::VIEW::SetCenter().

◆ SetMouseListener()

void KIGFX::OPENGL_GAL::SetMouseListener ( wxEvtHandler *  aMouseListener)
inline

Definition at line 287 of file opengl_gal.h.

288 {
289 m_mouseListener = aMouseListener;
290 }

References m_mouseListener.

◆ SetNativeCursorStyle()

bool OPENGL_GAL::SetNativeCursorStyle ( KICURSOR  aCursor)
overridevirtual

Set the cursor in the native panel.

Parameters
aCursoris the cursor to use in the native panel
Returns
true if the cursor was updated, false if the cursor given was already set

Reimplemented from KIGFX::GAL.

Definition at line 1972 of file opengl_gal.cpp.

1973{
1974 // Store the current cursor type and get the wxCursor for it
1975 if( !GAL::SetNativeCursorStyle( aCursor ) )
1976 return false;
1977
1979
1980 // Update the cursor in the wx control
1981 HIDPI_GL_CANVAS::SetCursor( m_currentwxCursor );
1982
1983 return true;
1984}
static const wxCursor GetCursor(KICURSOR aCursorType)
Definition: cursors.cpp:394
virtual bool SetNativeCursorStyle(KICURSOR aCursor)
Set the cursor in the native panel.
KICURSOR m_currentNativeCursor
Current cursor.

References CURSOR_STORE::GetCursor(), KIGFX::GAL::m_currentNativeCursor, m_currentwxCursor, and KIGFX::GAL::SetNativeCursorStyle().

◆ SetNegativeDrawMode()

void KIGFX::OPENGL_GAL::SetNegativeDrawMode ( bool  aSetting)
inlineoverridevirtual

Set negative draw mode in the renderer.

When negative mode is enabled, drawn items will subtract from previously drawn items. This is mainly needed for Gerber negative item support in Cairo, since unlike in OpenGL, objects drawn with zero opacity on top of other objects would not normally mask objects in Cairo. This method is a no-op in OpenGL.

Parameters
aSettingis true if negative mode should be enabled

Reimplemented from KIGFX::GAL.

Definition at line 259 of file opengl_gal.h.

259{}

◆ SetPaintListener()

void KIGFX::OPENGL_GAL::SetPaintListener ( wxEvtHandler *  aPaintListener)
inline

Definition at line 292 of file opengl_gal.h.

293 {
294 m_paintListener = aPaintListener;
295 }

References m_paintListener.

◆ SetRotation()

void KIGFX::GAL::SetRotation ( double  aRotation)
inlineinherited

Get/set the rotation angle (in radians).

Definition at line 587 of file graphics_abstraction_layer.h.

587{ m_rotation = aRotation; }

References KIGFX::GAL::m_rotation.

Referenced by KIGFX::GAL::GAL().

◆ SetScaleFactor()

void HIDPI_GL_CANVAS::SetScaleFactor ( double  aFactor)
inherited

Set the canvas scale factor, probably for a hi-DPI display.

Definition at line 65 of file hidpi_gl_canvas.cpp.

66{
67 m_scale_factor = aNewScaleFactor;
68}

References HIDPI_GL_CANVAS::m_scale_factor.

Referenced by EDA_3D_MODEL_VIEWER::EDA_3D_MODEL_VIEWER(), EDA_3D_VIEWER_FRAME::loadCommonSettings(), PANEL_PREVIEW_3D_MODEL::loadSettings(), and updatedGalDisplayOptions().

◆ SetScreenDPI()

void KIGFX::GAL::SetScreenDPI ( double  aScreenDPI)
inlineinherited

Set the dots per inch of the screen.

This value depends on the user screen, it should be configurable by the application. For instance a typical notebook with HD+ resolution (1600x900) has 106 DPI.

Definition at line 571 of file graphics_abstraction_layer.h.

571{ m_screenDPI = aScreenDPI; }

References KIGFX::GAL::m_screenDPI.

Referenced by KIGFX::CAIRO_PRINT_GAL::CAIRO_PRINT_GAL(), and KIGFX::GAL::GAL().

◆ SetScreenSize()

void KIGFX::GAL::SetScreenSize ( const VECTOR2I aSize)
inlineinherited

Definition at line 563 of file graphics_abstraction_layer.h.

563{ m_screenSize = aSize; }

References KIGFX::GAL::m_screenSize.

Referenced by KIGFX::CAIRO_PRINT_GAL::SetSheetSize().

◆ SetStrokeColor()

◆ SetTarget()

void OPENGL_GAL::SetTarget ( RENDER_TARGET  aTarget)
overridevirtual

Set the target for rendering.

Parameters
aTargetis the new target for rendering.

Reimplemented from KIGFX::GAL.

Definition at line 1886 of file opengl_gal.cpp.

1887{
1888 switch( aTarget )
1889 {
1890 default:
1895 }
1896
1897 m_currentTarget = aTarget;
1898}

References m_cachedManager, m_currentManager, m_currentTarget, m_nonCachedManager, m_overlayManager, m_tempManager, KIGFX::TARGET_CACHED, KIGFX::TARGET_NONCACHED, KIGFX::TARGET_OVERLAY, and KIGFX::TARGET_TEMP.

Referenced by DrawGrid(), OPENGL_GAL(), and StartDiffLayer().

◆ SetTextMirrored()

void KIGFX::GAL::SetTextMirrored ( const bool  aMirrored)
inlineinherited

◆ SetVerticalJustify()

void KIGFX::GAL::SetVerticalJustify ( const GR_TEXT_V_ALIGN_T  aVerticalJustify)
inlineinherited

Definition at line