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) 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 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...
 
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
 
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 const int CIRCLE_POINTS = 64
 The number of points for circle approximation. More...
 
static const int CURVE_POINTS = 32
 The number of points for curve approximation. More...
 
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 66 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 307 of file opengl_gal.h.

◆ super

typedef GAL KIGFX::OPENGL_GAL::super
private

Super class definition.

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

198  :
199  GAL( aDisplayOptions ),
200  HIDPI_GL_CANVAS( aParent, wxID_ANY, (int*) glAttributes, wxDefaultPosition, wxDefaultSize,
201  wxEXPAND, aName ),
202  m_mouseListener( aMouseListener ),
203  m_paintListener( aPaintListener ),
204  m_currentManager( nullptr ),
205  m_cachedManager( nullptr ),
206  m_nonCachedManager( nullptr ),
207  m_overlayManager( nullptr ),
208  m_mainBuffer( 0 ),
209  m_overlayBuffer( 0 ),
210  m_isContextLocked( false ),
211  m_lockClientCookie( 0 )
212 {
213  if( m_glMainContext == nullptr )
214  {
216 
218  }
219  else
220  {
222  }
223 
224  m_shader = new SHADER();
226 
227  m_bitmapCache = std::make_unique<GL_BITMAP_CACHE>();
228 
231 
232  // Initialize the flags
235  m_isInitialized = false;
236  m_isGrouping = false;
237  m_groupCounter = 0;
238 
239  // Connect the native cursor handler
240  Connect( wxEVT_SET_CURSOR, wxSetCursorEventHandler( OPENGL_GAL::onSetNativeCursor ), nullptr,
241  this );
242 
243  // Connecting the event handlers
244  Connect( wxEVT_PAINT, wxPaintEventHandler( OPENGL_GAL::onPaint ) );
245 
246  // Mouse events are skipped to the parent
247  Connect( wxEVT_MOTION, wxMouseEventHandler( OPENGL_GAL::skipMouseEvent ) );
248  Connect( wxEVT_LEFT_DOWN, wxMouseEventHandler( OPENGL_GAL::skipMouseEvent ) );
249  Connect( wxEVT_LEFT_UP, wxMouseEventHandler( OPENGL_GAL::skipMouseEvent ) );
250  Connect( wxEVT_LEFT_DCLICK, wxMouseEventHandler( OPENGL_GAL::skipMouseEvent ) );
251  Connect( wxEVT_MIDDLE_DOWN, wxMouseEventHandler( OPENGL_GAL::skipMouseEvent ) );
252  Connect( wxEVT_MIDDLE_UP, wxMouseEventHandler( OPENGL_GAL::skipMouseEvent ) );
253  Connect( wxEVT_MIDDLE_DCLICK, wxMouseEventHandler( OPENGL_GAL::skipMouseEvent ) );
254  Connect( wxEVT_RIGHT_DOWN, wxMouseEventHandler( OPENGL_GAL::skipMouseEvent ) );
255  Connect( wxEVT_RIGHT_UP, wxMouseEventHandler( OPENGL_GAL::skipMouseEvent ) );
256  Connect( wxEVT_RIGHT_DCLICK, wxMouseEventHandler( OPENGL_GAL::skipMouseEvent ) );
257  Connect( wxEVT_MOUSEWHEEL, wxMouseEventHandler( OPENGL_GAL::skipMouseEvent ) );
258 #if wxCHECK_VERSION( 3, 1, 0 ) || defined( USE_OSX_MAGNIFY_EVENT )
259  Connect( wxEVT_MAGNIFY, wxMouseEventHandler( OPENGL_GAL::skipMouseEvent ) );
260 #endif
261 #if defined _WIN32 || defined _WIN64
262  Connect( wxEVT_ENTER_WINDOW, wxMouseEventHandler( OPENGL_GAL::skipMouseEvent ) );
263 #endif
264 
265  SetSize( aParent->GetClientSize() );
267 
268  // Grid color settings are different in Cairo and OpenGL
269  SetGridColor( COLOR4D( 0.8, 0.8, 0.8, 0.1 ) );
270  SetAxesColor( COLOR4D( BLUE ) );
271 
272  // Tesselator initialization
273  m_tesselator = gluNewTess();
275 
276  gluTessProperty( m_tesselator, GLU_TESS_WINDING_RULE, GLU_TESS_WINDING_POSITIVE );
277 
279 
280  // Avoid uninitialized variables:
281  ufm_worldPixelSize = 1;
285 }
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:320
wxEvtHandler * m_paintListener
Definition: opengl_gal.h:302
static int m_instanceCounter
GL GAL instance counter.
Definition: opengl_gal.h:300
VERTEX_MANAGER * m_overlayManager
Container for storing overlaid VERTEX_ITEMs.
Definition: opengl_gal.h:315
static void InitTesselatorCallbacks(GLUtesselator *aTesselator)
unsigned int m_mainBuffer
Main rendering target.
Definition: opengl_gal.h:319
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:313
Auxiliary rendering target (noncached)
Definition: definitions.h:49
void SetAntialiasingMode(OPENGL_ANTIALIASING_MODE aMode)
wxEvtHandler * m_mouseListener
Definition: opengl_gal.h:301
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:311
static wxGLContext * m_glMainContext
Parent OpenGL context.
Definition: opengl_gal.h:298
SHADER * m_shader
There is only one shader used for different objects.
Definition: opengl_gal.h:324
bool m_isInitialized
Basic initialization flag, has to be done when the window is visible.
Definition: opengl_gal.h:331
void SetAxesColor(const COLOR4D &aAxesColor)
Set the axes color.
OPENGL_COMPOSITOR * m_compositor
Handles multiple rendering targets.
Definition: opengl_gal.h:318
static const int glAttributes[]
Definition: opengl_gal.cpp:80
GLUtesselator * m_tesselator
Definition: opengl_gal.h:346
GLint ufm_antialiasingOffset
Definition: opengl_gal.h:339
void onPaint(wxPaintEvent &aEvent)
This is the OnPaint event handler.
GLint ufm_screenPixelSize
Definition: opengl_gal.h:337
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:334
GLint ufm_worldPixelSize
Definition: opengl_gal.h:336
void SetTarget(RENDER_TARGET aTarget) override
Set the target for rendering.
wxGLContext * m_glPrivContext
Canvas-specific OpenGL context.
Definition: opengl_gal.h:299
Definition: color4d.h:56
bool m_isFramebufferInitialized
Are the framebuffers initialized?
Definition: opengl_gal.h:328
std::unique_ptr< GL_BITMAP_CACHE > m_bitmapCache
Definition: opengl_gal.h:343
unsigned int m_groupCounter
Counter used for generating keys for groups.
Definition: opengl_gal.h:310
bool m_isBitmapFontInitialized
Is the shader set to use bitmap fonts?
Definition: opengl_gal.h:330
VERTEX_MANAGER * m_nonCachedManager
Container for storing non-cached VERTEX_ITEMs.
Definition: opengl_gal.h:314
VECTOR2I m_screenSize
Screen size in screen coordinates.
GLint ufm_pixelSizeMultiplier
Definition: opengl_gal.h:338
void skipMouseEvent(wxMouseEvent &aEvent)
Skip the mouse event to the parent.
bool m_isGrouping
Was a group started?
Definition: opengl_gal.h:333
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 288 of file opengl_gal.cpp.

289 {
291 
293  glFlush();
294  gluDeleteTess( m_tesselator );
295  ClearCache();
296 
297  delete m_compositor;
298 
299  if( m_isInitialized )
300  {
301  delete m_cachedManager;
302  delete m_nonCachedManager;
303  delete m_overlayManager;
304  }
305 
307 
308  // If it was the main context, then it will be deleted
309  // when the last OpenGL GAL instance is destroyed (a few lines below)
312 
313  delete m_shader;
314 
315  // Are we destroying the last GAL instance?
316  if( m_instanceCounter == 0 )
317  {
319 
321  {
322  glDeleteTextures( 1, &g_fontTexture );
323  m_isBitmapFontLoaded = false;
324  }
325 
328  m_glMainContext = nullptr;
329  }
330 }
static bool m_isBitmapFontLoaded
Is the bitmap font texture loaded?
Definition: opengl_gal.h:329
static int m_instanceCounter
GL GAL instance counter.
Definition: opengl_gal.h:300
VERTEX_MANAGER * m_overlayManager
Container for storing overlaid VERTEX_ITEMs.
Definition: opengl_gal.h:315
VERTEX_MANAGER * m_cachedManager
Container for storing cached VERTEX_ITEMs.
Definition: opengl_gal.h:313
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:298
SHADER * m_shader
There is only one shader used for different objects.
Definition: opengl_gal.h:324
bool m_isInitialized
Basic initialization flag, has to be done when the window is visible.
Definition: opengl_gal.h:331
OPENGL_COMPOSITOR * m_compositor
Handles multiple rendering targets.
Definition: opengl_gal.h:318
GLUtesselator * m_tesselator
Definition: opengl_gal.h:346
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:304
wxGLContext * m_glPrivContext
Canvas-specific OpenGL context.
Definition: opengl_gal.h:299
void DestroyCtx(wxGLContext *aContext)
Destroy a managed OpenGL context.
VERTEX_MANAGER * m_nonCachedManager
Container for storing non-cached VERTEX_ITEMs.
Definition: opengl_gal.h:314

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

1023  {
1024  m_layerDepth -= 0.05;
1025  }
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 415 of file opengl_gal.cpp.

