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 DrawCircle (const VECTOR2D &aCenterPoint, double aRadius) override
 Draw a circle using world coordinates. More...
 
void DrawArc (const VECTOR2D &aCenterPoint, double aRadius, double aStartAngle, double aEndAngle) override
 Draw an arc. More...
 
void DrawArcSegment (const VECTOR2D &aCenterPoint, double aRadius, double aStartAngle, double 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 VECTOR2D aPointList[], int aListSize) override
 
void DrawPolyline (const SHAPE_LINE_CHAIN &aLineChain) override
 
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
 
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) override
 Draw a bitmap image. More...
 
void BitmapText (const wxString &aText, const VECTOR2D &aPosition, double aRotationAngle) 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
 Parameters passed to the GLU tesselator. More...
 
virtual bool IsCairoEngine ()
 Return true if the GAL engine is a Cairo based type. More...
 
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...
 
const STROKE_FONTGetStrokeFont () const
 
virtual void StrokeText (const wxString &aText, const VECTOR2D &aPosition, double aRotationAngle)
 Draw a vector type text using preloaded Newstroke font. More...
 
VECTOR2D GetTextLineSize (const UTF8 &aText) const
 Compute the X and Y size of a given text. More...
 
virtual void SetTextAttributes (const EDA_TEXT *aText)
 Loads attributes of the given text (bold/italic/underline/mirrored and so on). More...
 
void ResetTextAttributes ()
 Reset text attributes to default styling. More...
 
void SetGlyphSize (const VECTOR2D &aSize)
 Set the font glyph size. More...
 
const VECTOR2DGetGlyphSize () const
 
void SetFontBold (bool aBold)
 Set bold property of current font. More...
 
bool IsFontBold () const
 
void SetFontItalic (bool aItalic)
 Set italic property of current font. More...
 
bool IsFontItalic () const
 
void SetFontUnderlined (bool aUnderlined)
 
bool IsFontUnderlined () const
 
void SetTextMirrored (bool aMirrored)
 Set a mirrored property of text. More...
 
bool IsTextMirrored () const
 
void SetHorizontalJustify (const EDA_TEXT_HJUSTIFY_T aHorizontalJustify)
 Set the horizontal justify for text drawing. More...
 
EDA_TEXT_HJUSTIFY_T GetHorizontalJustify () const
 Return current text horizontal justification setting. More...
 
void SetVerticalJustify (const EDA_TEXT_VJUSTIFY_T aVerticalJustify)
 Set the vertical justify for text drawing. More...
 
EDA_TEXT_VJUSTIFY_T GetVerticalJustify () const
 Returns current text vertical justification setting. More...
 
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)
 Set the Point in world space to look at. More...
 
const VECTOR2DGetLookAtPoint () const
 Get the look at point. More...
 
void SetZoomFactor (double aZoomFactor)
 Set the zoom factor of the scene. More...
 
double GetZoomFactor () const
 Get the zoom factor. More...
 
void SetRotation (double aRotation)
 Set the rotation angle. More...
 
double GetRotation () const
 Get the rotation angle. More...
 
void SetDepthRange (const VECTOR2D &aDepthRange)
 Set the range of the layer depth. More...
 
double GetMinDepth () const
 Return the minimum depth in the currently used range (the top). More...
 
double GetMaxDepth () const
 Return the maximum depth in the currently used range (the bottom). More...
 
double GetWorldScale () const
 Get the world scale. More...
 
void SetFlip (bool xAxis, bool yAxis)
 Sets flipping of the screen. More...
 
bool IsFlippedX () const
 Return true if flip flag for the X axis is set. More...
 
bool IsFlippedY () const
 Return true if flip flag for the Y axis is set. More...
 
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...
 
STROKE_FONT m_strokeFont
 Instance of object that stores information about how to draw texts. 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 lockContext (int aClientCookie) override
 Use GAL_CONTEXT_LOCKER RAII object. More...
 
void unlockContext (int aClientCookie) override
 
void beginUpdate () override
 
void endUpdate () override
 
void beginDrawing () override
 
void endDrawing () override
 
bool updatedGalDisplayOptions (const GAL_DISPLAY_OPTIONS &aOptions) override
 Handle updating display options. More...
 
void drawLineQuad (const VECTOR2D &aStartPoint, const VECTOR2D &aEndPoint)
 Draw a quad for the line. 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)
 Draw a stroked semicircle. More...
 
void drawPolyline (const std::function< VECTOR2D(int)> &aPointGetter, int aPointCount)
 Generic way of drawing a polyline stored in different containers. 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)
 Draw a single character using bitmap font. More...
 
void drawBitmapOverbar (double aLength, double aHeight)
 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...
 
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...
 
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< boost::shared_array< GLdouble > > m_tessIntersects
 

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 70 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 315 of file opengl_gal.h.

◆ super

typedef GAL KIGFX::OPENGL_GAL::super
private

Super class definition.

Definition at line 304 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 197 of file opengl_gal.cpp.

199  :
200  GAL( aDisplayOptions ),
201  HIDPI_GL_CANVAS( aParent, wxID_ANY, (int*) glAttributes, wxDefaultPosition, wxDefaultSize,
202  wxEXPAND, aName ),
203  m_mouseListener( aMouseListener ),
204  m_paintListener( aPaintListener ),
205  m_currentManager( nullptr ),
206  m_cachedManager( nullptr ),
207  m_nonCachedManager( nullptr ),
208  m_overlayManager( nullptr ),
209  m_mainBuffer( 0 ),
210  m_overlayBuffer( 0 ),
211  m_isContextLocked( false ),
212  m_lockClientCookie( 0 )
213 {
214  if( m_glMainContext == nullptr )
215  {
217 
219  }
220  else
221  {
223  }
224 
225  m_shader = new SHADER();
227 
228  m_bitmapCache = std::make_unique<GL_BITMAP_CACHE>();
229 
232 
233  // Initialize the flags
236  m_isInitialized = false;
237  m_isGrouping = false;
238  m_groupCounter = 0;
239 
240  // Connect the native cursor handler
241  Connect( wxEVT_SET_CURSOR, wxSetCursorEventHandler( OPENGL_GAL::onSetNativeCursor ), nullptr,
242  this );
243 
244  // Connecting the event handlers
245  Connect( wxEVT_PAINT, wxPaintEventHandler( OPENGL_GAL::onPaint ) );
246 
247  // Mouse events are skipped to the parent
248  Connect( wxEVT_MOTION, wxMouseEventHandler( OPENGL_GAL::skipMouseEvent ) );
249  Connect( wxEVT_LEFT_DOWN, wxMouseEventHandler( OPENGL_GAL::skipMouseEvent ) );
250  Connect( wxEVT_LEFT_UP, wxMouseEventHandler( OPENGL_GAL::skipMouseEvent ) );
251  Connect( wxEVT_LEFT_DCLICK, wxMouseEventHandler( OPENGL_GAL::skipMouseEvent ) );
252  Connect( wxEVT_MIDDLE_DOWN, wxMouseEventHandler( OPENGL_GAL::skipMouseEvent ) );
253  Connect( wxEVT_MIDDLE_UP, wxMouseEventHandler( OPENGL_GAL::skipMouseEvent ) );
254  Connect( wxEVT_MIDDLE_DCLICK, wxMouseEventHandler( OPENGL_GAL::skipMouseEvent ) );
255  Connect( wxEVT_RIGHT_DOWN, wxMouseEventHandler( OPENGL_GAL::skipMouseEvent ) );
256  Connect( wxEVT_RIGHT_UP, wxMouseEventHandler( OPENGL_GAL::skipMouseEvent ) );
257  Connect( wxEVT_RIGHT_DCLICK, wxMouseEventHandler( OPENGL_GAL::skipMouseEvent ) );
258  Connect( wxEVT_MOUSEWHEEL, wxMouseEventHandler( OPENGL_GAL::skipMouseEvent ) );
259 #if wxCHECK_VERSION( 3, 1, 0 ) || defined( USE_OSX_MAGNIFY_EVENT )
260  Connect( wxEVT_MAGNIFY, wxMouseEventHandler( OPENGL_GAL::skipMouseEvent ) );
261 #endif
262 #if defined _WIN32 || defined _WIN64
263  Connect( wxEVT_ENTER_WINDOW, wxMouseEventHandler( OPENGL_GAL::skipMouseEvent ) );
264 #endif
265 
266  SetSize( aParent->GetClientSize() );
268 
269  // Grid color settings are different in Cairo and OpenGL
270  SetGridColor( COLOR4D( 0.8, 0.8, 0.8, 0.1 ) );
271  SetAxesColor( COLOR4D( BLUE ) );
272 
273  // Tesselator initialization
274  m_tesselator = gluNewTess();
276 
277  gluTessProperty( m_tesselator, GLU_TESS_WINDING_RULE, GLU_TESS_WINDING_POSITIVE );
278 
280 
281  // Avoid uninitialized variables:
282  ufm_worldPixelSize = 1;
286 }
virtual wxSize GetNativePixelSize() const
void onSetNativeCursor(wxSetCursorEvent &aEvent)
Give the correct cursor image when the native widget asks for it.
unsigned int m_overlayBuffer
Auxiliary rendering target (for menus etc.)
Definition: opengl_gal.h:328
wxEvtHandler * m_paintListener
Definition: opengl_gal.h:310
static int m_instanceCounter
GL GAL instance counter.
Definition: opengl_gal.h:308
VERTEX_MANAGER * m_overlayManager
Container for storing overlaid VERTEX_ITEMs.
Definition: opengl_gal.h:323
static void InitTesselatorCallbacks(GLUtesselator *aTesselator)
unsigned int m_mainBuffer
Main rendering target.
Definition: opengl_gal.h:327
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)
VECTOR2< int > VECTOR2I
Definition: vector2d.h:623
OPENGL_ANTIALIASING_MODE gl_antialiasing_mode
VERTEX_MANAGER * m_cachedManager
Container for storing cached VERTEX_ITEMs.
Definition: opengl_gal.h:321
Auxiliary rendering target (noncached)
Definition: definitions.h:49
void SetAntialiasingMode(OPENGL_ANTIALIASING_MODE aMode)
wxEvtHandler * m_mouseListener
Definition: opengl_gal.h:309
static GL_CONTEXT_MANAGER & Get()
Return the GL_CONTEXT_MANAGER instance (singleton).
GAL_DISPLAY_OPTIONS & m_options
GAL(GAL_DISPLAY_OPTIONS &aOptions)
void SetGridColor(const COLOR4D &aGridColor)
Set the grid color.
VERTEX_MANAGER * m_currentManager
Currently used VERTEX_MANAGER (for storing VERTEX_ITEMs).
Definition: opengl_gal.h:319
static wxGLContext * m_glMainContext
Parent OpenGL context.
Definition: opengl_gal.h:306
SHADER * m_shader
There is only one shader used for different objects.
Definition: opengl_gal.h:332
bool m_isInitialized
Basic initialization flag, has to be done when the window is visible.
Definition: opengl_gal.h:339
void SetAxesColor(const COLOR4D &aAxesColor)
Set the axes color.
OPENGL_COMPOSITOR * m_compositor
Handles multiple rendering targets.
Definition: opengl_gal.h:326
static const int glAttributes[]
Definition: opengl_gal.cpp:81
GLUtesselator * m_tesselator
Definition: opengl_gal.h:354
GLint ufm_antialiasingOffset
Definition: opengl_gal.h:347
void onPaint(wxPaintEvent &aEvent)
This is the OnPaint event handler.
GLint ufm_screenPixelSize
Definition: opengl_gal.h:345
wxGLContext * CreateCtx(wxGLCanvas *aCanvas, const wxGLContext *aOther=nullptr)
Create a managed OpenGL context.
Provide the access to the OpenGL shaders.
Definition: shader.h:76
bool m_isContextLocked
Used for assertion checking.
Definition: opengl_gal.h:342
GLint ufm_worldPixelSize
Definition: opengl_gal.h:344
void SetTarget(RENDER_TARGET aTarget) override
Set the target for rendering.
wxGLContext * m_glPrivContext
Canvas-specific OpenGL context.
Definition: opengl_gal.h:307
Definition: color4d.h:56
bool m_isFramebufferInitialized
Are the framebuffers initialized?
Definition: opengl_gal.h:336
std::unique_ptr< GL_BITMAP_CACHE > m_bitmapCache
Definition: opengl_gal.h:351
unsigned int m_groupCounter
Counter used for generating keys for groups.
Definition: opengl_gal.h:318
bool m_isBitmapFontInitialized
Is the shader set to use bitmap fonts?
Definition: opengl_gal.h:338
VERTEX_MANAGER * m_nonCachedManager
Container for storing non-cached VERTEX_ITEMs.
Definition: opengl_gal.h:322
VECTOR2I m_screenSize
Screen size in screen coordinates.
GLint ufm_pixelSizeMultiplier
Definition: opengl_gal.h:346
void skipMouseEvent(wxMouseEvent &aEvent)
Skip the mouse event to the parent.
bool m_isGrouping
Was a group started?
Definition: opengl_gal.h:341
A color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:103

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 289 of file opengl_gal.cpp.

290 {
292 
294  glFlush();
295  gluDeleteTess( m_tesselator );
296  ClearCache();
297 
298  delete m_compositor;
299 
300  if( m_isInitialized )
301  {
302  delete m_cachedManager;
303  delete m_nonCachedManager;
304  delete m_overlayManager;
305  }
306 
308 
309  // If it was the main context, then it will be deleted
310  // when the last OpenGL GAL instance is destroyed (a few lines below)
313 
314  delete m_shader;
315 
316  // Are we destroying the last GAL instance?
317  if( m_instanceCounter == 0 )
318  {
320 
322  {
323  glDeleteTextures( 1, &g_fontTexture );
324  m_isBitmapFontLoaded = false;
325  }
326 
329  m_glMainContext = nullptr;
330  }
331 }
static bool m_isBitmapFontLoaded
Is the bitmap font texture loaded?
Definition: opengl_gal.h:337
static int m_instanceCounter
GL GAL instance counter.
Definition: opengl_gal.h:308
VERTEX_MANAGER * m_overlayManager
Container for storing overlaid VERTEX_ITEMs.
Definition: opengl_gal.h:323
VERTEX_MANAGER * m_cachedManager
Container for storing cached VERTEX_ITEMs.
Definition: opengl_gal.h:321
void UnlockCtx(wxGLContext *aContext)
Allow other canvases to bind an OpenGL context.
static GL_CONTEXT_MANAGER & Get()
Return the GL_CONTEXT_MANAGER instance (singleton).
static wxGLContext * m_glMainContext
Parent OpenGL context.
Definition: opengl_gal.h:306
SHADER * m_shader
There is only one shader used for different objects.
Definition: opengl_gal.h:332
bool m_isInitialized
Basic initialization flag, has to be done when the window is visible.
Definition: opengl_gal.h:339
OPENGL_COMPOSITOR * m_compositor
Handles multiple rendering targets.
Definition: opengl_gal.h:326
GLUtesselator * m_tesselator
Definition: opengl_gal.h:354
void ClearCache() override
Delete all data created during caching of graphic items.
void LockCtx(wxGLContext *aContext, wxGLCanvas *aCanvas)
Set a context as current and prevents other canvases from switching it.
static GLuint g_fontTexture
Bitmap font texture handle (shared)
Definition: opengl_gal.h:312
wxGLContext * m_glPrivContext
Canvas-specific OpenGL context.
Definition: opengl_gal.h:307
void DestroyCtx(wxGLContext *aContext)
Destroy a managed OpenGL context.
VERTEX_MANAGER * m_nonCachedManager
Container for storing non-cached VERTEX_ITEMs.
Definition: opengl_gal.h:322

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_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 1056 of file graphics_abstraction_layer.h.

1057  {
1058  m_layerDepth -= 0.05;
1059  }
double m_layerDepth
The actual layer depth.

References KIGFX::GAL::m_layerDepth.

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

◆ beginDrawing()

void OPENGL_GAL::beginDrawing ( )
overrideprivatevirtual

Reimplemented from KIGFX::GAL.

Definition at line 418 of file opengl_gal.cpp.

419 {
420 #ifdef KICAD_GAL_PROFILE
421  PROF_COUNTER totalRealTime( "OPENGL_GAL::beginDrawing()", true );
422 #endif /* KICAD_GAL_PROFILE */
423 
424  wxASSERT_MSG( m_isContextLocked, "GAL_DRAWING_CONTEXT RAII object should have locked context. "
425  "Calling GAL::beginDrawing() directly is not allowed." );
426 
427  wxASSERT_MSG( IsVisible(), "GAL::beginDrawing() must not be entered when GAL is not visible. "
428  "Other drawing routines will expect everything to be initialized "
429  "which will not be the case." );
430 
431  if( !m_isInitialized )
432  init();
433 
434  // Set up the view port
435  glMatrixMode( GL_PROJECTION );
436  glLoadIdentity();
437 
438  // Create the screen transformation (Do the RH-LH conversion here)
439  glOrtho( 0, (GLint) m_screenSize.x, (GLsizei) m_screenSize.y, 0,
441 
443  {
444  // Prepare rendering target buffers
447  try
448  {
450  }
451  catch( const std::runtime_error& )
452  {
453  wxLogVerbose( "Could not create a framebuffer for overlays.\n" );
454  m_overlayBuffer = 0;
455  }
456 
458  }
459 
460  m_compositor->Begin();
461 
462  // Disable 2D Textures
463  glDisable( GL_TEXTURE_2D );
464 
465  glShadeModel( GL_FLAT );
466 
467  // Enable the depth buffer
468  glEnable( GL_DEPTH_TEST );
469  glDepthFunc( GL_LESS );
470 
471  // Setup blending, required for transparent objects
472  glEnable( GL_BLEND );
473  glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );
474 
475  glMatrixMode( GL_MODELVIEW );
476 
477  // Set up the world <-> screen transformation
479  GLdouble matrixData[16] = { 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1 };
480  matrixData[0] = m_worldScreenMatrix.m_data[0][0];
481  matrixData[1] = m_worldScreenMatrix.m_data[1][0];
482  matrixData[2] = m_worldScreenMatrix.m_data[2][0];
483  matrixData[4] = m_worldScreenMatrix.m_data[0][1];
484  matrixData[5] = m_worldScreenMatrix.m_data[1][1];
485  matrixData[6] = m_worldScreenMatrix.m_data[2][1];
486  matrixData[12] = m_worldScreenMatrix.m_data[0][2];
487  matrixData[13] = m_worldScreenMatrix.m_data[1][2];
488  matrixData[14] = m_worldScreenMatrix.m_data[2][2];
489  glLoadMatrixd( matrixData );
490 
491  // Set defaults
494 
495  // Remove all previously stored items
498 
502 
504  {
505  // Keep bitmap font texture always bound to the second texturing unit
506  const GLint FONT_TEXTURE_UNIT = 2;
507 
508  // Either load the font atlas to video memory, or simply bind it to a texture unit
509  if( !m_isBitmapFontLoaded )
510  {
511  glActiveTexture( GL_TEXTURE0 + FONT_TEXTURE_UNIT );
512  glGenTextures( 1, &g_fontTexture );
513  glBindTexture( GL_TEXTURE_2D, g_fontTexture );
514  glTexImage2D( GL_TEXTURE_2D, 0, GL_RGB8, font_image.width, font_image.height, 0, GL_RGB,
515  GL_UNSIGNED_BYTE, font_image.pixels );
516  glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
517  glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
518  checkGlError( "loading bitmap font", __FILE__, __LINE__ );
519 
520  glActiveTexture( GL_TEXTURE0 );
521 
522  m_isBitmapFontLoaded = true;
523  }
524  else
525  {
526  glActiveTexture( GL_TEXTURE0 + FONT_TEXTURE_UNIT );
527  glBindTexture( GL_TEXTURE_2D, g_fontTexture );
528  glActiveTexture( GL_TEXTURE0 );
529  }
530 
531  // Set shader parameter
532  GLint ufm_fontTexture = m_shader->AddParameter( "fontTexture" );
533  GLint ufm_fontTextureWidth = m_shader->AddParameter( "fontTextureWidth" );
534  ufm_worldPixelSize = m_shader->AddParameter( "worldPixelSize" );
535  ufm_screenPixelSize = m_shader->AddParameter( "screenPixelSize" );
536  ufm_pixelSizeMultiplier = m_shader->AddParameter( "pixelSizeMultiplier" );
537  ufm_antialiasingOffset = m_shader->AddParameter( "antialiasingOffset" );
538 
539  m_shader->Use();
540  m_shader->SetParameter( ufm_fontTexture, (int) FONT_TEXTURE_UNIT );
541  m_shader->SetParameter( ufm_fontTextureWidth, (int) font_image.width );
542  m_shader->Deactivate();
543  checkGlError( "setting bitmap font sampler as shader parameter", __FILE__, __LINE__ );
544 
546  }
547 
548  m_shader->Use();
550  (float) ( getWorldPixelSize() / GetScaleFactor() ) );
551  const VECTOR2D& screenPixelSize = getScreenPixelSize();
552  m_shader->SetParameter( ufm_screenPixelSize, screenPixelSize );
553  double pixelSizeMultiplier = m_compositor->GetAntialiasSupersamplingFactor();
554  m_shader->SetParameter( ufm_pixelSizeMultiplier, (float) pixelSizeMultiplier );
556  renderingOffset.x *= screenPixelSize.x;
557  renderingOffset.y *= screenPixelSize.y;
558  m_shader->SetParameter( ufm_antialiasingOffset, renderingOffset );
559  m_shader->Deactivate();
560 
561  // Something betreen BeginDrawing and EndDrawing seems to depend on
562  // this texture unit being active, but it does not assure it itself.
563  glActiveTexture( GL_TEXTURE0 );
564 
565  // Unbind buffers - set compositor for direct drawing
567 
568 #ifdef KICAD_GAL_PROFILE
569  totalRealTime.Stop();
570  wxLogTrace( traceGalProfile, wxT( "OPENGL_GAL::beginDrawing(): %.1f ms" ),
571  totalRealTime.msecs() );
572 #endif /* KICAD_GAL_PROFILE */
573 }
virtual void SetFillColor(const COLOR4D &aColor)
Set the fill color.
unsigned int m_overlayBuffer
Auxiliary rendering target (for menus etc.)
Definition: opengl_gal.h:328
static bool m_isBitmapFontLoaded
Is the bitmap font texture loaded?
Definition: opengl_gal.h:337
int GetAntialiasSupersamplingFactor() const
virtual void Begin() override
Call this at the beginning of each frame.
void BeginDrawing() const
Prepare buffers and items to start drawing.
void Use()
Use the shader.
Definition: shader.h:126
VERTEX_MANAGER * m_overlayManager
Container for storing overlaid VERTEX_ITEMs.
Definition: opengl_gal.h:323
VECTOR2D getScreenPixelSize() const
Definition: opengl_gal.cpp:410
void ComputeWorldScreenMatrix() override
Compute the world <-> screen transformation matrix.
void SetParameter(int aParameterNumber, float aValue) const
Set a parameter of the shader.
Definition: shader.cpp:143
double GetScaleFactor() const
Get the current scale factor.
const wxChar *const traceGalProfile
Flag to enable debug output of GAL performance profiling.
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
unsigned int m_mainBuffer
Main rendering target.
Definition: opengl_gal.h:327
static const unsigned int DIRECT_RENDERING
A small class to help profiling.
Definition: profile.h:45
VERTEX_MANAGER * m_cachedManager
Container for storing cached VERTEX_ITEMs.
Definition: opengl_gal.h:321
MATRIX3x3D m_worldScreenMatrix
World transformation.
T m_data[3][3]
Definition: matrix3x3.h:64
double getWorldPixelSize() const
Definition: opengl_gal.cpp:403
void init()
Basic OpenGL initialization and feature checks.
COLOR4D m_strokeColor
The color of the outlines.
SHADER * m_shader
There is only one shader used for different objects.
Definition: opengl_gal.h:332
bool m_isInitialized
Basic initialization flag, has to be done when the window is visible.
Definition: opengl_gal.h:339
OPENGL_COMPOSITOR * m_compositor
Handles multiple rendering targets.
Definition: opengl_gal.h:326
GLint ufm_antialiasingOffset
Definition: opengl_gal.h:347
int AddParameter(const std::string &aParameterName)
Add a parameter to the parameter queue.
Definition: shader.cpp:130
GLint ufm_screenPixelSize
Definition: opengl_gal.h:345
void Deactivate()
Deactivate the shader and use the default OpenGL program.
Definition: shader.h:135
FONT_IMAGE_TYPE font_image
Definition: gl_resources.cpp:4
unsigned char pixels[1024 *1024 *3]
Definition: gl_resources.h:38
virtual void SetBuffer(unsigned int aBufferHandle) override
Set the selected buffer as the rendering target.
bool m_isContextLocked
Used for assertion checking.
Definition: opengl_gal.h:342
virtual void Initialize() override
Perform primary initialization, necessary to use the object.
static GLuint g_fontTexture
Bitmap font texture handle (shared)
Definition: opengl_gal.h:312
GLint ufm_worldPixelSize
Definition: opengl_gal.h:344
virtual void SetStrokeColor(const COLOR4D &aColor)
Set the stroke color.
COLOR4D m_fillColor
The fill color.
VECTOR2D m_depthRange
Range of the depth.
bool m_isFramebufferInitialized
Are the framebuffers initialized?
Definition: opengl_gal.h:336
virtual unsigned int CreateBuffer() override
Prepare a new buffer that may be used as a rendering target.
bool m_isBitmapFontInitialized
Is the shader set to use bitmap fonts?
Definition: opengl_gal.h:338
VERTEX_MANAGER * m_nonCachedManager
Container for storing non-cached VERTEX_ITEMs.
Definition: opengl_gal.h:322
bool IsVisible() const override
Return true if the GAL canvas is visible on the screen.
Definition: opengl_gal.h:110
VECTOR2I m_screenSize
Screen size in screen coordinates.
GLint ufm_pixelSizeMultiplier
Definition: opengl_gal.h:346
void Clear() const
Remove all the stored vertices from the container.
VECTOR2D GetAntialiasRenderingOffset() const

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, KIGFX::GAL::m_worldScreenMatrix, PROF_COUNTER::msecs(), KIGFX::BUILTIN_FONT::FONT_IMAGE_TYPE::pixels, KIGFX::OPENGL_COMPOSITOR::SetBuffer(), KIGFX::GAL::SetFillColor(), KIGFX::SHADER::SetParameter(), KIGFX::GAL::SetStrokeColor(), PROF_COUNTER::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 1621 of file opengl_gal.cpp.

1622 {
1623  m_isGrouping = true;
1624 
1625  std::shared_ptr<VERTEX_ITEM> newItem = std::make_shared<VERTEX_ITEM>( *m_cachedManager );
1626  int groupNumber = getNewGroupNumber();
1627  m_groups.insert( std::make_pair( groupNumber, newItem ) );
1628 
1629  return groupNumber;
1630 }
GROUPS_MAP m_groups
Stores information about VBO objects (groups)
Definition: opengl_gal.h:317
VERTEX_MANAGER * m_cachedManager
Container for storing cached VERTEX_ITEMs.
Definition: opengl_gal.h:321
unsigned int getNewGroupNumber()
Return a valid key that can be used as a new group number.
bool m_isGrouping
Was a group started?
Definition: opengl_gal.h:341

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

◆ beginUpdate()

void OPENGL_GAL::beginUpdate ( )
overrideprivatevirtual

Reimplemented from KIGFX::GAL.

Definition at line 641 of file opengl_gal.cpp.

642 {
643  wxASSERT_MSG( m_isContextLocked, "GAL_UPDATE_CONTEXT RAII object should have locked context. "
644  "Calling this from anywhere else is not allowed." );
645 
646  wxASSERT_MSG( IsVisible(), "GAL::beginUpdate() must not be entered when GAL is not visible. "
647  "Other update routines will expect everything to be initialized "
648  "which will not be the case." );
649 
650  if( !m_isInitialized )
651  init();
652 
653  m_cachedManager->Map();
654 }
VERTEX_MANAGER * m_cachedManager
Container for storing cached VERTEX_ITEMs.
Definition: opengl_gal.h:321
void init()
Basic OpenGL initialization and feature checks.
bool m_isInitialized
Basic initialization flag, has to be done when the window is visible.
Definition: opengl_gal.h:339
void Map()
Map vertex buffer.
bool m_isContextLocked
Used for assertion checking.
Definition: opengl_gal.h:342
bool IsVisible() const override
Return true if the GAL canvas is visible on the screen.
Definition: opengl_gal.h:110

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

◆ BitmapText()

void OPENGL_GAL::BitmapText ( const wxString &  aText,
const VECTOR2D aPosition,
double  aRotationAngle 
)
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.
aRotationAngleis the text rotation angle.

Reimplemented from KIGFX::GAL.

Definition at line 1257 of file opengl_gal.cpp.

1259 {
1260  // Fallback to generic impl (which uses the stroke font) on cases we don't handle
1261  if( IsTextMirrored() || aText.Contains( wxT( "^{" ) ) || aText.Contains( wxT( "_{" ) ) )
1262  return GAL::BitmapText( aText, aPosition, aRotationAngle );
1263 
1264  const UTF8 text( aText );
1265  VECTOR2D textSize;
1266  float commonOffset;
1267  std::tie( textSize, commonOffset ) = computeBitmapTextSize( text );
1268 
1269  const double SCALE = 1.4 * GetGlyphSize().y / textSize.y;
1270  int overbarLength = 0;
1271  double overbarHeight = textSize.y;
1272 
1273  Save();
1274 
1276  m_currentManager->Translate( aPosition.x, aPosition.y, m_layerDepth );
1277  m_currentManager->Rotate( aRotationAngle, 0.0f, 0.0f, -1.0f );
1278 
1279  double sx = SCALE * ( m_globalFlipX ? -1.0 : 1.0 );
1280  double sy = SCALE * ( m_globalFlipY ? -1.0 : 1.0 );
1281 
1282  m_currentManager->Scale( sx, sy, 0 );
1283  m_currentManager->Translate( 0, -commonOffset, 0 );
1284 
1285  switch( GetHorizontalJustify() )
1286  {
1288  Translate( VECTOR2D( -textSize.x / 2.0, 0 ) );
1289  break;
1290 
1292  //if( !IsTextMirrored() )
1293  Translate( VECTOR2D( -textSize.x, 0 ) );
1294  break;
1295 
1296  case GR_TEXT_HJUSTIFY_LEFT:
1297  //if( IsTextMirrored() )
1298  //Translate( VECTOR2D( -textSize.x, 0 ) );
1299  break;
1300  }
1301 
1302  switch( GetVerticalJustify() )
1303  {
1304  case GR_TEXT_VJUSTIFY_TOP:
1305  Translate( VECTOR2D( 0, -textSize.y ) );
1306  overbarHeight = -textSize.y / 2.0;
1307  break;
1308 
1310  Translate( VECTOR2D( 0, -textSize.y / 2.0 ) );
1311  overbarHeight = 0;
1312  break;
1313 
1315  break;
1316  }
1317 
1318  int overbarDepth = -1;
1319  int braceNesting = 0;
1320 
1321  for( UTF8::uni_iter chIt = text.ubegin(), end = text.uend(); chIt < end; ++chIt )
1322  {
1323  wxASSERT_MSG( *chIt != '\n' && *chIt != '\r',
1324  wxT( "No support for multiline bitmap text yet" ) );
1325 
1326  if( *chIt == '~' && overbarDepth == -1 )
1327  {
1328  UTF8::uni_iter lookahead = chIt;
1329 
1330  if( ++lookahead != end && *lookahead == '{' )
1331  {
1332  chIt = lookahead;
1333  overbarDepth = braceNesting;
1334  braceNesting++;
1335  continue;
1336  }
1337  }
1338  else if( *chIt == '{' )
1339  {
1340  braceNesting++;
1341  }
1342  else if( *chIt == '}' )
1343  {
1344  if( braceNesting > 0 )
1345  braceNesting--;
1346 
1347  if( braceNesting == overbarDepth )
1348  {
1349  drawBitmapOverbar( overbarLength, overbarHeight );
1350  overbarLength = 0;
1351 
1352  overbarDepth = -1;
1353  continue;
1354  }
1355  }
1356 
1357  if( overbarDepth != -1 )
1358  overbarLength += drawBitmapChar( *chIt );
1359  else
1360  drawBitmapChar( *chIt );
1361  }
1362 
1363  // Handle the case when overbar is active till the end of the drawn text
1364  m_currentManager->Translate( 0, commonOffset, 0 );
1365 
1366  if( overbarDepth != -1 && overbarLength > 0 )
1367  drawBitmapOverbar( overbarLength, overbarHeight );
1368 
1369  Restore();
1370 }
An 8 bit string that is assuredly encoded in UTF8, and supplies special conversion support to and fro...
Definition: utf8.h:70
virtual void BitmapText(const wxString &aText, const VECTOR2D &aPosition, double aRotationAngle)
Draw a text using a bitmap font.
bool IsTextMirrored() const
void Translate(const VECTOR2D &aTranslation) override
Translate the context.
void Restore() override
Restore the context.
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 ...
double g
Green component.
Definition: color4d.h:378
EDA_TEXT_HJUSTIFY_T GetHorizontalJustify() const
Return current text horizontal justification setting.
double b
Blue component.
Definition: color4d.h:379
double m_layerDepth
The actual layer depth.
const VECTOR2D & GetGlyphSize() const
void Save() override
Save the context.
bool m_globalFlipX
Flag for X axis flipping.
VERTEX_MANAGER * m_currentManager
Currently used VERTEX_MANAGER (for storing VERTEX_ITEMs).
Definition: opengl_gal.h:319
double a
Alpha component.
Definition: color4d.h:380
COLOR4D m_strokeColor
The color of the outlines.
VECTOR2< double > VECTOR2D
Definition: vector2d.h:622
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...
void Color(const COLOR4D &aColor)
Changes currently used color that will be applied to newly added vertices.
uni_iter is a non-mutating iterator that walks through unicode code points in the UTF8 encoded string...
Definition: utf8.h:203
bool m_globalFlipY
Flag for Y axis flipping.
EDA_TEXT_VJUSTIFY_T GetVerticalJustify() const
Returns current text vertical justification setting.
int drawBitmapChar(unsigned long aChar)
Draw a single character using bitmap font.
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...
double r
Red component.
Definition: color4d.h:377
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)
Draw an overbar over the currently drawn text.