416 {
417 #ifdef KICAD_GAL_PROFILE
418  PROF_COUNTER totalRealTime( "OPENGL_GAL::beginDrawing()", true );
419 #endif /* KICAD_GAL_PROFILE */
420 
421  wxASSERT_MSG( m_isContextLocked, "GAL_DRAWING_CONTEXT RAII object should have locked context. "
422  "Calling GAL::beginDrawing() directly is not allowed." );
423 
424  wxASSERT_MSG( IsVisible(), "GAL::beginDrawing() must not be entered when GAL is not visible. "
425  "Other drawing routines will expect everything to be initialized "
426  "which will not be the case." );
427 
428  if( !m_isInitialized )
429  init();
430 
431  // Set up the view port
432  glMatrixMode( GL_PROJECTION );
433  glLoadIdentity();
434 
435  // Create the screen transformation (Do the RH-LH conversion here)
436  glOrtho( 0, (GLint) m_screenSize.x, (GLsizei) m_screenSize.y, 0,
438 
440  {
441  // Prepare rendering target buffers
444  try
445  {
447  }
448  catch( const std::runtime_error& )
449  {
450  wxLogVerbose( "Could not create a framebuffer for overlays.\n" );
451  m_overlayBuffer = 0;
452  }
453 
455  }
456 
457  m_compositor->Begin();
458 
459  // Disable 2D Textures
460  glDisable( GL_TEXTURE_2D );
461 
462  glShadeModel( GL_FLAT );
463 
464  // Enable the depth buffer
465  glEnable( GL_DEPTH_TEST );
466  glDepthFunc( GL_LESS );
467 
468  // Setup blending, required for transparent objects
469  glEnable( GL_BLEND );
470  glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );
471 
472  glMatrixMode( GL_MODELVIEW );
473 
474  // Set up the world <-> screen transformation
476  GLdouble matrixData[16] = { 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1 };
477  matrixData[0] = m_worldScreenMatrix.m_data[0][0];
478  matrixData[1] = m_worldScreenMatrix.m_data[1][0];
479  matrixData[2] = m_worldScreenMatrix.m_data[2][0];
480  matrixData[4] = m_worldScreenMatrix.m_data[0][1];
481  matrixData[5] = m_worldScreenMatrix.m_data[1][1];
482  matrixData[6] = m_worldScreenMatrix.m_data[2][1];
483  matrixData[12] = m_worldScreenMatrix.m_data[0][2];
484  matrixData[13] = m_worldScreenMatrix.m_data[1][2];
485  matrixData[14] = m_worldScreenMatrix.m_data[2][2];
486  glLoadMatrixd( matrixData );
487 
488  // Set defaults
491 
492  // Remove all previously stored items
495 
499 
501  {
502  // Keep bitmap font texture always bound to the second texturing unit
503  const GLint FONT_TEXTURE_UNIT = 2;
504 
505  // Either load the font atlas to video memory, or simply bind it to a texture unit
506  if( !m_isBitmapFontLoaded )
507  {
508  glActiveTexture( GL_TEXTURE0 + FONT_TEXTURE_UNIT );
509  glGenTextures( 1, &g_fontTexture );
510  glBindTexture( GL_TEXTURE_2D, g_fontTexture );
511  glTexImage2D( GL_TEXTURE_2D, 0, GL_RGB8, font_image.width, font_image.height, 0, GL_RGB,
512  GL_UNSIGNED_BYTE, font_image.pixels );
513  glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
514  glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
515  checkGlError( "loading bitmap font", __FILE__, __LINE__ );
516 
517  glActiveTexture( GL_TEXTURE0 );
518 
519  m_isBitmapFontLoaded = true;
520  }
521  else
522  {
523  glActiveTexture( GL_TEXTURE0 + FONT_TEXTURE_UNIT );
524  glBindTexture( GL_TEXTURE_2D, g_fontTexture );
525  glActiveTexture( GL_TEXTURE0 );
526  }
527 
528  // Set shader parameter
529  GLint ufm_fontTexture = m_shader->AddParameter( "fontTexture" );
530  GLint ufm_fontTextureWidth = m_shader->AddParameter( "fontTextureWidth" );
531  ufm_worldPixelSize = m_shader->AddParameter( "worldPixelSize" );
532  ufm_screenPixelSize = m_shader->AddParameter( "screenPixelSize" );
533  ufm_pixelSizeMultiplier = m_shader->AddParameter( "pixelSizeMultiplier" );
534  ufm_antialiasingOffset = m_shader->AddParameter( "antialiasingOffset" );
535 
536  m_shader->Use();
537  m_shader->SetParameter( ufm_fontTexture, (int) FONT_TEXTURE_UNIT );
538  m_shader->SetParameter( ufm_fontTextureWidth, (int) font_image.width );
539  m_shader->Deactivate();
540  checkGlError( "setting bitmap font sampler as shader parameter", __FILE__, __LINE__ );
541 
543  }
544 
545  m_shader->Use();
547  (float) ( getWorldPixelSize() / GetScaleFactor() ) );
548  const VECTOR2D& screenPixelSize = getScreenPixelSize();
549  m_shader->SetParameter( ufm_screenPixelSize, screenPixelSize );
550  double pixelSizeMultiplier = m_compositor->GetAntialiasSupersamplingFactor();
551  m_shader->SetParameter( ufm_pixelSizeMultiplier, (float) pixelSizeMultiplier );
553  renderingOffset.x *= screenPixelSize.x;
554  renderingOffset.y *= screenPixelSize.y;
555  m_shader->SetParameter( ufm_antialiasingOffset, renderingOffset );
556  m_shader->Deactivate();
557 
558  // Something betreen BeginDrawing and EndDrawing seems to depend on
559  // this texture unit being active, but it does not assure it itself.
560  glActiveTexture( GL_TEXTURE0 );
561 
562  // Unbind buffers - set compositor for direct drawing
564 
565 #ifdef KICAD_GAL_PROFILE
566  totalRealTime.Stop();
567  wxLogTrace( traceGalProfile, wxT( "OPENGL_GAL::beginDrawing(): %.1f ms" ),
568  totalRealTime.msecs() );
569 #endif /* KICAD_GAL_PROFILE */
570 }
virtual void SetFillColor(const COLOR4D &aColor)
Set the fill color.
unsigned int m_overlayBuffer
Auxiliary rendering target (for menus etc.)
Definition: opengl_gal.h:320
static bool m_isBitmapFontLoaded
Is the bitmap font texture loaded?
Definition: opengl_gal.h:329
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:315
VECTOR2D getScreenPixelSize() const
Definition: opengl_gal.cpp:407
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:319
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:313
MATRIX3x3D m_worldScreenMatrix
World transformation.
T m_data[3][3]
Definition: matrix3x3.h:64
double getWorldPixelSize() const
Definition: opengl_gal.cpp:400
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:324
bool m_isInitialized
Basic initialization flag, has to be done when the window is visible.
Definition: opengl_gal.h:331
OPENGL_COMPOSITOR * m_compositor
Handles multiple rendering targets.
Definition: opengl_gal.h:318
GLint ufm_antialiasingOffset
Definition: opengl_gal.h:339
int AddParameter(const std::string &aParameterName)
Add a parameter to the parameter queue.
Definition: shader.cpp:130
GLint ufm_screenPixelSize
Definition: opengl_gal.h:337
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:334
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:304
GLint ufm_worldPixelSize
Definition: opengl_gal.h:336
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:328
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:330
VERTEX_MANAGER * m_nonCachedManager
Container for storing non-cached VERTEX_ITEMs.
Definition: opengl_gal.h:314
bool IsVisible() const override
Return true if the GAL canvas is visible on the screen.
Definition: opengl_gal.h:106
VECTOR2I m_screenSize
Screen size in screen coordinates.
GLint ufm_pixelSizeMultiplier
Definition: opengl_gal.h:338
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 1614 of file opengl_gal.cpp.

1615 {
1616  m_isGrouping = true;
1617 
1618  std::shared_ptr<VERTEX_ITEM> newItem = std::make_shared<VERTEX_ITEM>( *m_cachedManager );
1619  int groupNumber = getNewGroupNumber();
1620  m_groups.insert( std::make_pair( groupNumber, newItem ) );
1621 
1622  return groupNumber;
1623 }
GROUPS_MAP m_groups
Stores information about VBO objects (groups)
Definition: opengl_gal.h:309
VERTEX_MANAGER * m_cachedManager
Container for storing cached VERTEX_ITEMs.
Definition: opengl_gal.h:313
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:333

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

◆ beginUpdate()

void OPENGL_GAL::beginUpdate ( )
overrideprivatevirtual

Reimplemented from KIGFX::GAL.

Definition at line 638 of file opengl_gal.cpp.

639 {
640  wxASSERT_MSG( m_isContextLocked, "GAL_UPDATE_CONTEXT RAII object should have locked context. "
641  "Calling this from anywhere else is not allowed." );
642 
643  wxASSERT_MSG( IsVisible(), "GAL::beginUpdate() must not be entered when GAL is not visible. "
644  "Other update routines will expect everything to be initialized "
645  "which will not be the case." );
646 
647  if( !m_isInitialized )
648  init();
649 
650  m_cachedManager->Map();
651 }
VERTEX_MANAGER * m_cachedManager
Container for storing cached VERTEX_ITEMs.
Definition: opengl_gal.h:313
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:331
void Map()
Map vertex buffer.
bool m_isContextLocked
Used for assertion checking.
Definition: opengl_gal.h:334
bool IsVisible() const override
Return true if the GAL canvas is visible on the screen.
Definition: opengl_gal.h:106

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

1252 {
1253  // Fallback to generic impl (which uses the stroke font) on cases we don't handle
1254  if( IsTextMirrored() || aText.Contains( wxT( "^{" ) ) || aText.Contains( wxT( "_{" ) ) )
1255  return GAL::BitmapText( aText, aPosition, aRotationAngle );
1256 
1257  const UTF8 text( aText );
1258  VECTOR2D textSize;
1259  float commonOffset;
1260  std::tie( textSize, commonOffset ) = computeBitmapTextSize( text );
1261 
1262  const double SCALE = 1.4 * GetGlyphSize().y / textSize.y;
1263  int overbarLength = 0;
1264  double overbarHeight = textSize.y;
1265 
1266  Save();
1267 
1269  m_currentManager->Translate( aPosition.x, aPosition.y, m_layerDepth );
1270  m_currentManager->Rotate( aRotationAngle, 0.0f, 0.0f, -1.0f );
1271 
1272  double sx = SCALE * ( m_globalFlipX ? -1.0 : 1.0 );
1273  double sy = SCALE * ( m_globalFlipY ? -1.0 : 1.0 );
1274 
1275  m_currentManager->Scale( sx, sy, 0 );
1276  m_currentManager->Translate( 0, -commonOffset, 0 );
1277 
1278  switch( GetHorizontalJustify() )
1279  {
1281  Translate( VECTOR2D( -textSize.x / 2.0, 0 ) );
1282  break;
1283 
1285  //if( !IsTextMirrored() )
1286  Translate( VECTOR2D( -textSize.x, 0 ) );
1287  break;
1288 
1289  case GR_TEXT_HJUSTIFY_LEFT:
1290  //if( IsTextMirrored() )
1291  //Translate( VECTOR2D( -textSize.x, 0 ) );
1292  break;
1293  }
1294 
1295  switch( GetVerticalJustify() )
1296  {
1297  case GR_TEXT_VJUSTIFY_TOP:
1298  Translate( VECTOR2D( 0, -textSize.y ) );
1299  overbarHeight = -textSize.y / 2.0;
1300  break;
1301 
1303  Translate( VECTOR2D( 0, -textSize.y / 2.0 ) );
1304  overbarHeight = 0;
1305  break;
1306 
1308  break;
1309  }
1310 
1311  int overbarDepth = -1;
1312  int braceNesting = 0;
1313 
1314  for( UTF8::uni_iter chIt = text.ubegin(), end = text.uend(); chIt < end; ++chIt )
1315  {
1316  wxASSERT_MSG( *chIt != '\n' && *chIt != '\r',
1317  wxT( "No support for multiline bitmap text yet" ) );
1318 
1319  if( *chIt == '~' && overbarDepth == -1 )
1320  {
1321  UTF8::uni_iter lookahead = chIt;
1322 
1323  if( ++lookahead != end && *lookahead == '{' )
1324  {
1325  chIt = lookahead;
1326  overbarDepth = braceNesting;
1327  braceNesting++;
1328  continue;
1329  }
1330  }
1331  else if( *chIt == '{' )
1332  {
1333  braceNesting++;
1334  }
1335  else if( *chIt == '}' )
1336  {
1337  if( braceNesting > 0 )
1338  braceNesting--;
1339 
1340  if( braceNesting == overbarDepth )
1341  {
1342  drawBitmapOverbar( overbarLength, overbarHeight );
1343  overbarLength = 0;
1344 
1345  overbarDepth = -1;
1346  continue;
1347  }
1348  }
1349 
1350  if( overbarDepth != -1 )
1351  overbarLength += drawBitmapChar( *chIt );
1352  else
1353  drawBitmapChar( *chIt );
1354  }
1355 
1356  // Handle the case when overbar is active till the end of the drawn text
1357  m_currentManager->Translate( 0, commonOffset, 0 );
1358 
1359  if( overbarDepth != -1 && overbarLength > 0 )
1360  drawBitmapOverbar( overbarLength, overbarHeight );
1361 
1362  Restore();
1363 }
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:364
EDA_TEXT_HJUSTIFY_T GetHorizontalJustify() const
Return current text horizontal justification setting.
double b
Blue component.
Definition: color4d.h:365
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:311
double a
Alpha component.
Definition: color4d.h:366
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:363
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 2145 of file opengl_gal.cpp.