References KIGFX::COLOR4D::a, 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_HJUSTIFY_CENTER, GR_TEXT_HJUSTIFY_LEFT, GR_TEXT_HJUSTIFY_RIGHT, GR_TEXT_VJUSTIFY_BOTTOM, GR_TEXT_VJUSTIFY_CENTER, GR_TEXT_VJUSTIFY_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, 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 2157 of file opengl_gal.cpp.

2158 {
2159  if( !IsCursorEnabled() )
2160  return;
2161 
2163 
2164  const int cursorSize = m_fullscreenCursor ? 8000 : 80;
2165 
2166  VECTOR2D cursorBegin = m_cursorPosition - cursorSize / ( 2 * m_worldScale );
2167  VECTOR2D cursorEnd = m_cursorPosition + cursorSize / ( 2 * m_worldScale );
2168  VECTOR2D cursorCenter = ( cursorBegin + cursorEnd ) / 2;
2169 
2170  const COLOR4D cColor = getCursorColor();
2171  const COLOR4D color( cColor.r * cColor.a, cColor.g * cColor.a, cColor.b * cColor.a, 1.0 );
2172 
2173  glActiveTexture( GL_TEXTURE0 );
2174  glDisable( GL_TEXTURE_2D );
2175  glLineWidth( 1.0 );
2176  glColor4d( color.r, color.g, color.b, color.a );
2177 
2178  glBegin( GL_LINES );
2179  glVertex2d( cursorCenter.x, cursorBegin.y );
2180  glVertex2d( cursorCenter.x, cursorEnd.y );
2181 
2182  glVertex2d( cursorBegin.x, cursorCenter.y );
2183  glVertex2d( cursorEnd.x, cursorCenter.y );
2184  glEnd();
2185 }
int color
Definition: DXF_plotter.cpp:57
double g
Green component.
Definition: color4d.h:378
static const unsigned int DIRECT_RENDERING
double b
Blue component.
Definition: color4d.h:379
double m_worldScale
The scale factor world->screen.
VECTOR2D m_cursorPosition
Current cursor position (world coordinates)
double a
Alpha component.
Definition: color4d.h:380
OPENGL_COMPOSITOR * m_compositor
Handles multiple rendering targets.
Definition: opengl_gal.h:326
virtual void SetBuffer(unsigned int aBufferHandle) override
Set the selected buffer as the rendering target.
COLOR4D getCursorColor() const
Get the actual cursor color to draw.
bool m_fullscreenCursor
Shape of the cursor (fullscreen or small cross)
double r
Red component.
Definition: color4d.h:377
bool IsCursorEnabled() const
Return information about cursor visibility.
A color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:103

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 511 of file opengl_gal.h.

512  {
513  // Bigger arcs need smaller alpha increment to make them look smooth
514  return std::min( 1e6 / aRadius, 2.0 * M_PI / SEG_PER_CIRCLE_COUNT );
515  }
#define SEG_PER_CIRCLE_COUNT
Definition: opengl_gal.h:53

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 1649 of file opengl_gal.cpp.

1650 {
1651  auto group = m_groups.find( aGroupNumber );
1652 
1653  if( group != m_groups.end() )
1654  m_cachedManager->ChangeItemColor( *group->second, aNewColor );
1655 }
GROUPS_MAP m_groups
Stores information about VBO objects (groups)
Definition: opengl_gal.h:317
VERTEX_MANAGER * m_cachedManager
Container for storing cached VERTEX_ITEMs.
Definition: opengl_gal.h:321
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 1658 of file opengl_gal.cpp.

1659 {
1660  auto group = m_groups.find( aGroupNumber );
1661 
1662  if( group != m_groups.end() )
1663  m_cachedManager->ChangeItemDepth( *group->second, aDepth );
1664 }
GROUPS_MAP m_groups
Stores information about VBO objects (groups)
Definition: opengl_gal.h:317
VERTEX_MANAGER * m_cachedManager
Container for storing cached VERTEX_ITEMs.
Definition: opengl_gal.h:321
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 334 of file opengl_gal.cpp.

335 {
336  wxString retVal = wxEmptyString;
337 
338  wxFrame* testFrame = new wxFrame( nullptr, wxID_ANY, wxT( "" ), wxDefaultPosition,
339  wxSize( 1, 1 ), wxFRAME_TOOL_WINDOW | wxNO_BORDER );
340 
341  KIGFX::OPENGL_GAL* opengl_gal = nullptr;
342 
343  try
344  {
345  opengl_gal = new KIGFX::OPENGL_GAL( aOptions, testFrame );
346 
347  testFrame->Raise();
348  testFrame->Show();
349 
350  GAL_CONTEXT_LOCKER lock( opengl_gal );
351  opengl_gal->init();
352  }
353  catch( std::runtime_error& err )
354  {
355  //Test failed
356  retVal = wxString( err.what() );
357  }
358 
359  delete opengl_gal;
360  delete testFrame;
361 
362  return retVal;
363 }
OpenGL implementation of the Graphics Abstraction Layer.
Definition: opengl_gal.h:70
void init()
Basic OpenGL initialization and feature checks.

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 1674 of file opengl_gal.cpp.

1675 {
1676  m_bitmapCache = std::make_unique<GL_BITMAP_CACHE>();
1677 
1678  m_groups.clear();
1679 
1680  if( m_isInitialized )
1682 }
GROUPS_MAP m_groups
Stores information about VBO objects (groups)
Definition: opengl_gal.h:317
VERTEX_MANAGER * m_cachedManager
Container for storing cached VERTEX_ITEMs.
Definition: opengl_gal.h:321
bool m_isInitialized
Basic initialization flag, has to be done when the window is visible.
Definition: opengl_gal.h:339
std::unique_ptr< GL_BITMAP_CACHE > m_bitmapCache
Definition: opengl_gal.h:351
void Clear() const
Remove all the stored vertices from the container.

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 1562 of file opengl_gal.cpp.

1563 {
1564  // Clear screen
1566 
1567  // NOTE: Black used here instead of m_clearColor; it will be composited later
1568  glClearColor( 0, 0, 0, 1 );
1569  glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT );
1570 }
static const unsigned int DIRECT_RENDERING
OPENGL_COMPOSITOR * m_compositor
Handles multiple rendering targets.
Definition: opengl_gal.h:326
virtual void SetBuffer(unsigned int aBufferHandle) override
Set the selected buffer as the rendering target.

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 1705 of file opengl_gal.cpp.

1706 {
1707  // Save the current state
1708  unsigned int oldTarget = m_compositor->GetBuffer();
1709 
1710  switch( aTarget )
1711  {
1712  // Cached and noncached items are rendered to the same buffer
1713  default:
1714  case TARGET_CACHED:
1715  case TARGET_NONCACHED:
1717  break;
1718 
1719  case TARGET_OVERLAY:
1720  if( m_overlayBuffer )
1722  break;
1723  }
1724 
1725  if( aTarget != TARGET_OVERLAY )
1727  else if( m_overlayBuffer )
1729 
1730  // Restore the previous state
1731  m_compositor->SetBuffer( oldTarget );
1732 }
unsigned int m_overlayBuffer
Auxiliary rendering target (for menus etc.)
Definition: opengl_gal.h:328
static const COLOR4D BLACK
Definition: color4d.h:387
unsigned int m_mainBuffer
Main rendering target.
Definition: opengl_gal.h:327
Auxiliary rendering target (noncached)
Definition: definitions.h:49
virtual void ClearBuffer(const COLOR4D &aColor) override
Clear the selected buffer (set by the SetBuffer() function).
OPENGL_COMPOSITOR * m_compositor
Handles multiple rendering targets.
Definition: opengl_gal.h:326
Items that may change while the view stays the same (noncached)
Definition: definitions.h:50
virtual void SetBuffer(unsigned int aBufferHandle) override
Set the selected buffer as the rendering target.
Main rendering target (cached)
Definition: definitions.h:48
virtual unsigned int GetBuffer() const override
Return currently used buffer handle.

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

◆ 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 2083 of file opengl_gal.cpp.

2084 {
2085  static const FONT_GLYPH_TYPE* defaultGlyph = LookupGlyph( '(' ); // for strange chars
2086 
2087  VECTOR2D textSize( 0, 0 );
2088  float commonOffset = std::numeric_limits<float>::max();
2089  float charHeight = font_information.max_y - defaultGlyph->miny;
2090  int overbarDepth = -1;
2091  int braceNesting = 0;
2092 
2093  for( UTF8::uni_iter chIt = aText.ubegin(), end = aText.uend(); chIt < end; ++chIt )
2094  {
2095  if( *chIt == '~' && overbarDepth == -1 )
2096  {
2097  UTF8::uni_iter lookahead = chIt;
2098 
2099  if( ++lookahead != end && *lookahead == '{' )
2100  {
2101  chIt = lookahead;
2102  overbarDepth = braceNesting;
2103  braceNesting++;
2104  continue;
2105  }
2106  }
2107  else if( *chIt == '{' )
2108  {
2109  braceNesting++;
2110  }
2111  else if( *chIt == '}' )
2112  {
2113  if( braceNesting > 0 )
2114  braceNesting--;
2115 
2116  if( braceNesting == overbarDepth )
2117  {
2118  overbarDepth = -1;
2119  continue;
2120  }
2121  }
2122 
2123  const FONT_GLYPH_TYPE* glyph = LookupGlyph( *chIt );
2124 
2125  if( !glyph // Not coded in font
2126  || *chIt == '-' || *chIt == '_' ) // Strange size of these 2 chars
2127  {
2128  glyph = defaultGlyph;
2129  }
2130 
2131  if( glyph )
2132  textSize.x += glyph->advance;
2133  }
2134 
2135  textSize.y = std::max<float>( textSize.y, charHeight );
2136  commonOffset = std::min<float>( font_information.max_y - defaultGlyph->maxy, commonOffset );
2137  textSize.y -= commonOffset;
2138 
2139  return std::make_pair( textSize, commonOffset );
2140 }
uni_iter uend() const
Return a uni_iter initialized to the end of "this" UTF8 byte sequence.
Definition: utf8.h:287
const FONT_GLYPH_TYPE * LookupGlyph(unsigned int aCodepoint)
uni_iter ubegin() const
Returns a uni_iter initialized to the start of "this" UTF8 byte sequence.
Definition: utf8.h:279
FONT_INFO_TYPE font_information
Definition: gl_resources.cpp:3
uni_iter is a non-mutating iterator that walks through unicode code points in the UTF8 encoded string...
Definition: utf8.h:203

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 237 of file graphics_abstraction_layer.cpp.

238 {
239  // just return the current value. This could be cleverer and take
240  // into account other settings in future
241  return m_gridMinSpacing;
242 }
int m_gridMinSpacing
Minimum screen size of the grid (pixels) below which the grid is not drawn.

References KIGFX::GAL::m_gridMinSpacing.

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

◆ computeWorldScale()

void KIGFX::GAL::computeWorldScale ( )
inlineprotectedinherited

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

Definition at line 1111 of file graphics_abstraction_layer.h.

1112  {
1114  }
double m_zoomFactor
The zoom factor.
double m_worldScale
The scale factor world->screen.
double m_screenDPI
The dots per inch of the screen.
double m_worldUnitLength
The unit length of the world coordinates [inch].

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

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

◆ ComputeWorldScreenMatrix()

void OPENGL_GAL::ComputeWorldScreenMatrix ( )
overridevirtual

Compute the world <-> screen transformation matrix.

Reimplemented from KIGFX::GAL.

Definition at line 2356 of file opengl_gal.cpp.

2357 {
2359  auto pixelSize = m_worldScale;
2360 
2361  // we need -m_lookAtPoint == -k * pixelSize + 0.5 * pixelSize for OpenGL
2362  // meaning m_lookAtPoint = (k-0.5)*pixelSize with integer k
2365 
2367 }
VECTOR2D m_lookAtPoint
Point to be looked at in world space.
virtual void ComputeWorldScreenMatrix()
Compute the world <-> screen transformation matrix.
double m_worldScale
The scale factor world->screen.
double round_to_half_pixel(double f, double r)
void computeWorldScale()
Compute the scaling factor for the world->screen matrix.

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 1667 of file opengl_gal.cpp.

1668 {
1669  // Frees memory in the container as well
1670  m_groups.erase( aGroupNumber );
1671 }
GROUPS_MAP m_groups
Stores information about VBO objects (groups)
Definition: opengl_gal.h:317

References m_groups.

◆ DrawArc()

void OPENGL_GAL::DrawArc ( const VECTOR2D aCenterPoint,
double  aRadius,
double  aStartAngle,
double  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 785 of file opengl_gal.cpp.

787 {
788  if( aRadius <= 0 )
789  return;
790 
791  // Swap the angles, if start angle is greater than end angle
792  SWAP( aStartAngle, >, aEndAngle );
793 
794  const double alphaIncrement = calcAngleStep( aRadius );
795 
796  Save();
797  m_currentManager->Translate( aCenterPoint.x, aCenterPoint.y, 0.0 );
798 
799  if( m_isFillEnabled )
800  {
801  double alpha;
804 
805  // Triangle fan
806  for( alpha = aStartAngle; ( alpha + alphaIncrement ) < aEndAngle; )
807  {
809  m_currentManager->Vertex( 0.0, 0.0, m_layerDepth );
810  m_currentManager->Vertex( cos( alpha ) * aRadius, sin( alpha ) * aRadius,
811  m_layerDepth );
812  alpha += alphaIncrement;
813  m_currentManager->Vertex( cos( alpha ) * aRadius, sin( alpha ) * aRadius,
814  m_layerDepth );
815  }
816 
817  // The last missing triangle
818  const VECTOR2D endPoint( cos( aEndAngle ) * aRadius, sin( aEndAngle ) * aRadius );
819 
821  m_currentManager->Vertex( 0.0, 0.0, m_layerDepth );
822  m_currentManager->Vertex( cos( alpha ) * aRadius, sin( alpha ) * aRadius, m_layerDepth );
823  m_currentManager->Vertex( endPoint.x, endPoint.y, m_layerDepth );
824  }
825 
826  if( m_isStrokeEnabled )
827  {
829  m_strokeColor.a );
830 
831  VECTOR2D p( cos( aStartAngle ) * aRadius, sin( aStartAngle ) * aRadius );
832  double alpha;
833 
834  for( alpha = aStartAngle + alphaIncrement; alpha <= aEndAngle; alpha += alphaIncrement )
835  {
836  VECTOR2D p_next( cos( alpha ) * aRadius, sin( alpha ) * aRadius );
837  DrawLine( p, p_next );
838 
839  p = p_next;
840  }
841 
842  // Draw the last missing part
843  if( alpha != aEndAngle )
844  {
845  VECTOR2D p_last( cos( aEndAngle ) * aRadius, sin( aEndAngle ) * aRadius );
846  DrawLine( p, p_last );
847  }
848  }
849 
850  Restore();
851 }
bool m_isFillEnabled
Is filling of graphic objects enabled ?
bool Reserve(unsigned int aSize)
Allocate space for vertices, so it will be used with subsequent Vertex() calls.
void Restore() override
Restore the context.
bool Vertex(const VERTEX &aVertex)
Add a vertex with the given coordinates to the currently set item.
double g
Green component.
Definition: color4d.h:378
double b
Blue component.
Definition: color4d.h:379
double m_layerDepth
The actual layer depth.
void Save() override
Save the context.
VERTEX_MANAGER * m_currentManager
Currently used VERTEX_MANAGER (for storing VERTEX_ITEMs).
Definition: opengl_gal.h:319
double a
Alpha component.
Definition: color4d.h:380
bool m_isStrokeEnabled
Are the outlines stroked ?
COLOR4D m_strokeColor
The color of the outlines.
double calcAngleStep(double aRadius) const
Compute the angle step when drawing arcs/circles approximated with lines.
Definition: opengl_gal.h:511
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...
void DrawLine(const VECTOR2D &aStartPoint, const VECTOR2D &aEndPoint) override
Draw a line.
Definition: opengl_gal.cpp:666
void Color(const COLOR4D &aColor)
Changes currently used color that will be applied to newly added vertices.
COLOR4D m_fillColor
The fill color.
#define SWAP(varA, condition, varB)
Swap the variables if a condition is met.
Definition: definitions.h:31
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.
double r
Red component.
Definition: color4d.h:377

References KIGFX::COLOR4D::a, 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,
double  aStartAngle,
double  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 854 of file opengl_gal.cpp.

857 {
858  if( aRadius <= 0 )
859  {
860  // Arcs of zero radius are a circle of aWidth diameter
861  if( aWidth > 0 )
862  DrawCircle( aCenterPoint, aWidth / 2.0 );
863 
864  return;
865  }
866 
867  // Swap the angles, if start angle is greater than end angle
868  SWAP( aStartAngle, >, aEndAngle );
869 
870  // Calculate the seg count to approximate the arc with aMaxError or less
871  int segCount360 = GetArcToSegmentCount( aRadius, aMaxError, 360.0 );
872  segCount360 = std::max( SEG_PER_CIRCLE_COUNT, segCount360 );
873  double alphaIncrement = 2.0 * M_PI / segCount360;
874 
875  // Refinement: Use a segment count multiple of 2, because we have a control point
876  // on the middle of the arc, and the look is better if it is on a segment junction
877  // because there is no approx error
878  int seg_count = KiROUND( ( aEndAngle - aStartAngle ) / alphaIncrement );
879 
880  if( seg_count % 2 != 0 )
881  seg_count += 1;
882 
883  // Recalculate alphaIncrement with a even integer number of segment
884  if( seg_count )
885  alphaIncrement = ( aEndAngle - aStartAngle ) / seg_count;
886 
887  Save();
888  m_currentManager->Translate( aCenterPoint.x, aCenterPoint.y, 0.0 );
889 
890  if( m_isStrokeEnabled )
891  {
893  m_strokeColor.a );
894 
895  double width = aWidth / 2.0;
896  VECTOR2D startPoint( cos( aStartAngle ) * aRadius, sin( aStartAngle ) * aRadius );
897  VECTOR2D endPoint( cos( aEndAngle ) * aRadius, sin( aEndAngle ) * aRadius );
898 
899  drawStrokedSemiCircle( startPoint, width, aStartAngle + M_PI );
900  drawStrokedSemiCircle( endPoint, width, aEndAngle );
901 
902  VECTOR2D pOuter( cos( aStartAngle ) * ( aRadius + width ),
903  sin( aStartAngle ) * ( aRadius + width ) );
904 
905  VECTOR2D pInner( cos( aStartAngle ) * ( aRadius - width ),
906  sin( aStartAngle ) * ( aRadius - width ) );
907 
908  double alpha;
909 
910  for( alpha = aStartAngle + alphaIncrement; alpha <= aEndAngle; alpha += alphaIncrement )
911  {
912  VECTOR2D pNextOuter( cos( alpha ) * ( aRadius + width ),
913  sin( alpha ) * ( aRadius + width ) );
914  VECTOR2D pNextInner( cos( alpha ) * ( aRadius - width ),
915  sin( alpha ) * ( aRadius - width ) );
916 
917  DrawLine( pOuter, pNextOuter );
918  DrawLine( pInner, pNextInner );
919 
920  pOuter = pNextOuter;
921  pInner = pNextInner;
922  }
923 
924  // Draw the last missing part
925  if( alpha != aEndAngle )
926  {
927  VECTOR2D pLastOuter( cos( aEndAngle ) * ( aRadius + width ),
928  sin( aEndAngle ) * ( aRadius + width ) );
929  VECTOR2D pLastInner( cos( aEndAngle ) * ( aRadius - width ),
930  sin( aEndAngle ) * ( aRadius - width ) );
931 
932  DrawLine( pOuter, pLastOuter );
933  DrawLine( pInner, pLastInner );
934  }
935  }
936 
937  if( m_isFillEnabled )
938  {
940  SetLineWidth( aWidth );
941 
942  VECTOR2D p( cos( aStartAngle ) * aRadius, sin( aStartAngle ) * aRadius );
943  double alpha;
944 
945  for( alpha = aStartAngle + alphaIncrement; alpha <= aEndAngle; alpha += alphaIncrement )
946  {
947  VECTOR2D p_next( cos( alpha ) * aRadius, sin( alpha ) * aRadius );
948  DrawLine( p, p_next );
949 
950  p = p_next;
951  }
952 
953  // Draw the last missing part
954  if( alpha != aEndAngle )
955  {
956  VECTOR2D p_last( cos( aEndAngle ) * aRadius, sin( aEndAngle ) * aRadius );
957  DrawLine( p, p_last );
958  }
959  }
960 
961  Restore();
962 }
bool m_isFillEnabled
Is filling of graphic objects enabled ?
void Restore() override
Restore the context.
double g
Green component.
Definition: color4d.h:378
virtual void SetLineWidth(float aLineWidth)
Set the line width.
double b
Blue component.
Definition: color4d.h:379
void Save() override
Save the context.
VERTEX_MANAGER * m_currentManager
Currently used VERTEX_MANAGER (for storing VERTEX_ITEMs).
Definition: opengl_gal.h:319
double a
Alpha component.
Definition: color4d.h:380
bool m_isStrokeEnabled
Are the outlines stroked ?
COLOR4D m_strokeColor
The color of the outlines.
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...
void DrawLine(const VECTOR2D &aStartPoint, const VECTOR2D &aEndPoint) override
Draw a line.
Definition: opengl_gal.cpp:666
void Color(const COLOR4D &aColor)
Changes currently used color that will be applied to newly added vertices.
void drawStrokedSemiCircle(const VECTOR2D &aCenterPoint, double aRadius, double aAngle)
Draw a stroked semicircle.
COLOR4D m_fillColor
The fill color.
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:73
#define SWAP(varA, condition, varB)
Swap the variables if a condition is met.
Definition: definitions.h:31
#define SEG_PER_CIRCLE_COUNT
Definition: opengl_gal.h:53
double r
Red component.
Definition: color4d.h:377
int GetArcToSegmentCount(int aRadius, int aErrorMax, double aArcAngleDegree)
void DrawCircle(const VECTOR2D &aCenterPoint, double aRadius) override
Draw a circle using world coordinates.
Definition: opengl_gal.cpp:728

References KIGFX::COLOR4D::a, KIGFX::COLOR4D::b, KIGFX::VERTEX_MANAGER::Color(), DrawCircle(), DrawLine(), drawStrokedSemiCircle(), 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, 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)
overridevirtual

Draw a bitmap image.

Reimplemented from KIGFX::GAL.

Definition at line 1202 of file opengl_gal.cpp.

1203 {
1204  // We have to calculate the pixel size in users units to draw the image.
1205  // m_worldUnitLength is a factor used for converting IU to inches
1206  double scale = 1.0 / ( aBitmap.GetPPI() * m_worldUnitLength );
1207  double w = (double) aBitmap.GetSizePixels().x * scale;
1208  double h = (double) aBitmap.GetSizePixels().y * scale;
1209 
1210  auto xform = m_currentManager->GetTransformation();
1211 
1212  glm::vec4 v0 = xform * glm::vec4( -w / 2, -h / 2, 0.0, 0.0 );
1213  glm::vec4 v1 = xform * glm::vec4( w / 2, h / 2, 0.0, 0.0 );
1214  glm::vec4 trans = xform[3];
1215 
1216  auto texture_id = m_bitmapCache->RequestBitmap( &aBitmap );
1217 
1218  if( !glIsTexture( texture_id ) ) // ensure the bitmap texture is still valid
1219  return;
1220 
1221  auto oldTarget = GetTarget();
1222 
1223  glPushMatrix();
1224  glTranslated( trans.x, trans.y, trans.z );
1225 
1227  glEnable( GL_TEXTURE_2D );
1228  glActiveTexture( GL_TEXTURE0 );
1229  glBindTexture( GL_TEXTURE_2D, texture_id );
1230 
1231  glBegin( GL_QUADS );
1232  glColor4f( 1.0, 1.0, 1.0, 1.0 );
1233  glTexCoord2f( 0.0, 0.0 );
1234  glVertex3f( v0.x, v0.y, m_layerDepth );
1235  glColor4f( 1.0, 1.0, 1.0, 1.0 );
1236  glTexCoord2f( 1.0, 0.0 );
1237  glVertex3f( v1.x, v0.y, m_layerDepth );
1238  glColor4f( 1.0, 1.0, 1.0, 1.0 );
1239  glTexCoord2f( 1.0, 1.0 );
1240  glVertex3f( v1.x, v1.y, m_layerDepth );
1241  glColor4f( 1.0, 1.0, 1.0, 1.0 );
1242  glTexCoord2f( 0.0, 1.0 );
1243  glVertex3f( v0.x, v1.y, m_layerDepth );
1244  glEnd();
1245 
1246  SetTarget( oldTarget );
1247  glBindTexture( GL_TEXTURE_2D, 0 );
1248 
1249 #ifdef DISABLE_BITMAP_CACHE
1250  glDeleteTextures( 1, &texture_id );
1251 #endif
1252 
1253  glPopMatrix();
1254 }
const glm::mat4 & GetTransformation() const
double m_layerDepth
The actual layer depth.
Auxiliary rendering target (noncached)
Definition: definitions.h:49
RENDER_TARGET GetTarget() const override
Get the currently used target for rendering.
VERTEX_MANAGER * m_currentManager
Currently used VERTEX_MANAGER (for storing VERTEX_ITEMs).
Definition: opengl_gal.h:319
void SetTarget(RENDER_TARGET aTarget) override
Set the target for rendering.
const int scale
wxSize GetSizePixels() const
Definition: bitmap_base.h:124
std::unique_ptr< GL_BITMAP_CACHE > m_bitmapCache
Definition: opengl_gal.h:351
double m_worldUnitLength
The unit length of the world coordinates [inch].
int GetPPI() const
Definition: bitmap_base.h:135

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

◆ drawBitmapChar()

int OPENGL_GAL::drawBitmapChar ( unsigned long  aChar)
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.

Definition at line 1977 of file opengl_gal.cpp.

1978 {
1979  const float TEX_X = font_image.width;
1980  const float TEX_Y = font_image.height;
1981 
1982  // handle space
1983  if( aChar == ' ' )
1984  {
1985  const FONT_GLYPH_TYPE* g = LookupGlyph( 'x' );
1986  wxASSERT( g );
1987 
1988  if( !g ) // Should not happen.
1989  return 0;
1990 
1991  Translate( VECTOR2D( g->advance, 0 ) );
1992  return g->advance;
1993  }
1994 
1995  const FONT_GLYPH_TYPE* glyph = LookupGlyph( aChar );
1996 
1997  // If the glyph is not found (happens for many esoteric unicode chars)
1998  // shows a '?' instead.
1999  if( !glyph )
2000  glyph = LookupGlyph( '?' );
2001 
2002  if( !glyph ) // Should not happen.
2003  return 0;
2004 
2005  const float X = glyph->atlas_x + font_information.smooth_pixels;
2006  const float Y = glyph->atlas_y + font_information.smooth_pixels;
2007  const float XOFF = glyph->minx;
2008 
2009  // adjust for height rounding
2010  const float round_adjust = ( glyph->maxy - glyph->miny )
2011  - float( glyph->atlas_h - font_information.smooth_pixels * 2 );
2012  const float top_adjust = font_information.max_y - glyph->maxy;
2013  const float YOFF = round_adjust + top_adjust;
2014  const float W = glyph->atlas_w - font_information.smooth_pixels * 2;
2015  const float H = glyph->atlas_h - font_information.smooth_pixels * 2;
2016  const float B = 0;
2017 
2018  m_currentManager->Reserve( 6 );
2019  Translate( VECTOR2D( XOFF, YOFF ) );
2020 
2021  /* Glyph:
2022  * v0 v1
2023  * +--+
2024  * | /|
2025  * |/ |
2026  * +--+
2027  * v2 v3
2028  */
2029  m_currentManager->Shader( SHADER_FONT, X / TEX_X, ( Y + H ) / TEX_Y );
2030  m_currentManager->Vertex( -B, -B, 0 ); // v0
2031 
2032  m_currentManager->Shader( SHADER_FONT, ( X + W ) / TEX_X, ( Y + H ) / TEX_Y );
2033  m_currentManager->Vertex( W + B, -B, 0 ); // v1
2034 
2035  m_currentManager->Shader( SHADER_FONT, X / TEX_X, Y / TEX_Y );
2036  m_currentManager->Vertex( -B, H + B, 0 ); // v2
2037 
2038 
2039  m_currentManager->Shader( SHADER_FONT, ( X + W ) / TEX_X, ( Y + H ) / TEX_Y );
2040  m_currentManager->Vertex( W + B, -B, 0 ); // v1
2041 
2042  m_currentManager->Shader( SHADER_FONT, X / TEX_X, Y / TEX_Y );
2043  m_currentManager->Vertex( -B, H + B, 0 ); // v2
2044 
2045  m_currentManager->Shader( SHADER_FONT, ( X + W ) / TEX_X, Y / TEX_Y );
2046  m_currentManager->Vertex( W + B, H + B, 0 ); // v3
2047 
2048  Translate( VECTOR2D( -XOFF + glyph->advance, -YOFF ) );
2049 
2050  return glyph->advance;
2051 }
void Translate(const VECTOR2D &aTranslation) override
Translate the context.
bool Reserve(unsigned int aSize)
Allocate space for vertices, so it will be used with subsequent Vertex() calls.
bool Vertex(const VERTEX &aVertex)
Add a vertex with the given coordinates to the currently set item.
const FONT_GLYPH_TYPE * LookupGlyph(unsigned int aCodepoint)
VERTEX_MANAGER * m_currentManager
Currently used VERTEX_MANAGER (for storing VERTEX_ITEMs).
Definition: opengl_gal.h:319
VECTOR2< double > VECTOR2D
Definition: vector2d.h:622
FONT_IMAGE_TYPE font_image
Definition: gl_resources.cpp:4
FONT_INFO_TYPE font_information
Definition: gl_resources.cpp:3
#define H(x, y, z)
Definition: md5_hash.cpp:17
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.

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, 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(), and KIGFX::BUILTIN_FONT::FONT_IMAGE_TYPE::width.

Referenced by BitmapText().

◆ drawBitmapOverbar()

void OPENGL_GAL::drawBitmapOverbar ( double  aLength,
double  aHeight 
)
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.

Definition at line 2054 of file opengl_gal.cpp.

2055 {
2056  // To draw an overbar, simply draw an overbar
2057  const FONT_GLYPH_TYPE* glyph = LookupGlyph( '_' );
2058  wxCHECK( glyph, /* void */ );
2059 
2060  const float H = glyph->maxy - glyph->miny;
2061 
2062  Save();
2063 
2064  Translate( VECTOR2D( -aLength, -aHeight ) );
2065 
2066  m_currentManager->Reserve( 6 );
2068 
2069  m_currentManager->Shader( 0 );
2070 
2071  m_currentManager->Vertex( 0, 0, 0 ); // v0
2072  m_currentManager->Vertex( aLength, 0, 0 ); // v1
2073  m_currentManager->Vertex( 0, H, 0 ); // v2
2074 
2075  m_currentManager->Vertex( aLength, 0, 0 ); // v1
2076  m_currentManager->Vertex( 0, H, 0 ); // v2
2077  m_currentManager->Vertex( aLength, H, 0 ); // v3
2078 
2079  Restore();
2080 }
void Translate(const VECTOR2D &aTranslation) override
Translate the context.
bool Reserve(unsigned int aSize)
Allocate space for vertices, so it will be used with subsequent Vertex() calls.
void Restore() override
Restore the context.
bool Vertex(const VERTEX &aVertex)
Add a vertex with the given coordinates to the currently set item.
double g
Green component.
Definition: color4d.h:378
const FONT_GLYPH_TYPE * LookupGlyph(unsigned int aCodepoint)
double b
Blue component.
Definition: color4d.h:379
void Save() override
Save the context.
VERTEX_MANAGER * m_currentManager
Currently used VERTEX_MANAGER (for storing VERTEX_ITEMs).
Definition: opengl_gal.h:319
double a
Alpha component.
Definition: color4d.h:380
COLOR4D m_strokeColor
The color of the outlines.
VECTOR2< double > VECTOR2D
Definition: vector2d.h:622
void Color(const COLOR4D &aColor)
Changes currently used color that will be applied to newly added vertices.
#define H(x, y, z)
Definition: md5_hash.cpp:17
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.
double r
Red component.
Definition: color4d.h:377

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 728 of file opengl_gal.cpp.