2146 {
2147  if( !IsCursorEnabled() )
2148  return;
2149 
2151 
2152  const int cursorSize = m_fullscreenCursor ? 8000 : 80;
2153 
2154  VECTOR2D cursorBegin = m_cursorPosition - cursorSize / ( 2 * m_worldScale );
2155  VECTOR2D cursorEnd = m_cursorPosition + cursorSize / ( 2 * m_worldScale );
2156  VECTOR2D cursorCenter = ( cursorBegin + cursorEnd ) / 2;
2157 
2158  const COLOR4D cColor = getCursorColor();
2159  const COLOR4D color( cColor.r * cColor.a, cColor.g * cColor.a, cColor.b * cColor.a, 1.0 );
2160 
2161  glActiveTexture( GL_TEXTURE0 );
2162  glDisable( GL_TEXTURE_2D );
2163  glLineWidth( 1.0 );
2164  glColor4d( color.r, color.g, color.b, color.a );
2165 
2166  glBegin( GL_LINES );
2167  glVertex2d( cursorCenter.x, cursorBegin.y );
2168  glVertex2d( cursorCenter.x, cursorEnd.y );
2169 
2170  glVertex2d( cursorBegin.x, cursorCenter.y );
2171  glVertex2d( cursorEnd.x, cursorCenter.y );
2172  glEnd();
2173 }
int color
Definition: DXF_plotter.cpp:60
double g
Green component.
Definition: color4d.h:364
static const unsigned int DIRECT_RENDERING
double b
Blue component.
Definition: color4d.h:365
double m_worldScale
The scale factor world->screen.
VECTOR2D m_cursorPosition
Current cursor position (world coordinates)
double a
Alpha component.
Definition: color4d.h:366
OPENGL_COMPOSITOR * m_compositor
Handles multiple rendering targets.
Definition: opengl_gal.h:318
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:363
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 503 of file opengl_gal.h.

504  {
505  // Bigger arcs need smaller alpha increment to make them look smooth
506  return std::min( 1e6 / aRadius, 2.0 * M_PI / CIRCLE_POINTS );
507  }
CIRCLE_POINTS

Referenced by DrawArc(), and DrawArcSegment().

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

1643 {
1644  auto group = m_groups.find( aGroupNumber );
1645 
1646  if( group != m_groups.end() )
1647  m_cachedManager->ChangeItemColor( *group->second, aNewColor );
1648 }
GROUPS_MAP m_groups
Stores information about VBO objects (groups)
Definition: opengl_gal.h:309
VERTEX_MANAGER * m_cachedManager
Container for storing cached VERTEX_ITEMs.
Definition: opengl_gal.h:313
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 1651 of file opengl_gal.cpp.

1652 {
1653  auto group = m_groups.find( aGroupNumber );
1654 
1655  if( group != m_groups.end() )
1656  m_cachedManager->ChangeItemDepth( *group->second, aDepth );
1657 }
GROUPS_MAP m_groups
Stores information about VBO objects (groups)
Definition: opengl_gal.h:309
VERTEX_MANAGER * m_cachedManager
Container for storing cached VERTEX_ITEMs.
Definition: opengl_gal.h:313
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 333 of file opengl_gal.cpp.

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

1668 {
1669  m_bitmapCache = std::make_unique<GL_BITMAP_CACHE>();
1670 
1671  m_groups.clear();
1672 
1673  if( m_isInitialized )
1675 }
GROUPS_MAP m_groups
Stores information about VBO objects (groups)
Definition: opengl_gal.h:309
VERTEX_MANAGER * m_cachedManager
Container for storing cached VERTEX_ITEMs.
Definition: opengl_gal.h:313
bool m_isInitialized
Basic initialization flag, has to be done when the window is visible.
Definition: opengl_gal.h:331
std::unique_ptr< GL_BITMAP_CACHE > m_bitmapCache
Definition: opengl_gal.h:343
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 1555 of file opengl_gal.cpp.

1556 {
1557  // Clear screen
1559 
1560  // NOTE: Black used here instead of m_clearColor; it will be composited later
1561  glClearColor( 0, 0, 0, 1 );
1562  glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT );
1563 }
static const unsigned int DIRECT_RENDERING
OPENGL_COMPOSITOR * m_compositor
Handles multiple rendering targets.
Definition: opengl_gal.h:318
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 1698 of file opengl_gal.cpp.

1699 {
1700  // Save the current state
1701  unsigned int oldTarget = m_compositor->GetBuffer();
1702 
1703  switch( aTarget )
1704  {
1705  // Cached and noncached items are rendered to the same buffer
1706  default:
1707  case TARGET_CACHED:
1708  case TARGET_NONCACHED:
1710  break;
1711 
1712  case TARGET_OVERLAY:
1713  if( m_overlayBuffer )
1715  break;
1716  }
1717 
1718  if( aTarget != TARGET_OVERLAY )
1720  else if( m_overlayBuffer )
1722 
1723  // Restore the previous state
1724  m_compositor->SetBuffer( oldTarget );
1725 }
unsigned int m_overlayBuffer
Auxiliary rendering target (for menus etc.)
Definition: opengl_gal.h:320
static const COLOR4D BLACK
Definition: color4d.h:373
unsigned int m_mainBuffer
Main rendering target.
Definition: opengl_gal.h:319
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:318
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 2062 of file opengl_gal.cpp.

2063 {
2064  static const FONT_GLYPH_TYPE* defaultGlyph = LookupGlyph( '(' ); // for strange chars
2065  static const FONT_GLYPH_TYPE* lineGlyph = LookupGlyph( '_' ); // for overbar thickness
2066 
2067  VECTOR2D textSize( 0, 0 );
2068  float commonOffset = std::numeric_limits<float>::max();
2069  float charHeight = font_information.max_y - defaultGlyph->miny;
2070  int overbarDepth = -1;
2071  int braceNesting = 0;
2072 
2073  for( UTF8::uni_iter chIt = aText.ubegin(), end = aText.uend(); chIt < end; ++chIt )
2074  {
2075  if( *chIt == '~' && overbarDepth == -1 )
2076  {
2077  UTF8::uni_iter lookahead = chIt;
2078 
2079  if( ++lookahead != end && *lookahead == '{' )
2080  {
2081  chIt = lookahead;
2082  overbarDepth = braceNesting;
2083  braceNesting++;
2084  continue;
2085  }
2086  }
2087  else if( *chIt == '{' )
2088  {
2089  braceNesting++;
2090  }
2091  else if( *chIt == '}' )
2092  {
2093  if( braceNesting > 0 )
2094  braceNesting--;
2095 
2096  if( braceNesting == overbarDepth )
2097  {
2098  overbarDepth = -1;
2099  continue;
2100  }
2101  }
2102 
2103  const FONT_GLYPH_TYPE* glyph = LookupGlyph( *chIt );
2104 
2105  if( !glyph // Not coded in font
2106  || *chIt == '-' || *chIt == '_' ) // Strange size of these 2 chars
2107  {
2108  glyph = defaultGlyph;
2109  }
2110 
2111  if( glyph )
2112  {
2113  textSize.x += glyph->advance;
2114 
2115  if( overbarDepth != -1 )
2116  {
2117  const float H = lineGlyph->maxy - lineGlyph->miny;
2118  textSize.y = std::max<float>( textSize.y, charHeight + 1.5 * H );
2119  }
2120  }
2121  }
2122 
2123  textSize.y = std::max<float>( textSize.y, charHeight );
2124  commonOffset = std::min<float>( font_information.max_y - defaultGlyph->maxy, commonOffset );
2125  textSize.y -= commonOffset;
2126 
2127  return std::make_pair( textSize, commonOffset );
2128 }
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
#define H(x, y, z)
Definition: md5_hash.cpp:17
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, H, 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 1077 of file graphics_abstraction_layer.h.

1078  {
1080  }
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 2344 of file opengl_gal.cpp.

2345 {
2347  auto pixelSize = m_worldScale;
2348 
2349  // we need -m_lookAtPoint == -k * pixelSize + 0.5 * pixelSize for OpenGL
2350  // meaning m_lookAtPoint = (k-0.5)*pixelSize with integer k
2353 
2355 }
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 1660 of file opengl_gal.cpp.

1661 {
1662  // Frees memory in the container as well
1663  m_groups.erase( aGroupNumber );
1664 }
GROUPS_MAP m_groups
Stores information about VBO objects (groups)
Definition: opengl_gal.h:309

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

784 {
785  if( aRadius <= 0 )
786  return;
787 
788  // Swap the angles, if start angle is greater than end angle
789  SWAP( aStartAngle, >, aEndAngle );
790 
791  const double alphaIncrement = calcAngleStep( aRadius );
792 
793  Save();
794  m_currentManager->Translate( aCenterPoint.x, aCenterPoint.y, 0.0 );
795 
796  if( m_isFillEnabled )
797  {
798  double alpha;
801 
802  // Triangle fan
803  for( alpha = aStartAngle; ( alpha + alphaIncrement ) < aEndAngle; )
804  {
806  m_currentManager->Vertex( 0.0, 0.0, m_layerDepth );
807  m_currentManager->Vertex( cos( alpha ) * aRadius, sin( alpha ) * aRadius,
808  m_layerDepth );
809  alpha += alphaIncrement;
810  m_currentManager->Vertex( cos( alpha ) * aRadius, sin( alpha ) * aRadius,
811  m_layerDepth );
812  }
813 
814  // The last missing triangle
815  const VECTOR2D endPoint( cos( aEndAngle ) * aRadius, sin( aEndAngle ) * aRadius );
816 
818  m_currentManager->Vertex( 0.0, 0.0, m_layerDepth );
819  m_currentManager->Vertex( cos( alpha ) * aRadius, sin( alpha ) * aRadius, m_layerDepth );
820  m_currentManager->Vertex( endPoint.x, endPoint.y, m_layerDepth );
821  }
822 
823  if( m_isStrokeEnabled )
824  {
826  m_strokeColor.a );
827 
828  VECTOR2D p( cos( aStartAngle ) * aRadius, sin( aStartAngle ) * aRadius );
829  double alpha;
830 
831  for( alpha = aStartAngle + alphaIncrement; alpha <= aEndAngle; alpha += alphaIncrement )
832  {
833  VECTOR2D p_next( cos( alpha ) * aRadius, sin( alpha ) * aRadius );
834  DrawLine( p, p_next );
835 
836  p = p_next;
837  }
838 
839  // Draw the last missing part
840  if( alpha != aEndAngle )
841  {
842  VECTOR2D p_last( cos( aEndAngle ) * aRadius, sin( aEndAngle ) * aRadius );
843  DrawLine( p, p_last );
844  }
845  }
846 
847  Restore();
848 }
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:364
double b
Blue component.
Definition: color4d.h:365
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:311
double a
Alpha component.
Definition: color4d.h:366
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:503
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:663
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:363

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

Reimplemented from KIGFX::GAL.

Definition at line 851 of file opengl_gal.cpp.

853 {
854  if( aRadius <= 0 )
855  {
856  // Arcs of zero radius are a circle of aWidth diameter
857  if( aWidth > 0 )
858  DrawCircle( aCenterPoint, aWidth / 2.0 );
859 
860  return;
861  }
862 
863  // Swap the angles, if start angle is greater than end angle
864  SWAP( aStartAngle, >, aEndAngle );
865 
866  double alphaIncrement = calcAngleStep( aRadius );
867 
868  // Refinement: Use a segment count multiple of 2, because we have a control point
869  // on the middle of the arc, and the look is better if it is on a segment junction
870  // because there is no approx error
871  int seg_count = KiROUND( ( aEndAngle - aStartAngle ) / alphaIncrement );
872 
873  if( seg_count % 2 != 0 )
874  seg_count += 1;
875 
876  // Recalculate alphaIncrement with a even integer number of segment
877  if( seg_count )
878  alphaIncrement = ( aEndAngle - aStartAngle ) / seg_count;
879 
880  Save();
881  m_currentManager->Translate( aCenterPoint.x, aCenterPoint.y, 0.0 );
882 
883  if( m_isStrokeEnabled )
884  {
886  m_strokeColor.a );
887 
888  double width = aWidth / 2.0;
889  VECTOR2D startPoint( cos( aStartAngle ) * aRadius, sin( aStartAngle ) * aRadius );
890  VECTOR2D endPoint( cos( aEndAngle ) * aRadius, sin( aEndAngle ) * aRadius );
891 
892  drawStrokedSemiCircle( startPoint, width, aStartAngle + M_PI );
893  drawStrokedSemiCircle( endPoint, width, aEndAngle );
894 
895  VECTOR2D pOuter( cos( aStartAngle ) * ( aRadius + width ),
896  sin( aStartAngle ) * ( aRadius + width ) );
897 
898  VECTOR2D pInner( cos( aStartAngle ) * ( aRadius - width ),
899  sin( aStartAngle ) * ( aRadius - width ) );
900 
901  double alpha;
902 
903  for( alpha = aStartAngle + alphaIncrement; alpha <= aEndAngle; alpha += alphaIncrement )
904  {
905  VECTOR2D pNextOuter( cos( alpha ) * ( aRadius + width ),
906  sin( alpha ) * ( aRadius + width ) );
907  VECTOR2D pNextInner( cos( alpha ) * ( aRadius - width ),
908  sin( alpha ) * ( aRadius - width ) );
909 
910  DrawLine( pOuter, pNextOuter );
911  DrawLine( pInner, pNextInner );
912 
913  pOuter = pNextOuter;
914  pInner = pNextInner;
915  }
916 
917  // Draw the last missing part
918  if( alpha != aEndAngle )
919  {
920  VECTOR2D pLastOuter( cos( aEndAngle ) * ( aRadius + width ),
921  sin( aEndAngle ) * ( aRadius + width ) );
922  VECTOR2D pLastInner( cos( aEndAngle ) * ( aRadius - width ),
923  sin( aEndAngle ) * ( aRadius - width ) );
924 
925  DrawLine( pOuter, pLastOuter );
926  DrawLine( pInner, pLastInner );
927  }
928  }
929 
930  if( m_isFillEnabled )
931  {
933  SetLineWidth( aWidth );
934 
935  VECTOR2D p( cos( aStartAngle ) * aRadius, sin( aStartAngle ) * aRadius );
936  double alpha;
937 
938  for( alpha = aStartAngle + alphaIncrement; alpha <= aEndAngle; alpha += alphaIncrement )
939  {
940  VECTOR2D p_next( cos( alpha ) * aRadius, sin( alpha ) * aRadius );
941  DrawLine( p, p_next );
942 
943  p = p_next;
944  }
945 
946  // Draw the last missing part
947  if( alpha != aEndAngle )
948  {
949  VECTOR2D p_last( cos( aEndAngle ) * aRadius, sin( aEndAngle ) * aRadius );
950  DrawLine( p, p_last );
951  }
952  }
953 
954  Restore();
955 }
bool m_isFillEnabled
Is filling of graphic objects enabled ?
void Restore() override
Restore the context.
double g
Green component.
Definition: color4d.h:364
virtual void SetLineWidth(float aLineWidth)
Set the line width.
double b
Blue component.
Definition: color4d.h:365
void Save() override
Save the context.
VERTEX_MANAGER * m_currentManager
Currently used VERTEX_MANAGER (for storing VERTEX_ITEMs).
Definition: opengl_gal.h:311
double a
Alpha component.
Definition: color4d.h:366
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:503
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:663
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
double r
Red component.
Definition: color4d.h:363
void DrawCircle(const VECTOR2D &aCenterPoint, double aRadius) override
Draw a circle using world coordinates.
Definition: opengl_gal.cpp:725

References KIGFX::COLOR4D::a, KIGFX::COLOR4D::b, calcAngleStep(), KIGFX::VERTEX_MANAGER::Color(), DrawCircle(), DrawLine(), drawStrokedSemiCircle(), KIGFX::COLOR4D::g, KiROUND(), m_currentManager, KIGFX::GAL::m_fillColor, KIGFX::GAL::m_isFillEnabled, KIGFX::GAL::m_isStrokeEnabled, KIGFX::GAL::m_strokeColor, KIGFX::COLOR4D::r, Restore(), Save(), 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 1195 of file opengl_gal.cpp.

1196 {
1197  // We have to calculate the pixel size in users units to draw the image.
1198  // m_worldUnitLength is a factor used for converting IU to inches
1199  double scale = 1.0 / ( aBitmap.GetPPI() * m_worldUnitLength );
1200  double w = (double) aBitmap.GetSizePixels().x * scale;
1201  double h = (double) aBitmap.GetSizePixels().y * scale;
1202 
1203  auto xform = m_currentManager->GetTransformation();
1204 
1205  glm::vec4 v0 = xform * glm::vec4( -w / 2, -h / 2, 0.0, 0.0 );
1206  glm::vec4 v1 = xform * glm::vec4( w / 2, h / 2, 0.0, 0.0 );
1207  glm::vec4 trans = xform[3];
1208 
1209  auto texture_id = m_bitmapCache->RequestBitmap( &aBitmap );
1210 
1211  if( !glIsTexture( texture_id ) ) // ensure the bitmap texture is still valid
1212  return;
1213 
1214  auto oldTarget = GetTarget();
1215 
1216  glPushMatrix();
1217  glTranslated( trans.x, trans.y, trans.z );
1218 
1220  glEnable( GL_TEXTURE_2D );
1221  glActiveTexture( GL_TEXTURE0 );
1222  glBindTexture( GL_TEXTURE_2D, texture_id );
1223 
1224  glBegin( GL_QUADS );
1225  glColor4f( 1.0, 1.0, 1.0, 1.0 );
1226  glTexCoord2f( 0.0, 0.0 );
1227  glVertex3f( v0.x, v0.y, m_layerDepth );
1228  glColor4f( 1.0, 1.0, 1.0, 1.0 );
1229  glTexCoord2f( 1.0, 0.0 );
1230  glVertex3f( v1.x, v0.y, m_layerDepth );
1231  glColor4f( 1.0, 1.0, 1.0, 1.0 );
1232  glTexCoord2f( 1.0, 1.0 );
1233  glVertex3f( v1.x, v1.y, m_layerDepth );
1234  glColor4f( 1.0, 1.0, 1.0, 1.0 );
1235  glTexCoord2f( 0.0, 1.0 );
1236  glVertex3f( v0.x, v1.y, m_layerDepth );
1237  glEnd();
1238 
1239  SetTarget( oldTarget );
1240  glBindTexture( GL_TEXTURE_2D, 0 );
1241 
1242 #ifdef DISABLE_BITMAP_CACHE
1243  glDeleteTextures( 1, &texture_id );
1244 #endif
1245 
1246  glPopMatrix();
1247 }
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:311
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:343
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 1956 of file opengl_gal.cpp.

1957 {
1958  const float TEX_X = font_image.width;
1959  const float TEX_Y = font_image.height;
1960 
1961  // handle space
1962  if( aChar == ' ' )
1963  {
1964  const FONT_GLYPH_TYPE* g = LookupGlyph( 'x' );
1965  wxASSERT( g );
1966 
1967  if( !g ) // Should not happen.
1968  return 0;
1969 
1970  Translate( VECTOR2D( g->advance, 0 ) );
1971  return g->advance;
1972  }
1973 
1974  const FONT_GLYPH_TYPE* glyph = LookupGlyph( aChar );
1975 
1976  // If the glyph is not found (happens for many esoteric unicode chars)
1977  // shows a '?' instead.
1978  if( !glyph )
1979  glyph = LookupGlyph( '?' );
1980 
1981  if( !glyph ) // Should not happen.
1982  return 0;
1983 
1984  const float X = glyph->atlas_x + font_information.smooth_pixels;
1985  const float Y = glyph->atlas_y + font_information.smooth_pixels;
1986  const float XOFF = glyph->minx;
1987 
1988  // adjust for height rounding
1989  const float round_adjust = ( glyph->maxy - glyph->miny )
1990  - float( glyph->atlas_h - font_information.smooth_pixels * 2 );
1991  const float top_adjust = font_information.max_y - glyph->maxy;
1992  const float YOFF = round_adjust + top_adjust;
1993  const float W = glyph->atlas_w - font_information.smooth_pixels * 2;
1994  const float H = glyph->atlas_h - font_information.smooth_pixels * 2;
1995  const float B = 0;
1996 
1997  m_currentManager->Reserve( 6 );
1998  Translate( VECTOR2D( XOFF, YOFF ) );
1999 
2000  /* Glyph:
2001  * v0 v1
2002  * +--+
2003  * | /|
2004  * |/ |
2005  * +--+
2006  * v2 v3
2007  */
2008  m_currentManager->Shader( SHADER_FONT, X / TEX_X, ( Y + H ) / TEX_Y );
2009  m_currentManager->Vertex( -B, -B, 0 ); // v0
2010 
2011  m_currentManager->Shader( SHADER_FONT, ( X + W ) / TEX_X, ( Y + H ) / TEX_Y );
2012  m_currentManager->Vertex( W + B, -B, 0 ); // v1
2013 
2014  m_currentManager->Shader( SHADER_FONT, X / TEX_X, Y / TEX_Y );
2015  m_currentManager->Vertex( -B, H + B, 0 ); // v2
2016 
2017 
2018  m_currentManager->Shader( SHADER_FONT, ( X + W ) / TEX_X, ( Y + H ) / TEX_Y );
2019  m_currentManager->Vertex( W + B, -B, 0 ); // v1
2020 
2021  m_currentManager->Shader( SHADER_FONT, X / TEX_X, Y / TEX_Y );
2022  m_currentManager->Vertex( -B, H + B, 0 ); // v2
2023 
2024  m_currentManager->Shader( SHADER_FONT, ( X + W ) / TEX_X, Y / TEX_Y );
2025  m_currentManager->Vertex( W + B, H + B, 0 ); // v3
2026 
2027  Translate( VECTOR2D( -XOFF + glyph->advance, -YOFF ) );
2028 
2029  return glyph->advance;
2030 }
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:311
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 2033 of file opengl_gal.cpp.