729 {
730  if( m_isFillEnabled )
731  {
734 
735  /* Draw a triangle that contains the circle, then shade it leaving only the circle.
736  * Parameters given to Shader() are indices of the triangle's vertices
737  * (if you want to understand more, check the vertex shader source [shader.vert]).
738  * Shader uses this coordinates to determine if fragments are inside the circle or not.
739  * Does the calculations in the vertex shader now (pixel alignment)
740  * v2
741  * /\
742  * //\\
743  * v0 /_\/_\ v1
744  */
745  m_currentManager->Shader( SHADER_FILLED_CIRCLE, 1.0, aRadius );
746  m_currentManager->Vertex( aCenterPoint.x, aCenterPoint.y, m_layerDepth );
747 
748  m_currentManager->Shader( SHADER_FILLED_CIRCLE, 2.0, aRadius );
749  m_currentManager->Vertex( aCenterPoint.x, aCenterPoint.y, m_layerDepth );
750 
751  m_currentManager->Shader( SHADER_FILLED_CIRCLE, 3.0, aRadius );
752  m_currentManager->Vertex( aCenterPoint.x, aCenterPoint.y, m_layerDepth );
753  }
754  if( m_isStrokeEnabled )
755  {
758  m_strokeColor.a );
759 
760  /* Draw a triangle that contains the circle, then shade it leaving only the circle.
761  * Parameters given to Shader() are indices of the triangle's vertices
762  * (if you want to understand more, check the vertex shader source [shader.vert]).
763  * and the line width. Shader uses this coordinates to determine if fragments are
764  * inside the circle or not.
765  * v2
766  * /\
767  * //\\
768  * v0 /_\/_\ v1
769  */
771  m_currentManager->Vertex( aCenterPoint.x, // v0
772  aCenterPoint.y, m_layerDepth );
773 
775  m_currentManager->Vertex( aCenterPoint.x, // v1
776  aCenterPoint.y, m_layerDepth );
777 
779  m_currentManager->Vertex( aCenterPoint.x, aCenterPoint.y, // v2
780  m_layerDepth );
781  }
782 }
bool m_isFillEnabled
Is filling of graphic objects enabled ?
bool Reserve(unsigned int aSize)
Allocate space for vertices, so it will be used with subsequent Vertex() calls.
bool Vertex(const VERTEX &aVertex)
Add a vertex with the given coordinates to the currently set item.
double g
Green component.
Definition: color4d.h:378
double b
Blue component.
Definition: color4d.h:379
double m_layerDepth
The actual layer depth.
VERTEX_MANAGER * m_currentManager
Currently used VERTEX_MANAGER (for storing VERTEX_ITEMs).
Definition: opengl_gal.h:319
double a
Alpha component.
Definition: color4d.h:380
bool m_isStrokeEnabled
Are the outlines stroked ?
COLOR4D m_strokeColor
The color of the outlines.
void Color(const COLOR4D &aColor)
Changes currently used color that will be applied to newly added vertices.
COLOR4D m_fillColor
The fill color.
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.
double r
Red component.
Definition: color4d.h:377
float m_lineWidth
The line width.

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 DrawArcSegment(), 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 1782 of file opengl_gal.cpp.

1783 {
1784  // Now we should only store the position of the mouse cursor
1785  // The real drawing routines are in blitCursor()
1786  //VECTOR2D screenCursor = m_worldScreenMatrix * aCursorPosition;
1787  //m_cursorPosition = m_screenWorldMatrix * VECTOR2D( screenCursor.x, screenCursor.y );
1788  m_cursorPosition = aCursorPosition;
1789 }
VECTOR2D m_cursorPosition
Current cursor position (world coordinates)

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 1183 of file opengl_gal.cpp.

1186 {
1187  std::vector<VECTOR2D> output;
1188  std::vector<VECTOR2D> pointCtrl;
1189 
1190  pointCtrl.push_back( aStartPoint );
1191  pointCtrl.push_back( aControlPointA );
1192  pointCtrl.push_back( aControlPointB );
1193  pointCtrl.push_back( aEndPoint );
1194 
1195  BEZIER_POLY converter( pointCtrl );
1196  converter.GetPoly( output, aFilterValue );
1197 
1198  DrawPolyline( &output[0], output.size() );
1199 }
void DrawPolyline(const std::deque< VECTOR2D > &aPointList) override
Draw a polyline.
Bezier curves to polygon converter.
Definition: bezier_curves.h:36

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 1856 of file opengl_gal.cpp.

1857 {
1858  Save();
1859 
1860  m_currentManager->Reserve( 3 );
1861  m_currentManager->Translate( aCenterPoint.x, aCenterPoint.y, 0.0f );
1862  m_currentManager->Rotate( aAngle, 0.0f, 0.0f, 1.0f );
1863 
1864  /* Draw a triangle that contains the semicircle, then shade it to leave only
1865  * the semicircle. Parameters given to Shader() are indices of the triangle's vertices
1866  * (if you want to understand more, check the vertex shader source [shader.vert]).
1867  * Shader uses these coordinates to determine if fragments are inside the semicircle or not.
1868  * v2
1869  * /\
1870  * /__\
1871  * v0 //__\\ v1
1872  */
1874  m_currentManager->Vertex( -aRadius * 3.0f / sqrt( 3.0f ), 0.0f, m_layerDepth ); // v0
1875 
1877  m_currentManager->Vertex( aRadius * 3.0f / sqrt( 3.0f ), 0.0f, m_layerDepth ); // v1
1878 
1880  m_currentManager->Vertex( 0.0f, aRadius * 2.0f, m_layerDepth ); // v2
1881 
1882  Restore();
1883 }
bool Reserve(unsigned int aSize)
Allocate space for vertices, so it will be used with subsequent Vertex() calls.
void Restore() override
Restore the context.
bool Vertex(const VERTEX &aVertex)
Add a vertex with the given coordinates to the currently set item.
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 ...
double m_layerDepth
The actual layer depth.
void Save() override
Save the context.
VERTEX_MANAGER * m_currentManager
Currently used VERTEX_MANAGER (for storing VERTEX_ITEMs).
Definition: opengl_gal.h:319
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...
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.

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().

◆ DrawGrid()

void OPENGL_GAL::DrawGrid ( )
overridevirtual

Reimplemented from KIGFX::GAL.

Definition at line 1373 of file opengl_gal.cpp.

1374 {
1377 
1379 
1380  // sub-pixel lines all render the same
1381  float minorLineWidth = std::fmax( 1.0f,
1383  float majorLineWidth = minorLineWidth * 2.0f;
1384 
1385  // Draw the axis and grid
1386  // For the drawing the start points, end points and increments have
1387  // to be calculated in world coordinates
1388  VECTOR2D worldStartPoint = m_screenWorldMatrix * VECTOR2D( 0.0, 0.0 );
1389  VECTOR2D worldEndPoint = m_screenWorldMatrix * VECTOR2D( m_screenSize );
1390 
1391  // Draw axes if desired
1392  if( m_axesEnabled )
1393  {
1394  SetLineWidth( minorLineWidth );
1396 
1397  DrawLine( VECTOR2D( worldStartPoint.x, 0 ), VECTOR2D( worldEndPoint.x, 0 ) );
1398  DrawLine( VECTOR2D( 0, worldStartPoint.y ), VECTOR2D( 0, worldEndPoint.y ) );
1399  }
1400 
1401  // force flush
1403 
1404  if( !m_gridVisibility || m_gridSize.x == 0 || m_gridSize.y == 0 )
1405  return;
1406 
1407  VECTOR2D gridScreenSize( m_gridSize );
1408 
1409  double gridThreshold = computeMinGridSpacing() / m_worldScale;
1410 
1412  gridThreshold *= 2.0;
1413 
1414  // If we cannot display the grid density, scale down by a tick size and
1415  // try again. Eventually, we get some representation of the grid
1416  while( std::min( gridScreenSize.x, gridScreenSize.y ) <= gridThreshold )
1417  {
1418  gridScreenSize = gridScreenSize * static_cast<double>( m_gridTick );
1419  }
1420 
1421  // Compute grid starting and ending indexes to draw grid points on the
1422  // visible screen area
1423  // Note: later any point coordinate will be offsetted by m_gridOrigin
1424  int gridStartX = KiROUND( ( worldStartPoint.x - m_gridOrigin.x ) / gridScreenSize.x );
1425  int gridEndX = KiROUND( ( worldEndPoint.x - m_gridOrigin.x ) / gridScreenSize.x );
1426  int gridStartY = KiROUND( ( worldStartPoint.y - m_gridOrigin.y ) / gridScreenSize.y );
1427  int gridEndY = KiROUND( ( worldEndPoint.y - m_gridOrigin.y ) / gridScreenSize.y );
1428 
1429  // Ensure start coordinate > end coordinate
1430  SWAP( gridStartX, >, gridEndX );
1431  SWAP( gridStartY, >, gridEndY );
1432 
1433  // Ensure the grid fills the screen
1434  --gridStartX;
1435  ++gridEndX;
1436  --gridStartY;
1437  ++gridEndY;
1438 
1439  glDisable( GL_DEPTH_TEST );
1440  glDisable( GL_TEXTURE_2D );
1441 
1442  if( m_gridStyle == GRID_STYLE::DOTS )
1443  {
1444  glEnable( GL_STENCIL_TEST );
1445  glStencilFunc( GL_ALWAYS, 1, 1 );
1446  glStencilOp( GL_KEEP, GL_KEEP, GL_INCR );
1447  glColor4d( 0.0, 0.0, 0.0, 0.0 );
1448  SetStrokeColor( COLOR4D( 0.0, 0.0, 0.0, 0.0 ) );
1449  }
1450  else
1451  {
1452  glColor4d( m_gridColor.r, m_gridColor.g, m_gridColor.b, m_gridColor.a );
1454  }
1455 
1457  {
1458  // Vertical positions
1459  for( int j = gridStartY; j <= gridEndY; j++ )
1460  {
1461  bool tickY = ( j % m_gridTick == 0 );
1462  const double posY = j * gridScreenSize.y + m_gridOrigin.y;
1463 
1464  // Horizontal positions
1465  for( int i = gridStartX; i <= gridEndX; i++ )
1466  {
1467  bool tickX = ( i % m_gridTick == 0 );
1468  SetLineWidth( ( ( tickX && tickY ) ? majorLineWidth : minorLineWidth ) );
1469  auto lineLen = 2.0 * GetLineWidth();
1470  auto posX = i * gridScreenSize.x + m_gridOrigin.x;
1471 
1472  DrawLine( VECTOR2D( posX - lineLen, posY ), VECTOR2D( posX + lineLen, posY ) );
1473  DrawLine( VECTOR2D( posX, posY - lineLen ), VECTOR2D( posX, posY + lineLen ) );
1474  }
1475  }
1476 
1478  }
1479  else
1480  {
1481  // Vertical lines
1482  for( int j = gridStartY; j <= gridEndY; j++ )
1483  {
1484  const double y = j * gridScreenSize.y + m_gridOrigin.y;
1485 
1486  // If axes are drawn, skip the lines that would cover them
1487  if( m_axesEnabled && y == 0.0 )
1488  continue;
1489 
1490  SetLineWidth( ( j % m_gridTick == 0 ) ? majorLineWidth : minorLineWidth );
1491  VECTOR2D a( gridStartX * gridScreenSize.x + m_gridOrigin.x, y );
1492  VECTOR2D b( gridEndX * gridScreenSize.x + m_gridOrigin.x, y );
1493 
1494  DrawLine( a, b );
1495  }
1496 
1498 
1499  if( m_gridStyle == GRID_STYLE::DOTS )
1500  {
1501  glStencilFunc( GL_NOTEQUAL, 0, 1 );
1502  glColor4d( m_gridColor.r, m_gridColor.g, m_gridColor.b, m_gridColor.a );
1504  }
1505 
1506  // Horizontal lines
1507  for( int i = gridStartX; i <= gridEndX; i++ )
1508  {
1509  const double x = i * gridScreenSize.x + m_gridOrigin.x;
1510 
1511  // If axes are drawn, skip the lines that would cover them
1512  if( m_axesEnabled && x == 0.0 )
1513  continue;
1514 
1515  SetLineWidth( ( i % m_gridTick == 0 ) ? majorLineWidth : minorLineWidth );
1516  VECTOR2D a( x, gridStartY * gridScreenSize.y + m_gridOrigin.y );
1517  VECTOR2D b( x, gridEndY * gridScreenSize.y + m_gridOrigin.y );
1518  DrawLine( a, b );
1519  }
1520 
1522 
1523  if( m_gridStyle == GRID_STYLE::DOTS )
1524  glDisable( GL_STENCIL_TEST );
1525  }
1526 
1527  glEnable( GL_DEPTH_TEST );
1528  glEnable( GL_TEXTURE_2D );
1529 }
float GetLineWidth() const
Get the line width.
bool m_axesEnabled
Should the axes be drawn.
double computeMinGridSpacing() const
compute minimum grid spacing from the grid settings
MATRIX3x3D m_screenWorldMatrix
Screen transformation.
VECTOR2D m_gridSize
The grid size.
double GetScaleFactor() const
Get the current scale factor.
double g
Green component.
Definition: color4d.h:378
unsigned int m_mainBuffer
Main rendering target.
Definition: opengl_gal.h:327
int m_gridTick
Every tick line gets the double width.
float m_gridLineWidth
Line width of the grid.
virtual void SetLineWidth(float aLineWidth)
Set the line width.
double b
Blue component.
Definition: color4d.h:379
Auxiliary rendering target (noncached)
Definition: definitions.h:49
double getWorldPixelSize() const
Definition: opengl_gal.cpp:403
COLOR4D m_gridColor
Color of the grid.
double m_worldScale
The scale factor world->screen.
double a
Alpha component.
Definition: color4d.h:380
VECTOR2< double > VECTOR2D
Definition: vector2d.h:622
bool m_gridVisibility
Should the grid be shown.
OPENGL_COMPOSITOR * m_compositor
Handles multiple rendering targets.
Definition: opengl_gal.h:326
void DrawLine(const VECTOR2D &aStartPoint, const VECTOR2D &aEndPoint) override
Draw a line.
Definition: opengl_gal.cpp:666
virtual void SetBuffer(unsigned int aBufferHandle) override
Set the selected buffer as the rendering target.
Use dots for the grid.
Use small cross instead of dots for the grid.
void EndDrawing() const
Finish drawing operations.
GRID_STYLE m_gridStyle
Grid display style.
void SetTarget(RENDER_TARGET aTarget) override
Set the target for rendering.
virtual void SetStrokeColor(const COLOR4D &aColor)
Set the stroke color.
COLOR4D m_axesColor
Color of the axes.
void EnableDepthTest(bool aEnabled)
Enable/disable Z buffer depth test.
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:73
#define SWAP(varA, condition, varB)
Swap the variables if a condition is met.
Definition: definitions.h:31
VECTOR2D m_gridOrigin
The grid origin.
double r
Red component.
Definition: color4d.h:377
VERTEX_MANAGER * m_nonCachedManager
Container for storing non-cached VERTEX_ITEMs.
Definition: opengl_gal.h:322
VECTOR2I m_screenSize
Screen size in screen coordinates.
A color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:103

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 1640 of file opengl_gal.cpp.

1641 {
1642  auto group = m_groups.find( aGroupNumber );
1643 
1644  if( group != m_groups.end() )
1645  m_cachedManager->DrawItem( *group->second );
1646 }
GROUPS_MAP m_groups
Stores information about VBO objects (groups)
Definition: opengl_gal.h:317
void DrawItem(const VERTEX_ITEM &aItem) const
Draw an item to the buffer.
VERTEX_MANAGER * m_cachedManager
Container for storing cached VERTEX_ITEMs.
Definition: opengl_gal.h:321

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 666 of file opengl_gal.cpp.

667 {
669 
670  drawLineQuad( aStartPoint, aEndPoint );
671 }
void drawLineQuad(const VECTOR2D &aStartPoint, const VECTOR2D &aEndPoint)
Draw a quad for the line.
double g
Green component.
Definition: color4d.h:378
double b
Blue component.
Definition: color4d.h:379
VERTEX_MANAGER * m_currentManager
Currently used VERTEX_MANAGER (for storing VERTEX_ITEMs).
Definition: opengl_gal.h:319
double a
Alpha component.
Definition: color4d.h:380
COLOR4D m_strokeColor
The color of the outlines.
void Color(const COLOR4D &aColor)
Changes currently used color that will be applied to newly added vertices.
double r
Red component.
Definition: color4d.h:377

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 
)
private