2034 {
2035  // To draw an overbar, simply draw an overbar
2036  const FONT_GLYPH_TYPE* glyph = LookupGlyph( '_' );
2037  wxCHECK( glyph, /* void */ );
2038 
2039  const float H = glyph->maxy - glyph->miny;
2040 
2041  Save();
2042 
2043  Translate( VECTOR2D( -aLength, -aHeight - 1.5 * H ) );
2044 
2045  m_currentManager->Reserve( 6 );
2047 
2048  m_currentManager->Shader( 0 );
2049 
2050  m_currentManager->Vertex( 0, 0, 0 ); // v0
2051  m_currentManager->Vertex( aLength, 0, 0 ); // v1
2052  m_currentManager->Vertex( 0, H, 0 ); // v2
2053 
2054  m_currentManager->Vertex( aLength, 0, 0 ); // v1
2055  m_currentManager->Vertex( 0, H, 0 ); // v2
2056  m_currentManager->Vertex( aLength, H, 0 ); // v3
2057 
2058  Restore();
2059 }
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:364
const FONT_GLYPH_TYPE * LookupGlyph(unsigned int aCodepoint)
double b
Blue component.
Definition: color4d.h:365
void Save() override
Save the context.
VERTEX_MANAGER * m_currentManager
Currently used VERTEX_MANAGER (for storing VERTEX_ITEMs).
Definition: opengl_gal.h:311
double a
Alpha component.
Definition: color4d.h:366
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:363

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

726 {
727  if( m_isFillEnabled )
728  {
731 
732  /* Draw a triangle that contains the circle, then shade it leaving only the circle.
733  * Parameters given to Shader() are indices of the triangle's vertices
734  * (if you want to understand more, check the vertex shader source [shader.vert]).
735  * Shader uses this coordinates to determine if fragments are inside the circle or not.
736  * Does the calculations in the vertex shader now (pixel alignment)
737  * v2
738  * /\
739  * //\\
740  * v0 /_\/_\ v1
741  */
742  m_currentManager->Shader( SHADER_FILLED_CIRCLE, 1.0, aRadius );
743  m_currentManager->Vertex( aCenterPoint.x, aCenterPoint.y, m_layerDepth );
744 
745  m_currentManager->Shader( SHADER_FILLED_CIRCLE, 2.0, aRadius );
746  m_currentManager->Vertex( aCenterPoint.x, aCenterPoint.y, m_layerDepth );
747 
748  m_currentManager->Shader( SHADER_FILLED_CIRCLE, 3.0, aRadius );
749  m_currentManager->Vertex( aCenterPoint.x, aCenterPoint.y, m_layerDepth );
750  }
751  if( m_isStrokeEnabled )
752  {
755  m_strokeColor.a );
756 
757  /* Draw a triangle that contains the circle, then shade it leaving only the circle.
758  * Parameters given to Shader() are indices of the triangle's vertices
759  * (if you want to understand more, check the vertex shader source [shader.vert]).
760  * and the line width. Shader uses this coordinates to determine if fragments are
761  * inside the circle or not.
762  * v2
763  * /\
764  * //\\
765  * v0 /_\/_\ v1
766  */
768  m_currentManager->Vertex( aCenterPoint.x, // v0
769  aCenterPoint.y, m_layerDepth );
770 
772  m_currentManager->Vertex( aCenterPoint.x, // v1
773  aCenterPoint.y, m_layerDepth );
774 
776  m_currentManager->Vertex( aCenterPoint.x, aCenterPoint.y, // v2
777  m_layerDepth );
778  }
779 }
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:364
double b
Blue component.
Definition: color4d.h:365
double m_layerDepth
The actual layer depth.
VERTEX_MANAGER * m_currentManager
Currently used VERTEX_MANAGER (for storing VERTEX_ITEMs).
Definition: opengl_gal.h:311
double a
Alpha component.
Definition: color4d.h:366
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:363
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 1761 of file opengl_gal.cpp.

1762 {
1763  // Now we should only store the position of the mouse cursor
1764  // The real drawing routines are in blitCursor()
1765  //VECTOR2D screenCursor = m_worldScreenMatrix * aCursorPosition;
1766  //m_cursorPosition = m_screenWorldMatrix * VECTOR2D( screenCursor.x, screenCursor.y );
1767  m_cursorPosition = aCursorPosition;
1768 }
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 1176 of file opengl_gal.cpp.

1179 {
1180  std::vector<VECTOR2D> output;
1181  std::vector<VECTOR2D> pointCtrl;
1182 
1183  pointCtrl.push_back( aStartPoint );
1184  pointCtrl.push_back( aControlPointA );
1185  pointCtrl.push_back( aControlPointB );
1186  pointCtrl.push_back( aEndPoint );
1187 
1188  BEZIER_POLY converter( pointCtrl );
1189  converter.GetPoly( output, aFilterValue );
1190 
1191  DrawPolyline( &output[0], output.size() );
1192 }
void DrawPolyline(const std::deque< VECTOR2D > &aPointList) override
Draw a polyline.
Definition: opengl_gal.cpp:997
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 1835 of file opengl_gal.cpp.

1836 {
1837  Save();
1838 
1839  m_currentManager->Reserve( 3 );
1840  m_currentManager->Translate( aCenterPoint.x, aCenterPoint.y, 0.0f );
1841  m_currentManager->Rotate( aAngle, 0.0f, 0.0f, 1.0f );
1842 
1843  /* Draw a triangle that contains the semicircle, then shade it to leave only
1844  * the semicircle. Parameters given to Shader() are indices of the triangle's vertices
1845  * (if you want to understand more, check the vertex shader source [shader.vert]).
1846  * Shader uses these coordinates to determine if fragments are inside the semicircle or not.
1847  * v2
1848  * /\
1849  * /__\
1850  * v0 //__\\ v1
1851  */
1853  m_currentManager->Vertex( -aRadius * 3.0f / sqrt( 3.0f ), 0.0f, m_layerDepth ); // v0
1854 
1856  m_currentManager->Vertex( aRadius * 3.0f / sqrt( 3.0f ), 0.0f, m_layerDepth ); // v1
1857 
1859  m_currentManager->Vertex( 0.0f, aRadius * 2.0f, m_layerDepth ); // v2
1860 
1861  Restore();
1862 }
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:311
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 1366 of file opengl_gal.cpp.

1367 {
1370 
1372 
1373  // sub-pixel lines all render the same
1374  float minorLineWidth = std::fmax( 1.0f,
1376  float majorLineWidth = minorLineWidth * 2.0f;
1377 
1378  // Draw the axis and grid
1379  // For the drawing the start points, end points and increments have
1380  // to be calculated in world coordinates
1381  VECTOR2D worldStartPoint = m_screenWorldMatrix * VECTOR2D( 0.0, 0.0 );
1382  VECTOR2D worldEndPoint = m_screenWorldMatrix * VECTOR2D( m_screenSize );
1383 
1384  // Draw axes if desired
1385  if( m_axesEnabled )
1386  {
1387  SetLineWidth( minorLineWidth );
1389 
1390  DrawLine( VECTOR2D( worldStartPoint.x, 0 ), VECTOR2D( worldEndPoint.x, 0 ) );
1391  DrawLine( VECTOR2D( 0, worldStartPoint.y ), VECTOR2D( 0, worldEndPoint.y ) );
1392  }
1393 
1394  // force flush
1396 
1397  if( !m_gridVisibility || m_gridSize.x == 0 || m_gridSize.y == 0 )
1398  return;
1399 
1400  VECTOR2D gridScreenSize( m_gridSize );
1401 
1402  double gridThreshold = computeMinGridSpacing() / m_worldScale;
1403 
1405  gridThreshold *= 2.0;
1406 
1407  // If we cannot display the grid density, scale down by a tick size and
1408  // try again. Eventually, we get some representation of the grid
1409  while( std::min( gridScreenSize.x, gridScreenSize.y ) <= gridThreshold )
1410  {
1411  gridScreenSize = gridScreenSize * static_cast<double>( m_gridTick );
1412  }
1413 
1414  // Compute grid starting and ending indexes to draw grid points on the
1415  // visible screen area
1416  // Note: later any point coordinate will be offsetted by m_gridOrigin
1417  int gridStartX = KiROUND( ( worldStartPoint.x - m_gridOrigin.x ) / gridScreenSize.x );
1418  int gridEndX = KiROUND( ( worldEndPoint.x - m_gridOrigin.x ) / gridScreenSize.x );
1419  int gridStartY = KiROUND( ( worldStartPoint.y - m_gridOrigin.y ) / gridScreenSize.y );
1420  int gridEndY = KiROUND( ( worldEndPoint.y - m_gridOrigin.y ) / gridScreenSize.y );
1421 
1422  // Ensure start coordinate > end coordinate
1423  SWAP( gridStartX, >, gridEndX );
1424  SWAP( gridStartY, >, gridEndY );
1425 
1426  // Ensure the grid fills the screen
1427  --gridStartX;
1428  ++gridEndX;
1429  --gridStartY;
1430  ++gridEndY;
1431 
1432  glDisable( GL_DEPTH_TEST );
1433  glDisable( GL_TEXTURE_2D );
1434 
1435  if( m_gridStyle == GRID_STYLE::DOTS )
1436  {
1437  glEnable( GL_STENCIL_TEST );
1438  glStencilFunc( GL_ALWAYS, 1, 1 );
1439  glStencilOp( GL_KEEP, GL_KEEP, GL_INCR );
1440  glColor4d( 0.0, 0.0, 0.0, 0.0 );
1441  SetStrokeColor( COLOR4D( 0.0, 0.0, 0.0, 0.0 ) );
1442  }
1443  else
1444  {
1445  glColor4d( m_gridColor.r, m_gridColor.g, m_gridColor.b, m_gridColor.a );
1447  }
1448 
1450  {
1451  // Vertical positions
1452  for( int j = gridStartY; j <= gridEndY; j++ )
1453  {
1454  bool tickY = ( j % m_gridTick == 0 );
1455  const double posY = j * gridScreenSize.y + m_gridOrigin.y;
1456 
1457  // Horizontal positions
1458  for( int i = gridStartX; i <= gridEndX; i++ )
1459  {
1460  bool tickX = ( i % m_gridTick == 0 );
1461  SetLineWidth( ( ( tickX && tickY ) ? majorLineWidth : minorLineWidth ) );
1462  auto lineLen = 2.0 * GetLineWidth();
1463  auto posX = i * gridScreenSize.x + m_gridOrigin.x;
1464 
1465  DrawLine( VECTOR2D( posX - lineLen, posY ), VECTOR2D( posX + lineLen, posY ) );
1466  DrawLine( VECTOR2D( posX, posY - lineLen ), VECTOR2D( posX, posY + lineLen ) );
1467  }
1468  }
1469 
1471  }
1472  else
1473  {
1474  // Vertical lines
1475  for( int j = gridStartY; j <= gridEndY; j++ )
1476  {
1477  const double y = j * gridScreenSize.y + m_gridOrigin.y;
1478 
1479  // If axes are drawn, skip the lines that would cover them
1480  if( m_axesEnabled && y == 0.0 )
1481  continue;
1482 
1483  SetLineWidth( ( j % m_gridTick == 0 ) ? majorLineWidth : minorLineWidth );
1484  VECTOR2D a( gridStartX * gridScreenSize.x + m_gridOrigin.x, y );
1485  VECTOR2D b( gridEndX * gridScreenSize.x + m_gridOrigin.x, y );
1486 
1487  DrawLine( a, b );
1488  }
1489 
1491 
1492  if( m_gridStyle == GRID_STYLE::DOTS )
1493  {
1494  glStencilFunc( GL_NOTEQUAL, 0, 1 );
1495  glColor4d( m_gridColor.r, m_gridColor.g, m_gridColor.b, m_gridColor.a );
1497  }
1498 
1499  // Horizontal lines
1500  for( int i = gridStartX; i <= gridEndX; i++ )
1501  {
1502  const double x = i * gridScreenSize.x + m_gridOrigin.x;
1503 
1504  // If axes are drawn, skip the lines that would cover them
1505  if( m_axesEnabled && x == 0.0 )
1506  continue;
1507 
1508  SetLineWidth( ( i % m_gridTick == 0 ) ? majorLineWidth : minorLineWidth );
1509  VECTOR2D a( x, gridStartY * gridScreenSize.y + m_gridOrigin.y );
1510  VECTOR2D b( x, gridEndY * gridScreenSize.y + m_gridOrigin.y );
1511  DrawLine( a, b );
1512  }
1513 
1515 
1516  if( m_gridStyle == GRID_STYLE::DOTS )
1517  glDisable( GL_STENCIL_TEST );
1518  }
1519 
1520  glEnable( GL_DEPTH_TEST );
1521  glEnable( GL_TEXTURE_2D );
1522 }
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:364
unsigned int m_mainBuffer
Main rendering target.
Definition: opengl_gal.h:319
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:365
Auxiliary rendering target (noncached)
Definition: definitions.h:49
double getWorldPixelSize() const
Definition: opengl_gal.cpp:400
COLOR4D m_gridColor
Color of the grid.
double m_worldScale
The scale factor world->screen.
double a
Alpha component.
Definition: color4d.h:366
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:318
void DrawLine(const VECTOR2D &aStartPoint, const VECTOR2D &aEndPoint) override
Draw a line.
Definition: opengl_gal.cpp:663
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:363
VERTEX_MANAGER * m_nonCachedManager
Container for storing non-cached VERTEX_ITEMs.
Definition: opengl_gal.h:314
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 1633 of file opengl_gal.cpp.

1634 {
1635  auto group = m_groups.find( aGroupNumber );
1636 
1637  if( group != m_groups.end() )
1638  m_cachedManager->DrawItem( *group->second );
1639 }
GROUPS_MAP m_groups
Stores information about VBO objects (groups)
Definition: opengl_gal.h:309
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:313

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

664 {
666 
667  drawLineQuad( aStartPoint, aEndPoint );
668 }
void drawLineQuad(const VECTOR2D &aStartPoint, const VECTOR2D &aEndPoint)
Draw a quad for the line.
double g
Green component.
Definition: color4d.h:364
double b
Blue component.
Definition: color4d.h:365
VERTEX_MANAGER * m_currentManager
Currently used VERTEX_MANAGER (for storing VERTEX_ITEMs).
Definition: opengl_gal.h:311
double a
Alpha component.
Definition: color4d.h:366
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:363

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

1772 {
1773  /* Helper drawing: ____--- v3 ^
1774  * ____---- ... \ \
1775  * ____---- ... \ end \
1776  * v1 ____---- ... ____---- \ width
1777  * ---- ...___---- \ \
1778  * \ ___...-- \ v
1779  * \ ____----... ____---- v2
1780  * ---- ... ____----
1781  * start \ ... ____----
1782  * \... ____----
1783  * ----
1784  * v0
1785  * dots mark triangles' hypotenuses
1786  */
1787 
1788  auto v1 = m_currentManager->GetTransformation()
1789  * glm::vec4( aStartPoint.x, aStartPoint.y, 0.0, 0.0 );
1791  * glm::vec4( aEndPoint.x, aEndPoint.y, 0.0, 0.0 );
1792 
1793  VECTOR2D vs( v2.x - v1.x, v2.y - v1.y );
1794 
1795  m_currentManager->Reserve( 6 );
1796 
1797  // Line width is maintained by the vertex shader
1799  m_currentManager->Vertex( aStartPoint, m_layerDepth );
1800 
1802  m_currentManager->Vertex( aStartPoint, m_layerDepth );
1803 
1805  m_currentManager->Vertex( aEndPoint, m_layerDepth );
1806 
1808  m_currentManager->Vertex( aEndPoint, m_layerDepth );
1809 
1811  m_currentManager->Vertex( aEndPoint, m_layerDepth );
1812 
1814  m_currentManager->Vertex( aStartPoint, m_layerDepth );
1815 }
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:311
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 1035 of file opengl_gal.cpp.

1036 {
1037  wxCHECK( aPointList.size() >= 2, /* void */ );
1038  auto points = std::unique_ptr<GLdouble[]>( new GLdouble[3 * aPointList.size()] );
1039  GLdouble* ptr = points.get();
1040 
1041  for( const VECTOR2D& p : aPointList )
1042  {
1043  *ptr++ = p.x;
1044  *ptr++ = p.y;
1045  *ptr++ = m_layerDepth;
1046  }
1047 
1048  drawPolygon( points.get(), aPointList.size() );
1049 }
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 1052 of file opengl_gal.cpp.

1053 {
1054  wxCHECK( aListSize >= 2, /* void */ );
1055  auto points = std::unique_ptr<GLdouble[]>( new GLdouble[3 * aListSize] );
1056  GLdouble* target = points.get();
1057  const VECTOR2D* src = aPointList;
1058 
1059  for( int i = 0; i < aListSize; ++i )
1060  {
1061  *target++ = src->x;
1062  *target++ = src->y;
1063  *target++ = m_layerDepth;
1064  ++src;
1065  }
1066 
1067  drawPolygon( points.get(), aListSize );
1068 }
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 1140 of file opengl_gal.cpp.

1141 {
1142  if( aPolySet.IsTriangulationUpToDate() )
1143  {
1144  drawTriangulatedPolyset( aPolySet, aStrokeTriangulation );
1145  return;
1146  }
1147 
1148  for( int j = 0; j < aPolySet.OutlineCount(); ++j )
1149  {
1150  const SHAPE_LINE_CHAIN& outline = aPolySet.COutline( j );
1151  DrawPolygon( outline );
1152  }
1153 }
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 1156 of file opengl_gal.cpp.

1157 {
1158  wxCHECK( aPolygon.PointCount() >= 2, /* void */ );
1159 
1160  const int pointCount = aPolygon.SegmentCount() + 1;
1161  std::unique_ptr<GLdouble[]> points( new GLdouble[3 * pointCount] );
1162  GLdouble* ptr = points.get();
1163 
1164  for( int i = 0; i < pointCount; ++i )
1165  {
1166  const VECTOR2I& p = aPolygon.CPoint( i );
1167  *ptr++ = p.x;
1168  *ptr++ = p.y;
1169  *ptr++ = m_layerDepth;
1170  }
1171 
1172  drawPolygon( points.get(), pointCount );
1173 }
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 1899 of file opengl_gal.cpp.

1900 {
1901  if( m_isFillEnabled )
1902  {
1905 
1906  // Any non convex polygon needs to be tesselated
1907  // for this purpose the GLU standard functions are used
1908  TessParams params = { m_currentManager, m_tessIntersects };
1909  gluTessBeginPolygon( m_tesselator, &params );
1910  gluTessBeginContour( m_tesselator );
1911 
1912  GLdouble* point = aPoints;
1913 
1914  for( int i = 0; i < aPointCount; ++i )
1915  {
1916  gluTessVertex( m_tesselator, point, point );
1917  point += 3; // 3 coordinates
1918  }
1919 
1920  gluTessEndContour( m_tesselator );
1921  gluTessEndPolygon( m_tesselator );
1922 
1923  // Free allocated intersecting points
1924  m_tessIntersects.clear();
1925  }
1926 
1927  if( m_isStrokeEnabled )
1928  {
1929  drawPolyline(
1930  [&]( int idx )
1931  {
1932  return VECTOR2D( aPoints[idx * 3], aPoints[idx * 3 + 1] );
1933  },
1934  aPointCount );
1935  }
1936 }
bool m_isFillEnabled
Is filling of graphic objects enabled ?
std::deque< boost::shared_array< GLdouble > > m_tessIntersects
Definition: opengl_gal.h:347
double g
Green component.
Definition: color4d.h:364
double b
Blue component.
Definition: color4d.h:365
VERTEX_MANAGER * m_currentManager
Currently used VERTEX_MANAGER (for storing VERTEX_ITEMs).
Definition: opengl_gal.h:311
double a
Alpha component.
Definition: color4d.h:366
bool m_isStrokeEnabled
Are the outlines stroked ?
VECTOR2< double > VECTOR2D
Definition: vector2d.h:622
GLUtesselator * m_tesselator
Definition: opengl_gal.h:346
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:363

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

998 {
999  drawPolyline(
1000  [&]( int idx )
1001  {
1002  return aPointList[idx];
1003  },
1004  aPointList.size() );
1005 }
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 1008 of file opengl_gal.cpp.

1009 {
1010  drawPolyline(
1011  [&]( int idx )
1012  {
1013  return aPointList[idx];
1014  },
1015  aListSize );
1016 }
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 1019 of file opengl_gal.cpp.

1020 {
1021  auto numPoints = aLineChain.PointCount();
1022 
1023  if( aLineChain.IsClosed() )
1024  numPoints += 1;
1025 
1026  drawPolyline(
1027  [&]( int idx )
1028  {
1029  return aLineChain.CPoint( idx );
1030  },
1031  numPoints );
1032 }
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 1939 of file opengl_gal.cpp.

1940 {
1941  wxCHECK( aPointCount >= 2, /* return */ );
1942 
1944  int i;
1945 
1946  for( i = 1; i < aPointCount; ++i )
1947  {
1948  auto start = aPointGetter( i - 1 );
1949  auto end = aPointGetter( i );
1950 
1951  drawLineQuad( start, end );
1952  }
1953 }
void drawLineQuad(const VECTOR2D &aStartPoint, const VECTOR2D &aEndPoint)
Draw a quad for the line.
double g
Green component.
Definition: color4d.h:364
double b
Blue component.
Definition: color4d.h:365
VERTEX_MANAGER * m_currentManager
Currently used VERTEX_MANAGER (for storing VERTEX_ITEMs).
Definition: opengl_gal.h:311
double a
Alpha component.
Definition: color4d.h:366
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:363

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

959 {
960  // Compute the diagonal points of the rectangle
961  VECTOR2D diagonalPointA( aEndPoint.x, aStartPoint.y );
962  VECTOR2D diagonalPointB( aStartPoint.x, aEndPoint.y );
963 
964  // Fill the rectangle
965  if( m_isFillEnabled )
966  {
970 
971  m_currentManager->Vertex( aStartPoint.x, aStartPoint.y, m_layerDepth );
972  m_currentManager->Vertex( diagonalPointA.x, diagonalPointA.y, m_layerDepth );
973  m_currentManager->Vertex( aEndPoint.x, aEndPoint.y, m_layerDepth );
974 
975  m_currentManager->Vertex( aStartPoint.x, aStartPoint.y, m_layerDepth );
976  m_currentManager->Vertex( aEndPoint.x, aEndPoint.y, m_layerDepth );
977  m_currentManager->Vertex( diagonalPointB.x, diagonalPointB.y, m_layerDepth );
978  }
979 
980  // Stroke the outline
981  if( m_isStrokeEnabled )
982  {
984  m_strokeColor.a );
985 
986  std::deque<VECTOR2D> pointList;
987  pointList.push_back( aStartPoint );
988  pointList.push_back( diagonalPointA );
989  pointList.push_back( aEndPoint );
990  pointList.push_back( diagonalPointB );
991  pointList.push_back( aStartPoint );
992  DrawPolyline( pointList );
993  }
994 }
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:364
double b
Blue component.
Definition: color4d.h:365
double m_layerDepth
The actual layer depth.
VERTEX_MANAGER * m_currentManager
Currently used VERTEX_MANAGER (for storing VERTEX_ITEMs).
Definition: opengl_gal.h:311
double a
Alpha component.
Definition: color4d.h:366
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.
Definition: opengl_gal.cpp:997
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:363

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