Draw a quad for the line.

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

Definition at line 1792 of file opengl_gal.cpp.

1793 {
1794  /* Helper drawing: ____--- v3 ^
1795  * ____---- ... \ \
1796  * ____---- ... \ end \
1797  * v1 ____---- ... ____---- \ width
1798  * ---- ...___---- \ \
1799  * \ ___...-- \ v
1800  * \ ____----... ____---- v2
1801  * ---- ... ____----
1802  * start \ ... ____----
1803  * \... ____----
1804  * ----
1805  * v0
1806  * dots mark triangles' hypotenuses
1807  */
1808 
1809  auto v1 = m_currentManager->GetTransformation()
1810  * glm::vec4( aStartPoint.x, aStartPoint.y, 0.0, 0.0 );
1812  * glm::vec4( aEndPoint.x, aEndPoint.y, 0.0, 0.0 );
1813 
1814  VECTOR2D vs( v2.x - v1.x, v2.y - v1.y );
1815 
1816  m_currentManager->Reserve( 6 );
1817 
1818  // Line width is maintained by the vertex shader
1820  m_currentManager->Vertex( aStartPoint, m_layerDepth );
1821 
1823  m_currentManager->Vertex( aStartPoint, m_layerDepth );
1824 
1826  m_currentManager->Vertex( aEndPoint, m_layerDepth );
1827 
1829  m_currentManager->Vertex( aEndPoint, m_layerDepth );
1830 
1832  m_currentManager->Vertex( aEndPoint, m_layerDepth );
1833 
1835  m_currentManager->Vertex( aStartPoint, m_layerDepth );
1836 }
const glm::mat4 & GetTransformation() const
VECTOR2I v2(1, 0)
Test suite for KiCad math code.
bool Reserve(unsigned int aSize)
Allocate space for vertices, so it will be used with subsequent Vertex() calls.
bool Vertex(const VERTEX &aVertex)
Add a vertex with the given coordinates to the currently set item.
double m_layerDepth
The actual layer depth.
VERTEX_MANAGER * m_currentManager
Currently used VERTEX_MANAGER (for storing VERTEX_ITEMs).
Definition: opengl_gal.h:319
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.
float m_lineWidth
The line width.

References KIGFX::VERTEX_MANAGER::GetTransformation(), m_currentManager, KIGFX::GAL::m_layerDepth, KIGFX::GAL::m_lineWidth, KIGFX::VERTEX_MANAGER::Reserve(), 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, v2, KIGFX::VERTEX_MANAGER::Vertex(), VECTOR2< T >::x, and VECTOR2< T >::y.

Referenced by DrawLine(), drawPolyline(), and DrawSegment().

◆ DrawPolygon() [1/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 1042 of file opengl_gal.cpp.

1043 {
1044  wxCHECK( aPointList.size() >= 2, /* void */ );
1045  auto points = std::unique_ptr<GLdouble[]>( new GLdouble[3 * aPointList.size()] );
1046  GLdouble* ptr = points.get();
1047 
1048  for( const VECTOR2D& p : aPointList )
1049  {
1050  *ptr++ = p.x;
1051  *ptr++ = p.y;
1052  *ptr++ = m_layerDepth;
1053  }
1054 
1055  drawPolygon( points.get(), aPointList.size() );
1056 }
void drawPolygon(GLdouble *aPoints, int aPointCount)
Draw a filled polygon.
double m_layerDepth
The actual layer depth.

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

Referenced by DrawPolygon().

◆ DrawPolygon() [2/4]

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

Reimplemented from KIGFX::GAL.

Definition at line 1059 of file opengl_gal.cpp.

1060 {
1061  wxCHECK( aListSize >= 2, /* void */ );
1062  auto points = std::unique_ptr<GLdouble[]>( new GLdouble[3 * aListSize] );
1063  GLdouble* target = points.get();
1064  const VECTOR2D* src = aPointList;
1065 
1066  for( int i = 0; i < aListSize; ++i )
1067  {
1068  *target++ = src->x;
1069  *target++ = src->y;
1070  *target++ = m_layerDepth;
1071  ++src;
1072  }
1073 
1074  drawPolygon( points.get(), aListSize );
1075 }
void drawPolygon(GLdouble *aPoints, int aPointCount)
Draw a filled polygon.
double m_layerDepth
The actual layer depth.

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

◆ DrawPolygon() [3/4]

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

Reimplemented from KIGFX::GAL.

Definition at line 1147 of file opengl_gal.cpp.

1148 {
1149  if( aPolySet.IsTriangulationUpToDate() )
1150  {
1151  drawTriangulatedPolyset( aPolySet, aStrokeTriangulation );
1152  return;
1153  }
1154 
1155  for( int j = 0; j < aPolySet.OutlineCount(); ++j )
1156  {
1157  const SHAPE_LINE_CHAIN& outline = aPolySet.COutline( j );
1158  DrawPolygon( outline );
1159  }
1160 }
int OutlineCount() const
Return the number of vertices in a given outline/hole.
void DrawPolygon(const std::deque< VECTOR2D > &aPointList) override
Draw a polygon.
bool IsTriangulationUpToDate() const
Represent a polyline (an zero-thickness chain of connected line segments).
const SHAPE_LINE_CHAIN & COutline(int aIndex) const
void drawTriangulatedPolyset(const SHAPE_POLY_SET &aPoly, bool aStrokeTriangulation)
Draw a set of polygons with a cached triangulation.

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

◆ DrawPolygon() [4/4]

void OPENGL_GAL::DrawPolygon ( const SHAPE_LINE_CHAIN aPolySet)
overridevirtual

Reimplemented from KIGFX::GAL.

Definition at line 1163 of file opengl_gal.cpp.

1164 {
1165  wxCHECK( aPolygon.PointCount() >= 2, /* void */ );
1166 
1167  const int pointCount = aPolygon.SegmentCount() + 1;
1168  std::unique_ptr<GLdouble[]> points( new GLdouble[3 * pointCount] );
1169  GLdouble* ptr = points.get();
1170 
1171  for( int i = 0; i < pointCount; ++i )
1172  {
1173  const VECTOR2I& p = aPolygon.CPoint( i );
1174  *ptr++ = p.x;
1175  *ptr++ = p.y;
1176  *ptr++ = m_layerDepth;
1177  }
1178 
1179  drawPolygon( points.get(), pointCount );
1180 }
void drawPolygon(GLdouble *aPoints, int aPointCount)
Draw a filled polygon.
double m_layerDepth
The actual layer depth.

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()

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 1920 of file opengl_gal.cpp.

1921 {
1922  if( m_isFillEnabled )
1923  {
1926 
1927  // Any non convex polygon needs to be tesselated
1928  // for this purpose the GLU standard functions are used
1929  TessParams params = { m_currentManager, m_tessIntersects };
1930  gluTessBeginPolygon( m_tesselator, &params );
1931  gluTessBeginContour( m_tesselator );
1932 
1933  GLdouble* point = aPoints;
1934 
1935  for( int i = 0; i < aPointCount; ++i )
1936  {
1937  gluTessVertex( m_tesselator, point, point );
1938  point += 3; // 3 coordinates
1939  }
1940 
1941  gluTessEndContour( m_tesselator );
1942  gluTessEndPolygon( m_tesselator );
1943 
1944  // Free allocated intersecting points
1945  m_tessIntersects.clear();
1946  }
1947 
1948  if( m_isStrokeEnabled )
1949  {
1950  drawPolyline(
1951  [&]( int idx )
1952  {
1953  return VECTOR2D( aPoints[idx * 3], aPoints[idx * 3 + 1] );
1954  },
1955  aPointCount );
1956  }
1957 }
bool m_isFillEnabled
Is filling of graphic objects enabled ?
std::deque< boost::shared_array< GLdouble > > m_tessIntersects
Definition: opengl_gal.h:355
double g
Green component.
Definition: color4d.h:378
double b
Blue component.
Definition: color4d.h:379
VERTEX_MANAGER * m_currentManager
Currently used VERTEX_MANAGER (for storing VERTEX_ITEMs).
Definition: opengl_gal.h:319
double a
Alpha component.
Definition: color4d.h:380
bool m_isStrokeEnabled
Are the outlines stroked ?
VECTOR2< double > VECTOR2D
Definition: vector2d.h:622
GLUtesselator * m_tesselator
Definition: opengl_gal.h:354
void Color(const COLOR4D &aColor)
Changes currently used color that will be applied to newly added vertices.
COLOR4D m_fillColor
The fill color.
void drawPolyline(const std::function< VECTOR2D(int)> &aPointGetter, int aPointCount)
Generic way of drawing a polyline stored in different containers.
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.
double r
Red component.
Definition: color4d.h:377

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/3]

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 1004 of file opengl_gal.cpp.

1005 {
1006  drawPolyline(
1007  [&]( int idx )
1008  {
1009  return aPointList[idx];
1010  },
1011  aPointList.size() );
1012 }
void drawPolyline(const std::function< VECTOR2D(int)> &aPointGetter, int aPointCount)
Generic way of drawing a polyline stored in different containers.

References drawPolyline().

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

◆ DrawPolyline() [2/3]

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

Reimplemented from KIGFX::GAL.

Definition at line 1015 of file opengl_gal.cpp.

1016 {
1017  drawPolyline(
1018  [&]( int idx )
1019  {
1020  return aPointList[idx];
1021  },
1022  aListSize );
1023 }
void drawPolyline(const std::function< VECTOR2D(int)> &aPointGetter, int aPointCount)
Generic way of drawing a polyline stored in different containers.

References drawPolyline().

◆ DrawPolyline() [3/3]

void OPENGL_GAL::DrawPolyline ( const SHAPE_LINE_CHAIN aLineChain)
overridevirtual

Reimplemented from KIGFX::GAL.

Definition at line 1026 of file opengl_gal.cpp.

1027 {
1028  auto numPoints = aLineChain.PointCount();
1029 
1030  if( aLineChain.IsClosed() )
1031  numPoints += 1;
1032 
1033  drawPolyline(
1034  [&]( int idx )
1035  {
1036  return aLineChain.CPoint( idx );
1037  },
1038  numPoints );
1039 }
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.
bool IsClosed() const override
void drawPolyline(const std::function< VECTOR2D(int)> &aPointGetter, int aPointCount)
Generic way of drawing a polyline stored in different containers.

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

◆ drawPolyline()

void OPENGL_GAL::drawPolyline ( const std::function< VECTOR2D(int)> &  aPointGetter,
int  aPointCount 
)
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.

Definition at line 1960 of file opengl_gal.cpp.

1961 {
1962  wxCHECK( aPointCount >= 2, /* return */ );
1963 
1965  int i;
1966 
1967  for( i = 1; i < aPointCount; ++i )
1968  {
1969  auto start = aPointGetter( i - 1 );
1970  auto end = aPointGetter( i );
1971 
1972  drawLineQuad( start, end );
1973  }
1974 }
void drawLineQuad(const VECTOR2D &aStartPoint, const VECTOR2D &aEndPoint)
Draw a quad for the line.
double g
Green component.
Definition: color4d.h:378
double b
Blue component.
Definition: color4d.h:379
VERTEX_MANAGER * m_currentManager
Currently used VERTEX_MANAGER (for storing VERTEX_ITEMs).
Definition: opengl_gal.h:319
double a
Alpha component.
Definition: color4d.h:380
COLOR4D m_strokeColor
The color of the outlines.
void Color(const COLOR4D &aColor)
Changes currently used color that will be applied to newly added vertices.
double r
Red component.
Definition: color4d.h:377

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 drawPolygon(), and DrawPolyline().

◆ DrawRectangle()

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 965 of file opengl_gal.cpp.

966 {
967  // Compute the diagonal points of the rectangle
968  VECTOR2D diagonalPointA( aEndPoint.x, aStartPoint.y );
969  VECTOR2D diagonalPointB( aStartPoint.x, aEndPoint.y );
970 
971  // Fill the rectangle
972  if( m_isFillEnabled )
973  {
977 
978  m_currentManager->Vertex( aStartPoint.x, aStartPoint.y, m_layerDepth );
979  m_currentManager->Vertex( diagonalPointA.x, diagonalPointA.y, m_layerDepth );
980  m_currentManager->Vertex( aEndPoint.x, aEndPoint.y, m_layerDepth );
981 
982  m_currentManager->Vertex( aStartPoint.x, aStartPoint.y, m_layerDepth );
983  m_currentManager->Vertex( aEndPoint.x, aEndPoint.y, m_layerDepth );
984  m_currentManager->Vertex( diagonalPointB.x, diagonalPointB.y, m_layerDepth );
985  }
986 
987  // Stroke the outline
988  if( m_isStrokeEnabled )
989  {
991  m_strokeColor.a );
992 
993  std::deque<VECTOR2D> pointList;
994  pointList.push_back( aStartPoint );
995  pointList.push_back( diagonalPointA );
996  pointList.push_back( aEndPoint );
997  pointList.push_back( diagonalPointB );
998  pointList.push_back( aStartPoint );
999  DrawPolyline( pointList );
1000  }
1001 }
bool m_isFillEnabled
Is filling of graphic objects enabled ?
bool Reserve(unsigned int aSize)
Allocate space for vertices, so it will be used with subsequent Vertex() calls.
bool Vertex(const VERTEX &aVertex)
Add a vertex with the given coordinates to the currently set item.
double g
Green component.
Definition: color4d.h:378
double b
Blue component.
Definition: color4d.h:379
double m_layerDepth
The actual layer depth.
VERTEX_MANAGER * m_currentManager
Currently used VERTEX_MANAGER (for storing VERTEX_ITEMs).
Definition: opengl_gal.h:319
double a
Alpha component.
Definition: color4d.h:380
bool m_isStrokeEnabled
Are the outlines stroked ?
COLOR4D m_strokeColor
The color of the outlines.
void Color(const COLOR4D &aColor)
Changes currently used color that will be applied to newly added vertices.
void DrawPolyline(const std::deque< VECTOR2D > &aPointList) override
Draw a polyline.
COLOR4D m_fillColor
The fill color.
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.
double r
Red component.
Definition: color4d.h:377

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 674 of file opengl_gal.cpp.

676 {
677  VECTOR2D startEndVector = aEndPoint - aStartPoint;
678  double lineLength = startEndVector.EuclideanNorm();
679 
680  float startx = aStartPoint.x;
681  float starty = aStartPoint.y;
682  float endx = aStartPoint.x + lineLength;
683  float endy = aStartPoint.y + lineLength;
684 
685  // Be careful about floating point rounding. As we draw segments in larger and larger
686  // coordinates, the shader (which uses floats) will lose precision and stop drawing small
687  // segments. In this case, we need to draw a circle for the minimal segment.
688  if( startx == endx || starty == endy )
689  {
690  DrawCircle( aStartPoint, aWidth / 2 );
691  return;
692  }
693 
694  if( m_isFillEnabled || aWidth == 1.0 )
695  {
697 
698  SetLineWidth( aWidth );
699  drawLineQuad( aStartPoint, aEndPoint );
700  }
701  else
702  {
703  auto lineAngle = startEndVector.Angle();
704  // Outlined tracks
705 
706  SetLineWidth( 1.0 );
708  m_strokeColor.a );
709 
710  Save();
711 
712  m_currentManager->Translate( aStartPoint.x, aStartPoint.y, 0.0 );
713  m_currentManager->Rotate( lineAngle, 0.0f, 0.0f, 1.0f );
714 
715  drawLineQuad( VECTOR2D( 0.0, aWidth / 2.0 ), VECTOR2D( lineLength, aWidth / 2.0 ) );
716 
717  drawLineQuad( VECTOR2D( 0.0, -aWidth / 2.0 ), VECTOR2D( lineLength, -aWidth / 2.0 ) );
718 
719  // Draw line caps
720  drawStrokedSemiCircle( VECTOR2D( 0.0, 0.0 ), aWidth / 2, M_PI / 2 );
721  drawStrokedSemiCircle( VECTOR2D( lineLength, 0.0 ), aWidth / 2, -M_PI / 2 );
722 
723  Restore();
724  }
725 }
bool m_isFillEnabled
Is filling of graphic objects enabled ?
void drawLineQuad(const VECTOR2D &aStartPoint, const VECTOR2D &aEndPoint)
Draw a quad for the line.
void Restore() override
Restore the context.
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 ...
double g
Green component.
Definition: color4d.h:378
virtual void SetLineWidth(float aLineWidth)
Set the line width.
double b
Blue component.
Definition: color4d.h:379
void Save() override
Save the context.
VERTEX_MANAGER * m_currentManager
Currently used VERTEX_MANAGER (for storing VERTEX_ITEMs).
Definition: opengl_gal.h:319
double a
Alpha component.
Definition: color4d.h:380
COLOR4D m_strokeColor
The color of the outlines.
VECTOR2< double > VECTOR2D
Definition: vector2d.h:622
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...
double Angle() const
Compute the angle of the vector.
Definition: vector2d.h:307
void Color(const COLOR4D &aColor)
Changes currently used color that will be applied to newly added vertices.
void drawStrokedSemiCircle(const VECTOR2D &aCenterPoint, double aRadius, double aAngle)
Draw a stroked semicircle.
COLOR4D m_fillColor
The fill color.
T EuclideanNorm() const
Compute the Euclidean norm of the vector, which is defined as sqrt(x ** 2 + y ** 2).
Definition: vector2d.h:293
double r
Red component.
Definition: color4d.h:377
void DrawCircle(const VECTOR2D &aCenterPoint, double aRadius) override
Draw a circle using world coordinates.
Definition: opengl_gal.cpp:728