673 {
674  VECTOR2D startEndVector = aEndPoint - aStartPoint;
675  double lineLength = startEndVector.EuclideanNorm();
676 
677  float startx = aStartPoint.x;
678  float starty = aStartPoint.y;
679  float endx = aStartPoint.x + lineLength;
680  float endy = aStartPoint.y + lineLength;
681 
682  // Be careful about floating point rounding. As we draw segments in larger and larger
683  // coordinates, the shader (which uses floats) will lose precision and stop drawing small
684  // segments. In this case, we need to draw a circle for the minimal segment.
685  if( startx == endx || starty == endy )
686  {
687  DrawCircle( aStartPoint, aWidth / 2 );
688  return;
689  }
690 
691  if( m_isFillEnabled || aWidth == 1.0 )
692  {
694 
695  SetLineWidth( aWidth );
696  drawLineQuad( aStartPoint, aEndPoint );
697  }
698  else
699  {
700  auto lineAngle = startEndVector.Angle();
701  // Outlined tracks
702 
703  SetLineWidth( 1.0 );
705  m_strokeColor.a );
706 
707  Save();
708 
709  m_currentManager->Translate( aStartPoint.x, aStartPoint.y, 0.0 );
710  m_currentManager->Rotate( lineAngle, 0.0f, 0.0f, 1.0f );
711 
712  drawLineQuad( VECTOR2D( 0.0, aWidth / 2.0 ), VECTOR2D( lineLength, aWidth / 2.0 ) );
713 
714  drawLineQuad( VECTOR2D( 0.0, -aWidth / 2.0 ), VECTOR2D( lineLength, -aWidth / 2.0 ) );
715 
716  // Draw line caps
717  drawStrokedSemiCircle( VECTOR2D( 0.0, 0.0 ), aWidth / 2, M_PI / 2 );
718  drawStrokedSemiCircle( VECTOR2D( lineLength, 0.0 ), aWidth / 2, -M_PI / 2 );
719 
720  Restore();
721  }
722 }
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:364
virtual void SetLineWidth(float aLineWidth)
Set the line width.
double b
Blue component.
Definition: color4d.h:365
void Save() override
Save the context.
VERTEX_MANAGER * m_currentManager
Currently used VERTEX_MANAGER (for storing VERTEX_ITEMs).
Definition: opengl_gal.h:311
double a
Alpha component.
Definition: color4d.h:366
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:363
void DrawCircle(const VECTOR2D &aCenterPoint, double aRadius) override
Draw a circle using world coordinates.
Definition: opengl_gal.cpp:725

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

1819 {
1820  if( m_isFillEnabled )
1821  {
1823  drawFilledSemiCircle( aCenterPoint, aRadius, aAngle );
1824  }
1825 
1826  if( m_isStrokeEnabled )
1827  {
1829  m_strokeColor.a );
1830  drawStrokedSemiCircle( aCenterPoint, aRadius, aAngle );
1831  }
1832 }
bool m_isFillEnabled
Is filling of graphic objects enabled ?
double g
Green component.
Definition: color4d.h:364
double b
Blue component.
Definition: color4d.h:365
VERTEX_MANAGER * m_currentManager
Currently used VERTEX_MANAGER (for storing VERTEX_ITEMs).
Definition: opengl_gal.h:311
double a
Alpha component.
Definition: color4d.h:366
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:363
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 1865 of file opengl_gal.cpp.

1867 {
1868  double outerRadius = aRadius + ( m_lineWidth / 2 );
1869 
1870  Save();
1871 
1872  m_currentManager->Reserve( 3 );
1873  m_currentManager->Translate( aCenterPoint.x, aCenterPoint.y, 0.0f );
1874  m_currentManager->Rotate( aAngle, 0.0f, 0.0f, 1.0f );
1875 
1876  /* Draw a triangle that contains the semicircle, then shade it to leave only
1877  * the semicircle. Parameters given to Shader() are indices of the triangle's vertices
1878  * (if you want to understand more, check the vertex shader source [shader.vert]), the
1879  * radius and the line width. Shader uses these coordinates to determine if fragments are
1880  * inside the semicircle or not.
1881  * v2
1882  * /\
1883  * /__\
1884  * v0 //__\\ v1
1885  */
1887  m_currentManager->Vertex( -outerRadius * 3.0f / sqrt( 3.0f ), 0.0f, m_layerDepth ); // v0
1888 
1890  m_currentManager->Vertex( outerRadius * 3.0f / sqrt( 3.0f ), 0.0f, m_layerDepth ); // v1
1891 
1893  m_currentManager->Vertex( 0.0f, outerRadius * 2.0f, m_layerDepth ); // v2
1894 
1895  Restore();
1896 }
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:311
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 1071 of file opengl_gal.cpp.

1073 {
1076 
1077  if( m_isFillEnabled )
1078  {
1079  for( unsigned int j = 0; j < aPolySet.TriangulatedPolyCount(); ++j )
1080  {
1081  auto triPoly = aPolySet.TriangulatedPolygon( j );
1082 
1083  for( size_t i = 0; i < triPoly->GetTriangleCount(); i++ )
1084  {
1085  VECTOR2I a, b, c;
1086  triPoly->GetTriangle( i, a, b, c );
1090  }
1091  }
1092  }
1093 
1094  if( m_isStrokeEnabled )
1095  {
1096  for( int j = 0; j < aPolySet.OutlineCount(); ++j )
1097  {
1098  const auto& poly = aPolySet.Polygon( j );
1099 
1100  for( const auto& lc : poly )
1101  {
1102  DrawPolyline( lc );
1103  }
1104  }
1105  }
1106 
1107  if( ADVANCED_CFG::GetCfg().m_DrawTriangulationOutlines )
1108  {
1109  aStrokeTriangulation = true;
1110  SetStrokeColor( COLOR4D( 0.0, 1.0, 0.2, 1.0 ) );
1111  }
1112 
1113  if( aStrokeTriangulation )
1114  {
1115  COLOR4D oldStrokeColor = m_strokeColor;
1116  double oldLayerDepth = m_layerDepth;
1117 
1118  SetLayerDepth( m_layerDepth - 1 );
1119 
1120  for( unsigned int j = 0; j < aPolySet.TriangulatedPolyCount(); ++j )
1121  {
1122  auto triPoly = aPolySet.TriangulatedPolygon( j );
1123 
1124  for( size_t i = 0; i < triPoly->GetTriangleCount(); i++ )
1125  {
1126  VECTOR2I a, b, c;
1127  triPoly->GetTriangle( i, a, b, c );
1128  DrawLine( a, b );
1129  DrawLine( b, c );
1130  DrawLine( c, a );
1131  }
1132  }
1133 
1134  SetStrokeColor( oldStrokeColor );
1135  SetLayerDepth( oldLayerDepth );
1136  }
1137 }
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:364
virtual void SetLayerDepth(double aLayerDepth)
Set the depth of the layer (position on the z-axis)
double b
Blue component.
Definition: color4d.h:365
double m_layerDepth
The actual layer depth.
VERTEX_MANAGER * m_currentManager
Currently used VERTEX_MANAGER (for storing VERTEX_ITEMs).
Definition: opengl_gal.h:311
double a
Alpha component.
Definition: color4d.h:366
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:663
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.
Definition: opengl_gal.cpp:997
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:363
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 2330 of file opengl_gal.cpp.

2331 {
2332  m_cachedManager->EnableDepthTest( aEnabled );
2333  m_nonCachedManager->EnableDepthTest( aEnabled );
2334  m_overlayManager->EnableDepthTest( aEnabled );
2335 }
VERTEX_MANAGER * m_overlayManager
Container for storing overlaid VERTEX_ITEMs.
Definition: opengl_gal.h:315
VERTEX_MANAGER * m_cachedManager
Container for storing cached VERTEX_ITEMs.
Definition: opengl_gal.h:313
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:314

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

◆ endDrawing()

void OPENGL_GAL::endDrawing ( )
overrideprivatevirtual

Update handler for OpenGL settings

Reimplemented from KIGFX::GAL.

Definition at line 573 of file opengl_gal.cpp.

574 {
575  wxASSERT_MSG( m_isContextLocked, "What happened to the context lock?" );
576 
577 #ifdef KICAD_GAL_PROFILE
578  PROF_COUNTER totalRealTime( "OPENGL_GAL::endDrawing()", true );
579 #endif /* KICAD_GAL_PROFILE */
580 
581  // Cached & non-cached containers are rendered to the same buffer
585 
586  // Overlay container is rendered to a different buffer
587  if( m_overlayBuffer )
589 
591 
592  // Be sure that the framebuffer is not colorized (happens on specific GPU&drivers combinations)
593  glColor4d( 1.0, 1.0, 1.0, 1.0 );
594 
595  // Draw the remaining contents, blit the rendering targets to the screen, swap the buffers
597 
598  if( m_overlayBuffer )
600 
602  blitCursor();
603 
604  SwapBuffers();
605 
606 #ifdef KICAD_GAL_PROFILE
607  totalRealTime.Stop();
608  wxLogTrace( traceGalProfile, wxT( "OPENGL_GAL::endDrawing(): %.1f ms" ),
609  totalRealTime.msecs() );
610 #endif /* KICAD_GAL_PROFILE */
611 }
unsigned int m_overlayBuffer
Auxiliary rendering target (for menus etc.)
Definition: opengl_gal.h:320
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:315
const wxChar *const traceGalProfile
Flag to enable debug output of GAL performance profiling.
unsigned int m_mainBuffer
Main rendering target.
Definition: opengl_gal.h:319
A small class to help profiling.
Definition: profile.h:45
VERTEX_MANAGER * m_cachedManager
Container for storing cached VERTEX_ITEMs.
Definition: opengl_gal.h:313
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:318
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:334
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:314

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