References KIGFX::COLOR4D::a, VECTOR2< T >::Angle(), 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, Restore(), KIGFX::VERTEX_MANAGER::Rotate(), Save(), KIGFX::GAL::SetLineWidth(), and KIGFX::VERTEX_MANAGER::Translate().

◆ 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 1839 of file opengl_gal.cpp.

1840 {
1841  if( m_isFillEnabled )
1842  {
1844  drawFilledSemiCircle( aCenterPoint, aRadius, aAngle );
1845  }
1846 
1847  if( m_isStrokeEnabled )
1848  {
1850  m_strokeColor.a );
1851  drawStrokedSemiCircle( aCenterPoint, aRadius, aAngle );
1852  }
1853 }
bool m_isFillEnabled
Is filling of graphic objects enabled ?
double g
Green component.
Definition: color4d.h:378
double b
Blue component.
Definition: color4d.h:379
VERTEX_MANAGER * m_currentManager
Currently used VERTEX_MANAGER (for storing VERTEX_ITEMs).
Definition: opengl_gal.h:319
double a
Alpha component.
Definition: color4d.h:380
bool m_isStrokeEnabled
Are the outlines stroked ?
COLOR4D m_strokeColor
The color of the outlines.
void Color(const COLOR4D &aColor)
Changes currently used color that will be applied to newly added vertices.
void drawStrokedSemiCircle(const VECTOR2D &aCenterPoint, double aRadius, double aAngle)
Draw a stroked semicircle.
COLOR4D m_fillColor
The fill color.
double r
Red component.
Definition: color4d.h:377
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 
)
private

Draw a stroked semicircle.

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

Definition at line 1886 of file opengl_gal.cpp.

1888 {
1889  double outerRadius = aRadius + ( m_lineWidth / 2 );
1890 
1891  Save();
1892 
1893  m_currentManager->Reserve( 3 );
1894  m_currentManager->Translate( aCenterPoint.x, aCenterPoint.y, 0.0f );
1895  m_currentManager->Rotate( aAngle, 0.0f, 0.0f, 1.0f );
1896 
1897  /* Draw a triangle that contains the semicircle, then shade it to leave only
1898  * the semicircle. Parameters given to Shader() are indices of the triangle's vertices
1899  * (if you want to understand more, check the vertex shader source [shader.vert]), the
1900  * radius and the line width. Shader uses these coordinates to determine if fragments are
1901  * inside the semicircle or not.
1902  * v2
1903  * /\
1904  * /__\
1905  * v0 //__\\ v1
1906  */
1908  m_currentManager->Vertex( -outerRadius * 3.0f / sqrt( 3.0f ), 0.0f, m_layerDepth ); // v0
1909 
1911  m_currentManager->Vertex( outerRadius * 3.0f / sqrt( 3.0f ), 0.0f, m_layerDepth ); // v1
1912 
1914  m_currentManager->Vertex( 0.0f, outerRadius * 2.0f, m_layerDepth ); // v2
1915 
1916  Restore();
1917 }
bool Reserve(unsigned int aSize)
Allocate space for vertices, so it will be used with subsequent Vertex() calls.
void Restore() override
Restore the context.
bool Vertex(const VERTEX &aVertex)
Add a vertex with the given coordinates to the currently set item.
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 ...
double m_layerDepth
The actual layer depth.
void Save() override
Save the context.
VERTEX_MANAGER * m_currentManager
Currently used VERTEX_MANAGER (for storing VERTEX_ITEMs).
Definition: opengl_gal.h:319
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...
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.
float m_lineWidth
The line width.

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 1078 of file opengl_gal.cpp.

1080 {
1083 
1084  if( m_isFillEnabled )
1085  {
1086  for( unsigned int j = 0; j < aPolySet.TriangulatedPolyCount(); ++j )
1087  {
1088  auto triPoly = aPolySet.TriangulatedPolygon( j );
1089 
1090  for( size_t i = 0; i < triPoly->GetTriangleCount(); i++ )
1091  {
1092  VECTOR2I a, b, c;
1093  triPoly->GetTriangle( i, a, b, c );
1097  }
1098  }
1099  }
1100 
1101  if( m_isStrokeEnabled )
1102  {
1103  for( int j = 0; j < aPolySet.OutlineCount(); ++j )
1104  {
1105  const auto& poly = aPolySet.Polygon( j );
1106 
1107  for( const auto& lc : poly )
1108  {
1109  DrawPolyline( lc );
1110  }
1111  }
1112  }
1113 
1114  if( ADVANCED_CFG::GetCfg().m_DrawTriangulationOutlines )
1115  {
1116  aStrokeTriangulation = true;
1117  SetStrokeColor( COLOR4D( 0.0, 1.0, 0.2, 1.0 ) );
1118  }
1119 
1120  if( aStrokeTriangulation )
1121  {
1122  COLOR4D oldStrokeColor = m_strokeColor;
1123  double oldLayerDepth = m_layerDepth;
1124 
1125  SetLayerDepth( m_layerDepth - 1 );
1126 
1127  for( unsigned int j = 0; j < aPolySet.TriangulatedPolyCount(); ++j )
1128  {
1129  auto triPoly = aPolySet.TriangulatedPolygon( j );
1130 
1131  for( size_t i = 0; i < triPoly->GetTriangleCount(); i++ )
1132  {
1133  VECTOR2I a, b, c;
1134  triPoly->GetTriangle( i, a, b, c );
1135  DrawLine( a, b );
1136  DrawLine( b, c );
1137  DrawLine( c, a );
1138  }
1139  }
1140 
1141  SetStrokeColor( oldStrokeColor );
1142  SetLayerDepth( oldLayerDepth );
1143  }
1144 }
bool m_isFillEnabled
Is filling of graphic objects enabled ?
bool Vertex(const VERTEX &aVertex)
Add a vertex with the given coordinates to the currently set item.
double g
Green component.
Definition: color4d.h:378
virtual void SetLayerDepth(double aLayerDepth)
Set the depth of the layer (position on the z-axis)
double b
Blue component.
Definition: color4d.h:379
double m_layerDepth
The actual layer depth.
VERTEX_MANAGER * m_currentManager
Currently used VERTEX_MANAGER (for storing VERTEX_ITEMs).
Definition: opengl_gal.h:319
double a
Alpha component.
Definition: color4d.h:380
bool m_isStrokeEnabled
Are the outlines stroked ?
COLOR4D m_strokeColor
The color of the outlines.
void DrawLine(const VECTOR2D &aStartPoint, const VECTOR2D &aEndPoint) override
Draw a line.
Definition: opengl_gal.cpp:666
void Color(const COLOR4D &aColor)
Changes currently used color that will be applied to newly added vertices.
void DrawPolyline(const std::deque< VECTOR2D > &aPointList) override
Draw a polyline.
virtual void SetStrokeColor(const COLOR4D &aColor)
Set the stroke color.
COLOR4D m_fillColor
The fill color.
static const ADVANCED_CFG & GetCfg()
Get the singleton instance's config, which is shared by all consumers.
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.
double r
Red component.
Definition: color4d.h:377
A color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:103

References KIGFX::COLOR4D::a, KIGFX::COLOR4D::b, KIGFX::VERTEX_MANAGER::Color(), DrawLine(), DrawPolyline(), KIGFX::COLOR4D::g, ADVANCED_CFG::GetCfg(), 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::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 2342 of file opengl_gal.cpp.

2343 {
2344  m_cachedManager->EnableDepthTest( aEnabled );
2345  m_nonCachedManager->EnableDepthTest( aEnabled );
2346  m_overlayManager->EnableDepthTest( aEnabled );
2347 }
VERTEX_MANAGER * m_overlayManager
Container for storing overlaid VERTEX_ITEMs.
Definition: opengl_gal.h:323
VERTEX_MANAGER * m_cachedManager
Container for storing cached VERTEX_ITEMs.
Definition: opengl_gal.h:321
void EnableDepthTest(bool aEnabled)
Enable/disable Z buffer depth test.
VERTEX_MANAGER * m_nonCachedManager
Container for storing non-cached VERTEX_ITEMs.
Definition: opengl_gal.h:322

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 1753 of file opengl_gal.cpp.

1754 {
1755  glBlendFunc( GL_SRC_ALPHA, GL_ONE );
1757  glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );
1758 }
VERTEX_MANAGER * m_currentManager
Currently used VERTEX_MANAGER (for storing VERTEX_ITEMs).
Definition: opengl_gal.h:319
void EndDrawing() const
Finish drawing operations.

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

◆ endDrawing()

void OPENGL_GAL::endDrawing ( )
overrideprivatevirtual

Update handler for OpenGL settings

Reimplemented from KIGFX::GAL.

Definition at line 576 of file opengl_gal.cpp.

577 {
578  wxASSERT_MSG( m_isContextLocked, "What happened to the context lock?" );
579 
580 #ifdef KICAD_GAL_PROFILE
581  PROF_COUNTER totalRealTime( "OPENGL_GAL::endDrawing()", true );
582 #endif /* KICAD_GAL_PROFILE */
583 
584  // Cached & non-cached containers are rendered to the same buffer
588 
589  // Overlay container is rendered to a different buffer
590  if( m_overlayBuffer )
592 
594 
595  // Be sure that the framebuffer is not colorized (happens on specific GPU&drivers combinations)
596  glColor4d( 1.0, 1.0, 1.0, 1.0 );
597 
598  // Draw the remaining contents, blit the rendering targets to the screen, swap the buffers
600 
601  if( m_overlayBuffer )
603 
605  blitCursor();
606 
607  SwapBuffers();
608 
609 #ifdef KICAD_GAL_PROFILE
610  totalRealTime.Stop();
611  wxLogTrace( traceGalProfile, wxT( "OPENGL_GAL::endDrawing(): %.1f ms" ),
612  totalRealTime.msecs() );
613 #endif /* KICAD_GAL_PROFILE */
614 }
unsigned int m_overlayBuffer
Auxiliary rendering target (for menus etc.)
Definition: opengl_gal.h:328
virtual void DrawBuffer(unsigned int aBufferHandle) override
Draw the selected buffer to the output buffer.
VERTEX_MANAGER * m_overlayManager
Container for storing overlaid VERTEX_ITEMs.
Definition: opengl_gal.h:323
const wxChar *const traceGalProfile
Flag to enable debug output of GAL performance profiling.
unsigned int m_mainBuffer
Main rendering target.
Definition: opengl_gal.h:327
A small class to help profiling.
Definition: profile.h:45
VERTEX_MANAGER * m_cachedManager
Container for storing cached VERTEX_ITEMs.
Definition: opengl_gal.h:321
virtual void Present() override
Call this to present the output buffer to the screen.
OPENGL_COMPOSITOR * m_compositor
Handles multiple rendering targets.
Definition: opengl_gal.h:326
virtual void SetBuffer(unsigned int aBufferHandle) override
Set the selected buffer as the rendering target.
bool m_isContextLocked
Used for assertion checking.
Definition: opengl_gal.h:342
void blitCursor()
Blit cursor into the current screen.
void EndDrawing() const
Finish drawing operations.
VERTEX_MANAGER * m_nonCachedManager
Container for storing non-cached VERTEX_ITEMs.
Definition: opengl_gal.h:322

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

◆ EndGroup()

void OPENGL_GAL::EndGroup ( )
overridevirtual

End the group.

Reimplemented from KIGFX::GAL.

Definition at line 1633 of file opengl_gal.cpp.

1634 {
1636  m_isGrouping = false;
1637 }
VERTEX_MANAGER * m_cachedManager
Container for storing cached VERTEX_ITEMs.
Definition: opengl_gal.h:321
void FinishItem() const
Clean after adding an item.
bool m_isGrouping
Was a group started?
Definition: opengl_gal.h:341

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 853 of file graphics_abstraction_layer.h.

853 {};

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

◆ endUpdate()

void OPENGL_GAL::endUpdate ( )
overrideprivatevirtual

Reimplemented from KIGFX::GAL.

Definition at line 657 of file opengl_gal.cpp.

658 {
659  if( !m_isInitialized )
660  return;
661 
663 }
VERTEX_MANAGER * m_cachedManager
Container for storing cached VERTEX_ITEMs.
Definition: opengl_gal.h:321
void Unmap()
Unmap vertex buffer.
bool m_isInitialized
Basic initialization flag, has to be done when the window is visible.
Definition: opengl_gal.h:339

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 1556 of file opengl_gal.cpp.

1557 {
1558  glFlush();
1559 }

◆ GetClearColor()

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

Definition at line 222 of file graphics_abstraction_layer.h.

223  {
224  return m_clearColor;
225  }

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 267 of file graphics_abstraction_layer.cpp.

268 {
270 
271  // dim the cursor if it's only on because it was forced
272  // (this helps to provide a hint for active tools)
273  if( !m_isCursorEnabled )
274  color.a = color.a * 0.5;
275 
276  return color;
277 }
int color
Definition: DXF_plotter.cpp:57
bool m_isCursorEnabled
Is the cursor enabled?
COLOR4D m_cursorColor
Cursor color.
A color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:103

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

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

◆ GetFillColor()

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

Get the fill color.

Returns
the color for filling a outline.

Definition at line 273 of file graphics_abstraction_layer.h.

274  {
275  return m_fillColor;
276  }
COLOR4D m_fillColor
The fill color.

References KIGFX::GAL::m_fillColor.

◆ GetGlyphSize()

◆ GetGridLineWidth()

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

Get the grid line width.

Returns
the grid line widthDraw the grid

Definition at line 969 of file graphics_abstraction_layer.h.

References KIGFX::GAL::m_gridLineWidth.

◆ GetGridOrigin()

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

Definition at line 894 of file graphics_abstraction_layer.h.

895  {
896  return m_gridOrigin;
897  }
VECTOR2D m_gridOrigin
The grid origin.

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 245 of file graphics_abstraction_layer.cpp.

246 {
247 #if 0
248  // This old code expects a non zero grid size, which can be wrong here.
249  return VECTOR2D( KiROUND( ( aPoint.x - m_gridOffset.x ) / m_gridSize.x ) * m_gridSize.x + m_gridOffset.x,
250  KiROUND( ( aPoint.y - m_gridOffset.y ) / m_gridSize.y ) * m_gridSize.y + m_gridOffset.y );
251 #else
252  // if grid size == 0.0 there is no grid, so use aPoint as grid reference position
253  double cx = m_gridSize.x > 0.0 ? KiROUND( ( aPoint.x - m_gridOffset.x ) / m_gridSize.x ) * m_gridSize.x + m_gridOffset.x
254  : aPoint.x;
255  double cy = m_gridSize.y > 0.0 ? KiROUND( ( aPoint.y - m_gridOffset.y ) / m_gridSize.y ) * m_gridSize.y + m_gridOffset.y
256  : aPoint.y;
257 
258  return VECTOR2D( cx, cy );
259 #endif
260 }
VECTOR2D m_gridSize
The grid size.
VECTOR2< double > VECTOR2D
Definition: vector2d.h:622
VECTOR2D m_gridOffset
The grid offset to compensate cursor position.
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:73

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()

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

◆ GetGridSnapping()

◆ GetGridVisibility()

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

Definition at line 866 of file graphics_abstraction_layer.h.

866 { return m_gridVisibility; }
bool m_gridVisibility
Should the grid be shown.

References KIGFX::GAL::m_gridVisibility.

Referenced by EDA_DRAW_PANEL_GAL::SwitchBackend().

◆ GetHorizontalJustify()

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

Return current text horizontal justification setting.

Definition at line 458 of file graphics_abstraction_layer.h.

459  {
461  }
struct KIGFX::GAL::TEXT_PROPERTIES textProperties
EDA_TEXT_HJUSTIFY_T m_horizontalJustify
Horizontal justification.

References KIGFX::GAL::TEXT_PROPERTIES::m_horizontalJustify, and KIGFX::GAL::textProperties.

Referenced by BitmapText(), KIGFX::SCH_PAINTER::boxText(), and KIGFX::STROKE_FONT::drawSingleLineText().

◆ GetLineWidth()

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

◆ GetLookAtPoint()

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

Get the look at point.

Returns
the look at point.

Definition at line 663 of file graphics_abstraction_layer.h.

664  {
665  return m_lookAtPoint;
666  }
VECTOR2D m_lookAtPoint
Point to be looked at in world space.

References KIGFX::GAL::m_lookAtPoint.

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

◆ GetMaxDepth()

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

Return the maximum depth in the currently used range (the bottom).

Definition at line 732 of file graphics_abstraction_layer.h.

733  {
734  return m_depthRange.y;
735  }
VECTOR2D m_depthRange
Range of the depth.

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

◆ GetMinDepth()

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

Return the minimum depth in the currently used range (the top).

Definition at line 724 of file graphics_abstraction_layer.h.

725  {
726  return m_depthRange.x;
727  }
VECTOR2D m_depthRange
Range of the depth.

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

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

◆ 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 }
double GetScaleFactor() const
Get the current scale factor.

References HIDPI_GL_CANVAS::GetScaleFactor().

Referenced by EDA_3D_CANVAS::DoRePaint(), EDA_3D_MODEL_VIEWER::OnMouseMove(), EDA_3D_CANVAS::OnMouseMove(), 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 }
double GetScaleFactor() const
Get the current scale factor.

References HIDPI_GL_CANVAS::GetScaleFactor().

Referenced by EDA_3D_MODEL_VIEWER::OnMouseMove(), EDA_3D_CANVAS::OnMouseMove(), and EDA_3D_CANVAS::OnMouseWheel().

◆ 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 2188 of file opengl_gal.cpp.

2189 {
2190  wxASSERT_MSG( m_groups.size() < std::numeric_limits<unsigned int>::max(),
2191  wxT( "There are no free slots to store a group" ) );
2192 
2193  while( m_groups.find( m_groupCounter ) != m_groups.end() )
2194  m_groupCounter++;
2195 
2196  return m_groupCounter++;
2197 }
GROUPS_MAP m_groups
Stores information about VBO objects (groups)
Definition: opengl_gal.h:317
unsigned int m_groupCounter
Counter used for generating keys for groups.
Definition: opengl_gal.h:318

References m_groupCounter, and m_groups.

Referenced by BeginGroup().

◆ GetRotation()

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

Get the rotation angle.

Returns
The rotation angle (radians).

Definition at line 703 of file graphics_abstraction_layer.h.

704  {
705  return m_rotation;
706  }
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 410 of file opengl_gal.cpp.

411 {
412  double sf = GetScaleFactor();
413  return VECTOR2D( 2.0 / (double) ( m_screenSize.x * sf ), 2.0 /
414  (double) ( m_screenSize.y * sf ) );
415 }
double GetScaleFactor() const
Get the current scale factor.
VECTOR2< double > VECTOR2D
Definition: vector2d.h:622
VECTOR2I m_screenSize
Screen size in screen coordinates.

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 594 of file graphics_abstraction_layer.h.

595  {
596  return m_screenWorldMatrix;
597  }
MATRIX3x3D m_screenWorldMatrix
Screen transformation.

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 293 of file graphics_abstraction_layer.h.

294  {
295  return m_strokeColor;
296  }
COLOR4D m_strokeColor
The color of the outlines.

References KIGFX::GAL::m_strokeColor.

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

◆ GetStrokeFont()

const STROKE_FONT& KIGFX::GAL::GetStrokeFont ( ) const
inlineinherited

Definition at line 335 of file graphics_abstraction_layer.h.

336  {
337  return m_strokeFont;
338  }
STROKE_FONT m_strokeFont
Instance of object that stores information about how to draw texts.

References KIGFX::GAL::m_strokeFont.

Referenced by KIGFX::SCH_PAINTER::boxText(), and EDA_TEXT::GetTextBox().

◆ 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 1699 of file opengl_gal.cpp.

1700 {
1701  return m_currentTarget;
1702 }
RENDER_TARGET m_currentTarget
Current rendering target.
Definition: opengl_gal.h:329

References m_currentTarget.

Referenced by DrawBitmap().

◆ GetTextLineSize()

VECTOR2D GAL::GetTextLineSize ( const UTF8 aText) const
inherited

Compute the X and Y size of a given text.

The text is expected to be a only one line text.

Parameters
aTextis the text string (one line).
Returns
is the text size.

Definition at line 183 of file graphics_abstraction_layer.cpp.

184 {
185  // Compute the X and Y size of a given text.
186  // Because computeTextLineSize expects a one line text,
187  // aText is expected to be only one line text.
188  return m_strokeFont.computeTextLineSize( aText );
189 }
STROKE_FONT m_strokeFont
Instance of object that stores information about how to draw texts.
VECTOR2D computeTextLineSize(const UTF8 &aText) const
Compute the X and Y size of a given text.

References KIGFX::STROKE_FONT::computeTextLineSize(), and KIGFX::GAL::m_strokeFont.

Referenced by LABEL_MANAGER::Add(), GraphicTextWidth(), and EDA_TEXT::LenSize().

◆ GetVerticalJustify()

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

Returns current text vertical justification setting.

Definition at line 476 of file graphics_abstraction_layer.h.

477  {
479  }
EDA_TEXT_VJUSTIFY_T m_verticalJustify
Vertical justification.
struct KIGFX::GAL::TEXT_PROPERTIES textProperties

References KIGFX::GAL::TEXT_PROPERTIES::m_verticalJustify, and KIGFX::GAL::textProperties.

Referenced by BitmapText(), KIGFX::SCH_PAINTER::boxText(), and KIGFX::STROKE_FONT::Draw().

◆ GetVisibleWorldExtents()

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

Definition at line 222 of file graphics_abstraction_layer.cpp.

223 {
224  const MATRIX3x3D& matrix = GetScreenWorldMatrix();
225 
226  VECTOR2D halfSize = VECTOR2D( matrix.GetScale().x * m_screenSize.x * 0.5,
227  matrix.GetScale().y * m_screenSize.y * 0.5 );
228 
229  BOX2D extents;
230  extents.SetOrigin( GetLookAtPoint() - halfSize );
231  extents.SetSize( halfSize * 2 );
232 
233  return extents;
234 }
const MATRIX3x3D & GetScreenWorldMatrix() const
Get the screen <-> world transformation matrix.
Define a general 2D-vector/point.
Definition: vector2d.h:61
VECTOR2< T > GetScale() const
Get the scale components of the matrix.
Definition: matrix3x3.h:265
VECTOR2< double > VECTOR2D
Definition: vector2d.h:622
const VECTOR2D & GetLookAtPoint() const
Get the look at point.
void SetOrigin(const Vec &pos)
Definition: box2.h:193
VECTOR2I m_screenSize
Screen size in screen coordinates.

References KIGFX::GAL::GetLookAtPoint(), MATRIX3x3< T >::GetScale(), KIGFX::GAL::GetScreenWorldMatrix(), KIGFX::GAL::m_screenSize, BOX2< Vec >::SetOrigin(), 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 403 of file opengl_gal.cpp.

404 {
405  MATRIX3x3D matrix = GetScreenWorldMatrix();
406  return std::min( std::abs( matrix.GetScale().x ), std::abs( matrix.GetScale().y ) );
407 }
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 MATRIX3x3< T >::GetScale(), KIGFX::GAL::GetScreenWorldMatrix(), VECTOR2< T >::x, and VECTOR2< T >::y.

Referenced by beginDrawing(), and DrawGrid().

◆ GetWorldScale()

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

◆ GetWorldScreenMatrix()

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

Get the world <-> screen transformation matrix.

Returns
the transformation matrix.

Definition at line 584 of file graphics_abstraction_layer.h.

585  {
586  return m_worldScreenMatrix;
587  }
MATRIX3x3D m_worldScreenMatrix
World transformation.

References KIGFX::GAL::m_worldScreenMatrix.

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

◆ GetZoomFactor()

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

Get the zoom factor.

Returns
the zoom factor.

Definition at line 683 of file graphics_abstraction_layer.h.

684  {
685  return m_zoomFactor;
686  }
double m_zoomFactor
The zoom factor.

References KIGFX::GAL::m_zoomFactor.

Referenced by COMMON_TOOLS::doZoomInOut(), EDA_DRAW_FRAME::GetZoomLevelIndicator(), EDA_DRAW_FRAME::OnUpdateSelectZoom(), ZOOM_MENU::update(), and EDA_DRAW_FRAME::UpdateZoomSelectBox().

◆ 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 1735 of file opengl_gal.cpp.

1736 {
1737  switch( aTarget )
1738  {
1739  default:
1740  case TARGET_CACHED:
1741  case TARGET_NONCACHED: return true;
1742  case TARGET_OVERLAY: return ( m_overlayBuffer != 0 );
1743  }
1744 }
unsigned int m_overlayBuffer
Auxiliary rendering target (for menus etc.)
Definition: opengl_gal.h:328
Auxiliary rendering target (noncached)
Definition: definitions.h:49
Items that may change while the view stays the same (noncached)
Definition: definitions.h:50
Main rendering target (cached)
Definition: definitions.h:48

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

◆ 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 2200 of file opengl_gal.cpp.

2201 {
2202  wxASSERT( IsShownOnScreen() );
2203 
2204  wxASSERT_MSG( m_isContextLocked, "This should only be called from within a locked context." );
2205 
2206 // IsDisplayAttr() handles WX_GL_{MAJOR,MINOR}_VERSION correctly only in 3.0.4
2207 // starting with 3.1.0 one should use wxGLContext::IsOk() (done by GL_CONTEXT_MANAGER)
2208 #if wxCHECK_VERSION( 3, 0, 3 ) and !wxCHECK_VERSION( 3, 1, 0 )
2209  const int attr[] = { WX_GL_MAJOR_VERSION, 2, WX_GL_MINOR_VERSION, 1, 0 };
2210 
2211  if( !IsDisplaySupported( attr ) )
2212  throw std::runtime_error( "OpenGL 2.1 or higher is required!" );
2213 #endif /* wxCHECK_VERSION( 3, 0, 3 ) */
2214 
2215  // Check correct initialization from the constructor
2216  if( !m_glMainContext )
2217  throw std::runtime_error( "Could not create the main OpenGL context" );
2218 
2219  if( !m_glPrivContext )
2220  throw std::runtime_error( "Could not create a private OpenGL context" );
2221 
2222  if( m_tesselator == nullptr )
2223  throw std::runtime_error( "Could not create the m_tesselator" );
2224  // End initialization checks
2225 
2226  GLenum err = glewInit();
2227 
2228  if( GLEW_OK != err )
2229  throw std::runtime_error( (const char*) glewGetErrorString( err ) );
2230 
2231  // Check the OpenGL version (minimum 2.1 is required)
2232  if( !GLEW_VERSION_2_1 )
2233  throw std::runtime_error( "OpenGL 2.1 or higher is required!" );
2234 
2235 #if defined( __LINUX__ ) // calling enableGlDebug crashes opengl on some OS (OSX and some Windows)
2236 #ifdef DEBUG
2237  if( GLEW_ARB_debug_output )
2238  enableGlDebug( true );
2239 #endif
2240 #endif
2241 
2242  // Framebuffers have to be supported
2243  if( !GLEW_EXT_framebuffer_object )
2244  throw std::runtime_error( "Framebuffer objects are not supported!" );
2245 
2246  // Vertex buffer has to be supported
2247  if( !GLEW_ARB_vertex_buffer_object )
2248  throw std::runtime_error( "Vertex buffer objects are not supported!" );
2249 
2250  // Prepare shaders
2251  if( !m_shader->IsLinked()
2254  {
2255  throw std::runtime_error( "Cannot compile vertex shader!" );
2256  }
2257 
2258  if( !m_shader->IsLinked()
2261  {
2262  throw std::runtime_error( "Cannot compile fragment shader!" );
2263  }
2264 
2265  if( !m_shader->IsLinked() && !m_shader->Link() )
2266  throw std::runtime_error( "Cannot link the shaders!" );
2267 
2268  // Check if video card supports textures big enough to fit the font atlas
2269  int maxTextureSize;
2270  glGetIntegerv( GL_MAX_TEXTURE_SIZE, &maxTextureSize );
2271 
2272  if( maxTextureSize < (int) font_image.width || maxTextureSize < (int) font_image.height )
2273  {
2274  // TODO implement software texture scaling
2275  // for bitmap fonts and use a higher resolution texture?
2276  throw std::runtime_error( "Requested texture size is not supported" );
2277  }
2278 
2280 
2281  m_cachedManager = new VERTEX_MANAGER( true );
2282  m_nonCachedManager = new VERTEX_MANAGER( false );
2283  m_overlayManager = new VERTEX_MANAGER( false );
2284 
2285  // Make VBOs use shaders
2289 
2290  m_isInitialized = true;
2291 }
bool IsLinked() const
Return true if shaders are linked correctly.
Definition: shader.h:118
bool LoadShaderFromStrings(SHADER_TYPE aShaderType, Args &&... aArgs)
Add a shader and compile the shader sources.
Definition: shader.h:93
VERTEX_MANAGER * m_overlayManager
Container for storing overlaid VERTEX_ITEMs.
Definition: opengl_gal.h:323
Fragment shader.
Definition: shader.h:47
bool Link()
Link the shaders.
Definition: shader.cpp:101
VERTEX_MANAGER * m_cachedManager
Container for storing cached VERTEX_ITEMs.
Definition: opengl_gal.h:321
void enableGlDebug(bool aEnable)
Enable or disable OpenGL driver messages output.
Definition: utils.cpp:183
static wxGLContext * m_glMainContext
Parent OpenGL context.
Definition: opengl_gal.h:306
SHADER * m_shader
There is only one shader used for different objects.
Definition: opengl_gal.h:332
bool m_isInitialized
Basic initialization flag, has to be done when the window is visible.
Definition: opengl_gal.h:339
void SetShader(SHADER &aShader) const
Set a shader program that is going to be used during rendering.
GLUtesselator * m_tesselator
Definition: opengl_gal.h:354
FONT_IMAGE_TYPE font_image
Definition: gl_resources.cpp:4
Vertex shader.
Definition: shader.h:46
bool m_isContextLocked
Used for assertion checking.
Definition: opengl_gal.h:342
wxGLContext * m_glPrivContext
Canvas-specific OpenGL context.
Definition: opengl_gal.h:307
Class to control vertex container and GPU with possibility of emulating old-style OpenGL 1....
static int SetSwapInterval(int aVal)
Attempts to set the OpenGL swap interval.
Definition: gl_utils.h:40
VERTEX_MANAGER * m_nonCachedManager
Container for storing non-cached VERTEX_ITEMs.
Definition: opengl_gal.h:322

References enableGlDebug(), KIGFX::BUILTIN_FONT::font_image, KIGFX::BUILTIN_FONT::FONT_IMAGE_TYPE::height, KIGFX::SHADER::IsLinked(), KIGFX::BUILTIN_SHADERS::kicad_fragment_shader, KIGFX::BUILTIN_SHADERS::kicad_vertex_shader, KIGFX::SHADER::Link(), KIGFX::SHADER::LoadShaderFromStrings(), m_cachedManager, m_glMainContext, m_glPrivContext, m_isContextLocked, m_isInitialized, m_nonCachedManager, m_overlayManager, m_shader, 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

Parameters passed to the GLU tesselator.

Reimplemented from KIGFX::GAL.

Definition at line 287 of file opengl_gal.h.

References m_isContextLocked.

◆ IsCursorEnabled()

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

Return information about cursor visibility.

Returns
True if cursor is visible.

Definition at line 1030 of file graphics_abstraction_layer.h.

1031  {
1033  }
bool m_isCursorEnabled
Is the cursor enabled?
bool m_forceDisplayCursor
Always show cursor.

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

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

◆ IsFlippedX()

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

◆ IsFlippedY()

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

Return true if flip flag for the Y axis is set.

Definition at line 770 of file graphics_abstraction_layer.h.

771  {
772  return m_globalFlipY;
773