1627 {
1629  m_isGrouping = false;
1630 }
VERTEX_MANAGER * m_cachedManager
Container for storing cached VERTEX_ITEMs.
Definition: opengl_gal.h:313
void FinishItem() const
Clean after adding an item.
bool m_isGrouping
Was a group started?
Definition: opengl_gal.h:333

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

◆ endUpdate()

void OPENGL_GAL::endUpdate ( )
overrideprivatevirtual

Reimplemented from KIGFX::GAL.

Definition at line 654 of file opengl_gal.cpp.

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

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

1550 {
1551  glFlush();
1552 }

◆ GetClearColor()

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

Definition at line 220 of file graphics_abstraction_layer.h.

221  {
222  return m_clearColor;
223  }

References KIGFX::GAL::m_clearColor.

◆ 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:60
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 271 of file graphics_abstraction_layer.h.

272  {
273  return m_fillColor;
274  }
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 935 of file graphics_abstraction_layer.h.

References KIGFX::GAL::m_gridLineWidth.

◆ GetGridOrigin()

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

Definition at line 860 of file graphics_abstraction_layer.h.

861  {
862  return m_gridOrigin;
863  }
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 832 of file graphics_abstraction_layer.h.

832 { 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 456 of file graphics_abstraction_layer.h.

457  {
459  }
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(), 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 661 of file graphics_abstraction_layer.h.

662  {
663  return m_lookAtPoint;
664  }
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 730 of file graphics_abstraction_layer.h.

731  {
732  return m_depthRange.y;
733  }
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 722 of file graphics_abstraction_layer.h.

723  {
724  return m_depthRange.x;
725  }
VECTOR2D m_depthRange
Range of the depth.

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

Referenced by KIGFX::PREVIEW::RULER_ITEM::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().

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

2177 {
2178  wxASSERT_MSG( m_groups.size() < std::numeric_limits<unsigned int>::max(),
2179  wxT( "There are no free slots to store a group" ) );
2180 
2181  while( m_groups.find( m_groupCounter ) != m_groups.end() )
2182  m_groupCounter++;
2183 
2184  return m_groupCounter++;
2185 }
GROUPS_MAP m_groups
Stores information about VBO objects (groups)
Definition: opengl_gal.h:309
unsigned int m_groupCounter
Counter used for generating keys for groups.
Definition: opengl_gal.h:310

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

702  {
703  return m_rotation;
704  }
double m_rotation
Rotation transformation (radians)

References KIGFX::GAL::m_rotation.

◆ GetScaleFactor()

double HIDPI_GL_CANVAS::GetScaleFactor ( ) const
inherited

Get the current scale factor.

Definition at line 59 of file hidpi_gl_canvas.cpp.

60 {
61  return m_scale_factor;
62 }
double m_scale_factor
The current scale factor (e.g.

References HIDPI_GL_CANVAS::m_scale_factor.

Referenced by beginDrawing(), DrawGrid(), HIDPI_GL_CANVAS::GetNativePixelSize(), getScreenPixelSize(), ResizeScreen(), KIGFX::PREVIEW::SetConstantGlyphHeight(), and updatedGalDisplayOptions().

◆ GetScreenPixelSize()

◆ getScreenPixelSize()

VECTOR2D OPENGL_GAL::getScreenPixelSize ( ) const
private

Definition at line 407 of file opengl_gal.cpp.

408 {
409  double sf = GetScaleFactor();
410  return VECTOR2D( 2.0 / (double) ( m_screenSize.x * sf ), 2.0 /
411  (double) ( m_screenSize.y * sf ) );
412 }
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 592 of file graphics_abstraction_layer.h.

593  {
594  return m_screenWorldMatrix;
595  }
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 291 of file graphics_abstraction_layer.h.

292  {
293  return m_strokeColor;
294  }
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 333 of file graphics_abstraction_layer.h.

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

References KIGFX::GAL::m_strokeFont.

Referenced by 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 1692 of file opengl_gal.cpp.

1693 {
1694  return m_currentTarget;
1695 }
RENDER_TARGET m_currentTarget
Current rendering target.
Definition: opengl_gal.h:321

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

475  {
477  }
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(), 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 400 of file opengl_gal.cpp.

401 {
402  MATRIX3x3D matrix = GetScreenWorldMatrix();
403  return std::min( std::abs( matrix.GetScale().x ), std::abs( matrix.GetScale().y ) );
404 }
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 582 of file graphics_abstraction_layer.h.

583  {
584  return m_worldScreenMatrix;
585  }
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 681 of file graphics_abstraction_layer.h.

682  {
683  return m_zoomFactor;
684  }
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 1728 of file opengl_gal.cpp.

1729 {
1730  switch( aTarget )
1731  {
1732  default:
1733  case TARGET_CACHED:
1734  case TARGET_NONCACHED: return true;
1735  case TARGET_OVERLAY: return ( m_overlayBuffer != 0 );
1736  }
1737 }
unsigned int m_overlayBuffer
Auxiliary rendering target (for menus etc.)
Definition: opengl_gal.h:320
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 2188 of file opengl_gal.cpp.

2189 {
2190  wxASSERT( IsShownOnScreen() );
2191 
2192  wxASSERT_MSG( m_isContextLocked, "This should only be called from within a locked context." );
2193 
2194 // IsDisplayAttr() handles WX_GL_{MAJOR,MINOR}_VERSION correctly only in 3.0.4
2195 // starting with 3.1.0 one should use wxGLContext::IsOk() (done by GL_CONTEXT_MANAGER)
2196 #if wxCHECK_VERSION( 3, 0, 3 ) and !wxCHECK_VERSION( 3, 1, 0 )
2197  const int attr[] = { WX_GL_MAJOR_VERSION, 2, WX_GL_MINOR_VERSION, 1, 0 };
2198 
2199  if( !IsDisplaySupported( attr ) )
2200  throw std::runtime_error( "OpenGL 2.1 or higher is required!" );
2201 #endif /* wxCHECK_VERSION( 3, 0, 3 ) */
2202 
2203  // Check correct initialization from the constructor
2204  if( !m_glMainContext )
2205  throw std::runtime_error( "Could not create the main OpenGL context" );
2206 
2207  if( !m_glPrivContext )
2208  throw std::runtime_error( "Could not create a private OpenGL context" );
2209 
2210  if( m_tesselator == nullptr )
2211  throw std::runtime_error( "Could not create the m_tesselator" );
2212  // End initialization checks
2213 
2214  GLenum err = glewInit();
2215 
2216  if( GLEW_OK != err )
2217  throw std::runtime_error( (const char*) glewGetErrorString( err ) );
2218 
2219  // Check the OpenGL version (minimum 2.1 is required)
2220  if( !GLEW_VERSION_2_1 )
2221  throw std::runtime_error( "OpenGL 2.1 or higher is required!" );
2222 
2223 #if defined( __LINUX__ ) // calling enableGlDebug crashes opengl on some OS (OSX and some Windows)
2224 #ifdef DEBUG
2225  if( GLEW_ARB_debug_output )
2226  enableGlDebug( true );
2227 #endif
2228 #endif
2229 
2230  // Framebuffers have to be supported
2231  if( !GLEW_EXT_framebuffer_object )
2232  throw std::runtime_error( "Framebuffer objects are not supported!" );
2233 
2234  // Vertex buffer has to be supported
2235  if( !GLEW_ARB_vertex_buffer_object )
2236  throw std::runtime_error( "Vertex buffer objects are not supported!" );
2237 
2238  // Prepare shaders
2239  if( !m_shader->IsLinked()
2242  {
2243  throw std::runtime_error( "Cannot compile vertex shader!" );
2244  }
2245 
2246  if( !m_shader->IsLinked()
2249  {
2250  throw std::runtime_error( "Cannot compile fragment shader!" );
2251  }
2252 
2253  if( !m_shader->IsLinked() && !m_shader->Link() )
2254  throw std::runtime_error( "Cannot link the shaders!" );
2255 
2256  // Check if video card supports textures big enough to fit the font atlas
2257  int maxTextureSize;
2258  glGetIntegerv( GL_MAX_TEXTURE_SIZE, &maxTextureSize );
2259 
2260  if( maxTextureSize < (int) font_image.width || maxTextureSize < (int) font_image.height )
2261  {
2262  // TODO implement software texture scaling
2263  // for bitmap fonts and use a higher resolution texture?
2264  throw std::runtime_error( "Requested texture size is not supported" );
2265  }
2266 
2268 
2269  m_cachedManager = new VERTEX_MANAGER( true );
2270  m_nonCachedManager = new VERTEX_MANAGER( false );
2271  m_overlayManager = new VERTEX_MANAGER( false );
2272 
2273  // Make VBOs use shaders
2277 
2278  m_isInitialized = true;
2279 }
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:315
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:313
void enableGlDebug(bool aEnable)
Enable or disable OpenGL driver messages output.
Definition: utils.cpp:179
static wxGLContext * m_glMainContext
Parent OpenGL context.
Definition: opengl_gal.h:298
SHADER * m_shader
There is only one shader used for different objects.
Definition: opengl_gal.h:324
bool m_isInitialized
Basic initialization flag, has to be done when the window is visible.
Definition: opengl_gal.h:331
void SetShader(SHADER &aShader) const
Set a shader program that is going to be used during rendering.
GLUtesselator * m_tesselator
Definition: opengl_gal.h:346
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:334
wxGLContext * m_glPrivContext
Canvas-specific OpenGL context.
Definition: opengl_gal.h:299
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:314

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

997  {
999  }
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 768 of file graphics_abstraction_layer.h.

769  {
770  return m_globalFlipY;
771  }
bool m_globalFlipY
Flag for Y axis flipping.

References KIGFX::GAL::m_globalFlipY.

◆ IsFontBold()

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

Definition at line 422 of file graphics_abstraction_layer.h.

422 { return textProperties.m_bold; }
struct KIGFX::GAL::TEXT_PROPERTIES textProperties

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

Referenced by KIGFX::STROKE_FONT::Draw().

◆ IsFontItalic()

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

◆ IsFontUnderlined()

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

◆ IsInitialized()

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

Return the initialization status for the canvas.

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

Reimplemented from KIGFX::GAL.

Definition at line 99 of file opengl_gal.h.

◆ IsOpenGlEngine()

bool KIGFX::OPENGL_GAL::IsOpe