KiCad PCB EDA Suite
KIGFX::OPENGL_GAL Class Reference

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

#include <opengl_gal.h>

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

Classes

struct  TessParams
 

Public Member Functions

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

Static Public Member Functions

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

Protected Member Functions

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

Protected Attributes

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

Static Protected Attributes

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

Private Types

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

Private Member Functions

void beginUpdate () override
 
void endUpdate () override
 
bool updatedGalDisplayOptions (const GAL_DISPLAY_OPTIONS &aOptions) override
 Handle updating display options. More...
 
void drawLineQuad (const VECTOR2D &aStartPoint, const VECTOR2D &aEndPoint)
 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...
 
VERTEX_MANAGERm_tempManager
 Container for storing temp (diff mode) VERTEX_ITEMs. More...
 
OPENGL_COMPOSITORm_compositor
 Handles multiple rendering targets. More...
 
unsigned int m_mainBuffer
 Main rendering target. More...
 
unsigned int m_overlayBuffer
 Auxiliary rendering target (for menus etc.) More...
 
unsigned int m_tempBuffer
 Temporary rendering target (for diffing etc.) More...
 
RENDER_TARGET m_currentTarget
 Current rendering target. More...
 
SHADERm_shader
 There is only one shader used for different objects. More...
 
bool m_isFramebufferInitialized
 Are the framebuffers initialized? More...
 
bool m_isBitmapFontInitialized
 Is the shader set to use bitmap fonts? More...
 
bool m_isInitialized
 Basic initialization flag, has to be done when the window is visible. More...
 
bool m_isGrouping
 Was a group started? More...
 
bool m_isContextLocked
 Used for assertion checking. More...
 
int m_lockClientCookie
 
GLint ufm_worldPixelSize
 
GLint ufm_screenPixelSize
 
GLint ufm_pixelSizeMultiplier
 
GLint ufm_antialiasingOffset
 
wxCursor m_currentwxCursor
 wxCursor showing the current native cursor More...
 
std::unique_ptr< GL_BITMAP_CACHEm_bitmapCache
 
GLUtesselator * m_tesselator
 
std::deque< boost::shared_array< GLdouble > > m_tessIntersects
 

Static Private Attributes

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

Detailed Description

OpenGL implementation of the Graphics Abstraction Layer.

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

Definition at line 70 of file opengl_gal.h.

Member Typedef Documentation

◆ GROUPS_MAP

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

Definition at line 325 of file opengl_gal.h.

◆ super

typedef GAL KIGFX::OPENGL_GAL::super
private

Super class definition.

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

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

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

◆ ~OPENGL_GAL()

OPENGL_GAL::~OPENGL_GAL ( )

Definition at line 289 of file opengl_gal.cpp.

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

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

Member Function Documentation

◆ AdvanceDepth()

void KIGFX::GAL::AdvanceDepth ( )
inlineinherited

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

Definition at line 1056 of file graphics_abstraction_layer.h.

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

References KIGFX::GAL::m_layerDepth.

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

◆ BeginDrawing()

void OPENGL_GAL::BeginDrawing ( )
overridevirtual

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

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

Reimplemented from KIGFX::GAL.

Definition at line 419 of file opengl_gal.cpp.

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

1643 {
1644  m_isGrouping = true;
1645 
1646  std::shared_ptr<VERTEX_ITEM> newItem = std::make_shared<VERTEX_ITEM>( *m_cachedManager );
1647  int groupNumber = getNewGroupNumber();
1648  m_groups.insert( std::make_pair( groupNumber, newItem ) );
1649 
1650  return groupNumber;
1651 }
GROUPS_MAP m_groups
Stores information about VBO objects (groups)
Definition: opengl_gal.h:327
VERTEX_MANAGER * m_cachedManager
Container for storing cached VERTEX_ITEMs.
Definition: opengl_gal.h:331
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:353

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

◆ beginUpdate()

void OPENGL_GAL::beginUpdate ( )
overrideprivatevirtual

Reimplemented from KIGFX::GAL.

Definition at line 662 of file opengl_gal.cpp.

663 {
664  wxASSERT_MSG( m_isContextLocked, "GAL_UPDATE_CONTEXT RAII object should have locked context. "
665  "Calling this from anywhere else is not allowed." );
666 
667  wxASSERT_MSG( IsVisible(), "GAL::beginUpdate() must not be entered when GAL is not visible. "
668  "Other update routines will expect everything to be initialized "
669  "which will not be the case." );
670 
671  if( !m_isInitialized )
672  init();
673 
674  m_cachedManager->Map();
675 }
VERTEX_MANAGER * m_cachedManager
Container for storing cached VERTEX_ITEMs.
Definition: opengl_gal.h:331
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:351
void Map()
Map vertex buffer.
bool m_isContextLocked
Used for assertion checking.
Definition: opengl_gal.h:354
bool IsVisible() const override
Return true if the GAL canvas is visible on the screen.
Definition: opengl_gal.h:110

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

◆ BitmapText()

void OPENGL_GAL::BitmapText ( const wxString &  aText,
const VECTOR2D aPosition,
double  aRotationAngle 
)
overridevirtual

Draw a text using a bitmap font.

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

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

Reimplemented from KIGFX::GAL.

Definition at line 1278 of file opengl_gal.cpp.

1280 {
1281  // Fallback to generic impl (which uses the stroke font) on cases we don't handle
1282  if( IsTextMirrored() || aText.Contains( wxT( "^{" ) ) || aText.Contains( wxT( "_{" ) ) )
1283  return GAL::BitmapText( aText, aPosition, aRotationAngle );
1284 
1285  const UTF8 text( aText );
1286  VECTOR2D textSize;
1287  float commonOffset;
1288  std::tie( textSize, commonOffset ) = computeBitmapTextSize( text );
1289 
1290  const double SCALE = 1.4 * GetGlyphSize().y / textSize.y;
1291  int overbarLength = 0;
1292  double overbarHeight = textSize.y;
1293 
1294  Save();
1295 
1297  m_currentManager->Translate( aPosition.x, aPosition.y, m_layerDepth );
1298  m_currentManager->Rotate( aRotationAngle, 0.0f, 0.0f, -1.0f );
1299 
1300  double sx = SCALE * ( m_globalFlipX ? -1.0 : 1.0 );
1301  double sy = SCALE * ( m_globalFlipY ? -1.0 : 1.0 );
1302 
1303  m_currentManager->Scale( sx, sy, 0 );
1304  m_currentManager->Translate( 0, -commonOffset, 0 );
1305 
1306  switch( GetHorizontalJustify() )
1307  {
1309  Translate( VECTOR2D( -textSize.x / 2.0, 0 ) );
1310  break;
1311 
1313  //if( !IsTextMirrored() )
1314  Translate( VECTOR2D( -textSize.x, 0 ) );
1315  break;
1316 
1317  case GR_TEXT_HJUSTIFY_LEFT:
1318  //if( IsTextMirrored() )
1319  //Translate( VECTOR2D( -textSize.x, 0 ) );
1320  break;
1321  }
1322 
1323  switch( GetVerticalJustify() )
1324  {
1325  case GR_TEXT_VJUSTIFY_TOP:
1326  Translate( VECTOR2D( 0, -textSize.y ) );
1327  overbarHeight = -textSize.y / 2.0;
1328  break;
1329 
1331  Translate( VECTOR2D( 0, -textSize.y / 2.0 ) );
1332  overbarHeight = 0;
1333  break;
1334 
1336  break;
1337  }
1338 
1339  int overbarDepth = -1;
1340  int braceNesting = 0;
1341 
1342  for( UTF8::uni_iter chIt = text.ubegin(), end = text.uend(); chIt < end; ++chIt )
1343  {
1344  wxASSERT_MSG( *chIt != '\n' && *chIt != '\r',
1345  wxT( "No support for multiline bitmap text yet" ) );
1346 
1347  if( *chIt == '~' && overbarDepth == -1 )
1348  {
1349  UTF8::uni_iter lookahead = chIt;
1350 
1351  if( ++lookahead != end && *lookahead == '{' )
1352  {
1353  chIt = lookahead;
1354  overbarDepth = braceNesting;
1355  braceNesting++;
1356  continue;
1357  }
1358  }
1359  else if( *chIt == '{' )
1360  {
1361  braceNesting++;
1362  }
1363  else if( *chIt == '}' )
1364  {
1365  if( braceNesting > 0 )
1366  braceNesting--;
1367 
1368  if( braceNesting == overbarDepth )
1369  {
1370  drawBitmapOverbar( overbarLength, overbarHeight );
1371  overbarLength = 0;
1372 
1373  overbarDepth = -1;
1374  continue;
1375  }
1376  }
1377 
1378  if( overbarDepth != -1 )
1379  overbarLength += drawBitmapChar( *chIt );
1380  else
1381  drawBitmapChar( *chIt );
1382  }
1383 
1384  // Handle the case when overbar is active till the end of the drawn text
1385  m_currentManager->Translate( 0, commonOffset, 0 );
1386 
1387  if( overbarDepth != -1 && overbarLength > 0 )
1388  drawBitmapOverbar( overbarLength, overbarHeight );
1389 
1390  Restore();
1391 }
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:385
EDA_TEXT_HJUSTIFY_T GetHorizontalJustify() const
Return current text horizontal justification setting.
double b
Blue component.
Definition: color4d.h:386
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:329
double a
Alpha component.
Definition: color4d.h:387
COLOR4D m_strokeColor
The color of the outlines.
VECTOR2< double > VECTOR2D
Definition: vector2d.h:621
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:384
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 2188 of file opengl_gal.cpp.

2189 {
2190  if( !IsCursorEnabled() )
2191  return;
2192 
2194 
2195  const int cursorSize = m_fullscreenCursor ? 8000 : 80;
2196 
2197  VECTOR2D cursorBegin = m_cursorPosition - cursorSize / ( 2 * m_worldScale );
2198  VECTOR2D cursorEnd = m_cursorPosition + cursorSize / ( 2 * m_worldScale );
2199  VECTOR2D cursorCenter = ( cursorBegin + cursorEnd ) / 2;
2200 
2201  const COLOR4D cColor = getCursorColor();
2202  const COLOR4D color( cColor.r * cColor.a, cColor.g * cColor.a, cColor.b * cColor.a, 1.0 );
2203 
2204  glActiveTexture( GL_TEXTURE0 );
2205  glDisable( GL_TEXTURE_2D );
2206  glLineWidth( 1.0 );
2207  glColor4d( color.r, color.g, color.b, color.a );
2208 
2209  glBegin( GL_LINES );
2210  glVertex2d( cursorCenter.x, cursorBegin.y );
2211  glVertex2d( cursorCenter.x, cursorEnd.y );
2212 
2213  glVertex2d( cursorBegin.x, cursorCenter.y );
2214  glVertex2d( cursorEnd.x, cursorCenter.y );
2215  glEnd();
2216 }
int color
Definition: DXF_plotter.cpp:57
double g
Green component.
Definition: color4d.h:385
static const unsigned int DIRECT_RENDERING
double b
Blue component.
Definition: color4d.h:386
double m_worldScale
The scale factor world->screen.
VECTOR2D m_cursorPosition
Current cursor position (world coordinates)
double a
Alpha component.
Definition: color4d.h:387
OPENGL_COMPOSITOR * m_compositor
Handles multiple rendering targets.
Definition: opengl_gal.h:337
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:384
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 513 of file opengl_gal.h.

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

References SEG_PER_CIRCLE_COUNT.

Referenced by DrawArc().

◆ ChangeGroupColor()

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

Change the color used to draw the group.

Parameters
aGroupNumberis the group number.
aNewColoris the new color.

Reimplemented from KIGFX::GAL.

Definition at line 1670 of file opengl_gal.cpp.

1671 {
1672  auto group = m_groups.find( aGroupNumber );
1673 
1674  if( group != m_groups.end() )
1675  m_cachedManager->ChangeItemColor( *group->second, aNewColor );
1676 }
GROUPS_MAP m_groups
Stores information about VBO objects (groups)
Definition: opengl_gal.h:327
VERTEX_MANAGER * m_cachedManager
Container for storing cached VERTEX_ITEMs.
Definition: opengl_gal.h:331
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 1679 of file opengl_gal.cpp.

1680 {
1681  auto group = m_groups.find( aGroupNumber );
1682 
1683  if( group != m_groups.end() )
1684  m_cachedManager->ChangeItemDepth( *group->second, aDepth );
1685 }
GROUPS_MAP m_groups
Stores information about VBO objects (groups)
Definition: opengl_gal.h:327
VERTEX_MANAGER * m_cachedManager
Container for storing cached VERTEX_ITEMs.
Definition: opengl_gal.h:331
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 335 of file opengl_gal.cpp.

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

References init().

Referenced by EDA_DRAW_PANEL_GAL::SwitchBackend().

◆ ClearCache()

void OPENGL_GAL::ClearCache ( )
overridevirtual

Delete all data created during caching of graphic items.

Reimplemented from KIGFX::GAL.

Definition at line 1695 of file opengl_gal.cpp.

1696 {
1697  m_bitmapCache = std::make_unique<GL_BITMAP_CACHE>();
1698 
1699  m_groups.clear();
1700 
1701  if( m_isInitialized )
1703 }
GROUPS_MAP m_groups
Stores information about VBO objects (groups)
Definition: opengl_gal.h:327
VERTEX_MANAGER * m_cachedManager
Container for storing cached VERTEX_ITEMs.
Definition: opengl_gal.h:331
bool m_isInitialized
Basic initialization flag, has to be done when the window is visible.
Definition: opengl_gal.h:351
std::unique_ptr< GL_BITMAP_CACHE > m_bitmapCache
Definition: opengl_gal.h:363
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 1583 of file opengl_gal.cpp.

1584 {
1585  // Clear screen
1587 
1588  // NOTE: Black used here instead of m_clearColor; it will be composited later
1589  glClearColor( 0, 0, 0, 1 );
1590  glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT );
1591 }
static const unsigned int DIRECT_RENDERING
OPENGL_COMPOSITOR * m_compositor
Handles multiple rendering targets.
Definition: opengl_gal.h:337
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 1727 of file opengl_gal.cpp.

1728 {
1729  // Save the current state
1730  unsigned int oldTarget = m_compositor->GetBuffer();
1731 
1732  switch( aTarget )
1733  {
1734  // Cached and noncached items are rendered to the same buffer
1735  default:
1736  case TARGET_CACHED:
1737  case TARGET_NONCACHED:
1739  break;
1740 
1741  case TARGET_TEMP:
1743  break;
1744 
1745  case TARGET_OVERLAY:
1746  if( m_overlayBuffer )
1748  break;
1749  }
1750 
1751  if( aTarget != TARGET_OVERLAY )
1753  else if( m_overlayBuffer )
1755 
1756  // Restore the previous state
1757  m_compositor->SetBuffer( oldTarget );
1758 }
unsigned int m_overlayBuffer
Auxiliary rendering target (for menus etc.)
Definition: opengl_gal.h:339
static const COLOR4D BLACK
Definition: color4d.h:394
unsigned int m_mainBuffer
Main rendering target.
Definition: opengl_gal.h:338
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:337
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
unsigned int m_tempBuffer
Temporary rendering target (for diffing etc.)
Definition: opengl_gal.h:340
Temporary target for drawing in separate layer.
Definition: definitions.h:51
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, m_tempBuffer, KIGFX::OPENGL_COMPOSITOR::SetBuffer(), KIGFX::TARGET_CACHED, KIGFX::TARGET_NONCACHED, KIGFX::TARGET_OVERLAY, and KIGFX::TARGET_TEMP.

Referenced by StartDiffLayer().

◆ computeBitmapTextSize()

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

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

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

Definition at line 2114 of file opengl_gal.cpp.

2115 {
2116  static const FONT_GLYPH_TYPE* defaultGlyph = LookupGlyph( '(' ); // for strange chars
2117 
2118  VECTOR2D textSize( 0, 0 );
2119  float commonOffset = std::numeric_limits<float>::max();
2120  float charHeight = font_information.max_y - defaultGlyph->miny;
2121  int overbarDepth = -1;
2122  int braceNesting = 0;
2123 
2124  for( UTF8::uni_iter chIt = aText.ubegin(), end = aText.uend(); chIt < end; ++chIt )
2125  {
2126  if( *chIt == '~' && overbarDepth == -1 )
2127  {
2128  UTF8::uni_iter lookahead = chIt;
2129 
2130  if( ++lookahead != end && *lookahead == '{' )
2131  {
2132  chIt = lookahead;
2133  overbarDepth = braceNesting;
2134  braceNesting++;
2135  continue;
2136  }
2137  }
2138  else if( *chIt == '{' )
2139  {
2140  braceNesting++;
2141  }
2142  else if( *chIt == '}' )
2143  {
2144  if( braceNesting > 0 )
2145  braceNesting--;
2146 
2147  if( braceNesting == overbarDepth )
2148  {
2149  overbarDepth = -1;
2150  continue;
2151  }
2152  }
2153 
2154  const FONT_GLYPH_TYPE* glyph = LookupGlyph( *chIt );
2155 
2156  if( !glyph // Not coded in font
2157  || *chIt == '-' || *chIt == '_' ) // Strange size of these 2 chars
2158  {
2159  glyph = defaultGlyph;
2160  }
2161 
2162  if( glyph )
2163  textSize.x += glyph->advance;
2164  }
2165 
2166  textSize.y = std::max<float>( textSize.y, charHeight );
2167  commonOffset = std::min<float>( font_information.max_y - defaultGlyph->maxy, commonOffset );
2168  textSize.y -= commonOffset;
2169 
2170  return std::make_pair( textSize, commonOffset );
2171 }
uni_iter uend() const
Return a uni_iter initialized to the end of "this" UTF8 byte sequence.
Definition: utf8.h:287
const FONT_GLYPH_TYPE * LookupGlyph(unsigned int aCodepoint)
uni_iter ubegin() const
Returns a uni_iter initialized to the start of "this" UTF8 byte sequence.
Definition: utf8.h:279
FONT_INFO_TYPE font_information
Definition: gl_resources.cpp:3
uni_iter is a non-mutating iterator that walks through unicode code points in the UTF8 encoded string...
Definition: utf8.h:203

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

Referenced by BitmapText().

◆ computeMinGridSpacing()

double GAL::computeMinGridSpacing ( ) const
protectedinherited

compute minimum grid spacing from the grid settings

Returns
the minimum spacing to use for drawing the grid

Definition at line 237 of file graphics_abstraction_layer.cpp.

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

References KIGFX::GAL::m_gridMinSpacing.

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

◆ computeWorldScale()

void KIGFX::GAL::computeWorldScale ( )
inlineprotectedinherited

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

Definition at line 1119 of file graphics_abstraction_layer.h.

1120  {
1122  }
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 2389 of file opengl_gal.cpp.

2390 {
2392  auto pixelSize = m_worldScale;
2393 
2394  // we need -m_lookAtPoint == -k * pixelSize + 0.5 * pixelSize for OpenGL
2395  // meaning m_lookAtPoint = (k-0.5)*pixelSize with integer k
2398 
2400 }
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 1688 of file opengl_gal.cpp.

1689 {
1690  // Frees memory in the container as well
1691  m_groups.erase( aGroupNumber );
1692 }
GROUPS_MAP m_groups
Stores information about VBO objects (groups)
Definition: opengl_gal.h:327

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

808 {
809  if( aRadius <= 0 )
810  return;
811 
812  // Swap the angles, if start angle is greater than end angle
813  SWAP( aStartAngle, >, aEndAngle );
814 
815  const double alphaIncrement = calcAngleStep( aRadius );
816 
817  Save();
818  m_currentManager->Translate( aCenterPoint.x, aCenterPoint.y, 0.0 );
819 
820  if( m_isFillEnabled )
821  {
822  double alpha;
825 
826  // Triangle fan
827  for( alpha = aStartAngle; ( alpha + alphaIncrement ) < aEndAngle; )
828  {
830  m_currentManager->Vertex( 0.0, 0.0, m_layerDepth );
831  m_currentManager->Vertex( cos( alpha ) * aRadius, sin( alpha ) * aRadius,
832  m_layerDepth );
833  alpha += alphaIncrement;
834  m_currentManager->Vertex( cos( alpha ) * aRadius, sin( alpha ) * aRadius,
835  m_layerDepth );
836  }
837 
838  // The last missing triangle
839  const VECTOR2D endPoint( cos( aEndAngle ) * aRadius, sin( aEndAngle ) * aRadius );
840 
842  m_currentManager->Vertex( 0.0, 0.0, m_layerDepth );
843  m_currentManager->Vertex( cos( alpha ) * aRadius, sin( alpha ) * aRadius, m_layerDepth );
844  m_currentManager->Vertex( endPoint.x, endPoint.y, m_layerDepth );
845  }
846 
847  if( m_isStrokeEnabled )
848  {
850  m_strokeColor.a );
851 
852  VECTOR2D p( cos( aStartAngle ) * aRadius, sin( aStartAngle ) * aRadius );
853  double alpha;
854 
855  for( alpha = aStartAngle + alphaIncrement; alpha <= aEndAngle; alpha += alphaIncrement )
856  {
857  VECTOR2D p_next( cos( alpha ) * aRadius, sin( alpha ) * aRadius );
858  DrawLine( p, p_next );
859 
860  p = p_next;
861  }
862 
863  // Draw the last missing part
864  if( alpha != aEndAngle )
865  {
866  VECTOR2D p_last( cos( aEndAngle ) * aRadius, sin( aEndAngle ) * aRadius );
867  DrawLine( p, p_last );
868  }
869  }
870 
871  Restore();
872 }
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:385
double b
Blue component.
Definition: color4d.h:386
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:329
double a
Alpha component.
Definition: color4d.h:387
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:513
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:687
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:384

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

◆ DrawArcSegment()

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

Draw an arc segment.

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

TODO: Unify Arc routines

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

Reimplemented from KIGFX::GAL.

Definition at line 875 of file opengl_gal.cpp.

878 {
879  if( aRadius <= 0 )
880  {
881  // Arcs of zero radius are a circle of aWidth diameter
882  if( aWidth > 0 )
883  DrawCircle( aCenterPoint, aWidth / 2.0 );
884 
885  return;
886  }
887 
888  // Swap the angles, if start angle is greater than end angle
889  SWAP( aStartAngle, >, aEndAngle );
890 
891  // Calculate the seg count to approximate the arc with aMaxError or less
892  int segCount360 = GetArcToSegmentCount( aRadius, aMaxError, 360.0 );
893  segCount360 = std::max( SEG_PER_CIRCLE_COUNT, segCount360 );
894  double alphaIncrement = 2.0 * M_PI / segCount360;
895 
896  // Refinement: Use a segment count multiple of 2, because we have a control point
897  // on the middle of the arc, and the look is better if it is on a segment junction
898  // because there is no approx error
899  int seg_count = KiROUND( ( aEndAngle - aStartAngle ) / alphaIncrement );
900 
901  if( seg_count % 2 != 0 )
902  seg_count += 1;
903 
904  // Recalculate alphaIncrement with a even integer number of segment
905  if( seg_count )
906  alphaIncrement = ( aEndAngle - aStartAngle ) / seg_count;
907 
908  Save();
909  m_currentManager->Translate( aCenterPoint.x, aCenterPoint.y, 0.0 );
910 
911  if( m_isStrokeEnabled )
912  {
914  m_strokeColor.a );
915 
916  double width = aWidth / 2.0;
917  VECTOR2D startPoint( cos( aStartAngle ) * aRadius, sin( aStartAngle ) * aRadius );
918  VECTOR2D endPoint( cos( aEndAngle ) * aRadius, sin( aEndAngle ) * aRadius );
919 
920  drawStrokedSemiCircle( startPoint, width, aStartAngle + M_PI );
921  drawStrokedSemiCircle( endPoint, width, aEndAngle );
922 
923  VECTOR2D pOuter( cos( aStartAngle ) * ( aRadius + width ),
924  sin( aStartAngle ) * ( aRadius + width ) );
925 
926  VECTOR2D pInner( cos( aStartAngle ) * ( aRadius - width ),
927  sin( aStartAngle ) * ( aRadius - width ) );
928 
929  double alpha;
930 
931  for( alpha = aStartAngle + alphaIncrement; alpha <= aEndAngle; alpha += alphaIncrement )
932  {
933  VECTOR2D pNextOuter( cos( alpha ) * ( aRadius + width ),
934  sin( alpha ) * ( aRadius + width ) );
935  VECTOR2D pNextInner( cos( alpha ) * ( aRadius - width ),
936  sin( alpha ) * ( aRadius - width ) );
937 
938  DrawLine( pOuter, pNextOuter );
939  DrawLine( pInner, pNextInner );
940 
941  pOuter = pNextOuter;
942  pInner = pNextInner;
943  }
944 
945  // Draw the last missing part
946  if( alpha != aEndAngle )
947  {
948  VECTOR2D pLastOuter( cos( aEndAngle ) * ( aRadius + width ),
949  sin( aEndAngle ) * ( aRadius + width ) );
950  VECTOR2D pLastInner( cos( aEndAngle ) * ( aRadius - width ),
951  sin( aEndAngle ) * ( aRadius - width ) );
952 
953  DrawLine( pOuter, pLastOuter );
954  DrawLine( pInner, pLastInner );
955  }
956  }
957 
958  if( m_isFillEnabled )
959  {
961  SetLineWidth( aWidth );
962 
963  VECTOR2D p( cos( aStartAngle ) * aRadius, sin( aStartAngle ) * aRadius );
964  double alpha;
965 
966  for( alpha = aStartAngle + alphaIncrement; alpha <= aEndAngle; alpha += alphaIncrement )
967  {
968  VECTOR2D p_next( cos( alpha ) * aRadius, sin( alpha ) * aRadius );
969  DrawLine( p, p_next );
970 
971  p = p_next;
972  }
973 
974  // Draw the last missing part
975  if( alpha != aEndAngle )
976  {
977  VECTOR2D p_last( cos( aEndAngle ) * aRadius, sin( aEndAngle ) * aRadius );
978  DrawLine( p, p_last );
979  }
980  }
981 
982  Restore();
983 }
bool m_isFillEnabled
Is filling of graphic objects enabled ?
void Restore() override
Restore the context.
double g
Green component.
Definition: color4d.h:385
virtual void SetLineWidth(float aLineWidth)
Set the line width.
double b
Blue component.
Definition: color4d.h:386
void Save() override
Save the context.
VERTEX_MANAGER * m_currentManager
Currently used VERTEX_MANAGER (for storing VERTEX_ITEMs).
Definition: opengl_gal.h:329
double a
Alpha component.
Definition: color4d.h:387
bool m_isStrokeEnabled
Are the outlines stroked ?
COLOR4D m_strokeColor
The color of the outlines.
void Translate(GLfloat aX, GLfloat aY, GLfloat aZ)
Multiply the current matrix by a translation matrix, so newly vertices will be translated by the give...
void DrawLine(const VECTOR2D &aStartPoint, const VECTOR2D &aEndPoint) override
Draw a line.
Definition: opengl_gal.cpp:687
void Color(const COLOR4D &aColor)
Changes currently used color that will be applied to newly added vertices.
void drawStrokedSemiCircle(const VECTOR2D &aCenterPoint, double aRadius, double aAngle)
Draw a stroked semicircle.
COLOR4D m_fillColor
The fill color.
constexpr ret_type KiROUND(fp_type v)
Round a floating point number to an integer using "round halfway cases away from zero".
Definition: util.h:73
#define SWAP(varA, condition, varB)
Swap the variables if a condition is met.
Definition: definitions.h:31
#define SEG_PER_CIRCLE_COUNT
Definition: opengl_gal.h:53
double r
Red component.
Definition: color4d.h:384
int GetArcToSegmentCount(int aRadius, int aErrorMax, double aArcAngleDegree)
void DrawCircle(const VECTOR2D &aCenterPoint, double aRadius) override
Draw a circle using world coordinates.
Definition: opengl_gal.cpp:749

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

◆ DrawBitmap()

void OPENGL_GAL::DrawBitmap ( const BITMAP_BASE aBitmap)
overridevirtual

Draw a bitmap image.

Reimplemented from KIGFX::GAL.

Definition at line 1223 of file opengl_gal.cpp.

1224 {
1225  // We have to calculate the pixel size in users units to draw the image.
1226  // m_worldUnitLength is a factor used for converting IU to inches
1227  double scale = 1.0 / ( aBitmap.GetPPI() * m_worldUnitLength );
1228  double w = (double) aBitmap.GetSizePixels().x * scale;
1229  double h = (double) aBitmap.GetSizePixels().y * scale;
1230 
1231  auto xform = m_currentManager->GetTransformation();
1232 
1233  glm::vec4 v0 = xform * glm::vec4( -w / 2, -h / 2, 0.0, 0.0 );
1234  glm::vec4 v1 = xform * glm::vec4( w / 2, h / 2, 0.0, 0.0 );
1235  glm::vec4 trans = xform[3];
1236 
1237  auto texture_id = m_bitmapCache->RequestBitmap( &aBitmap );
1238 
1239  if( !glIsTexture( texture_id ) ) // ensure the bitmap texture is still valid
1240  return;
1241 
1242  auto oldTarget = GetTarget();
1243 
1244  glPushMatrix();
1245  glTranslated( trans.x, trans.y, trans.z );
1246 
1248  glEnable( GL_TEXTURE_2D );
1249  glActiveTexture( GL_TEXTURE0 );
1250  glBindTexture( GL_TEXTURE_2D, texture_id );
1251 
1252  glBegin( GL_QUADS );
1253  glColor4f( 1.0, 1.0, 1.0, 1.0 );
1254  glTexCoord2f( 0.0, 0.0 );
1255  glVertex3f( v0.x, v0.y, m_layerDepth );
1256  glColor4f( 1.0, 1.0, 1.0, 1.0 );
1257  glTexCoord2f( 1.0, 0.0 );
1258  glVertex3f( v1.x, v0.y, m_layerDepth );
1259  glColor4f( 1.0, 1.0, 1.0, 1.0 );
1260  glTexCoord2f( 1.0, 1.0 );
1261  glVertex3f( v1.x, v1.y, m_layerDepth );
1262  glColor4f( 1.0, 1.0, 1.0, 1.0 );
1263  glTexCoord2f( 0.0, 1.0 );
1264  glVertex3f( v0.x, v1.y, m_layerDepth );
1265  glEnd();
1266 
1267  SetTarget( oldTarget );
1268  glBindTexture( GL_TEXTURE_2D, 0 );
1269 
1270 #ifdef DISABLE_BITMAP_CACHE
1271  glDeleteTextures( 1, &texture_id );
1272 #endif
1273 
1274  glPopMatrix();
1275 }
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:329
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:363
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 2008 of file opengl_gal.cpp.

2009 {
2010  const float TEX_X = font_image.width;
2011  const float TEX_Y = font_image.height;
2012 
2013  // handle space
2014  if( aChar == ' ' )
2015  {
2016  const FONT_GLYPH_TYPE* g = LookupGlyph( 'x' );
2017  wxASSERT( g );
2018 
2019  if( !g ) // Should not happen.
2020  return 0;
2021 
2022  Translate( VECTOR2D( g->advance, 0 ) );
2023  return g->advance;
2024  }
2025 
2026  const FONT_GLYPH_TYPE* glyph = LookupGlyph( aChar );
2027 
2028  // If the glyph is not found (happens for many esoteric unicode chars)
2029  // shows a '?' instead.
2030  if( !glyph )
2031  glyph = LookupGlyph( '?' );
2032 
2033  if( !glyph ) // Should not happen.
2034  return 0;
2035 
2036  const float X = glyph->atlas_x + font_information.smooth_pixels;
2037  const float Y = glyph->atlas_y + font_information.smooth_pixels;
2038  const float XOFF = glyph->minx;
2039 
2040  // adjust for height rounding
2041  const float round_adjust = ( glyph->maxy - glyph->miny )
2042  - float( glyph->atlas_h - font_information.smooth_pixels * 2 );
2043  const float top_adjust = font_information.max_y - glyph->maxy;
2044  const float YOFF = round_adjust + top_adjust;
2045  const float W = glyph->atlas_w - font_information.smooth_pixels * 2;
2046  const float H = glyph->atlas_h - font_information.smooth_pixels * 2;
2047  const float B = 0;
2048 
2049  m_currentManager->Reserve( 6 );
2050  Translate( VECTOR2D( XOFF, YOFF ) );
2051 
2052  /* Glyph:
2053  * v0 v1
2054  * +--+
2055  * | /|
2056  * |/ |
2057  * +--+
2058  * v2 v3
2059  */
2060  m_currentManager->Shader( SHADER_FONT, X / TEX_X, ( Y + H ) / TEX_Y );
2061  m_currentManager->Vertex( -B, -B, 0 ); // v0
2062 
2063  m_currentManager->Shader( SHADER_FONT, ( X + W ) / TEX_X, ( Y + H ) / TEX_Y );
2064  m_currentManager->Vertex( W + B, -B, 0 ); // v1
2065 
2066  m_currentManager->Shader( SHADER_FONT, X / TEX_X, Y / TEX_Y );
2067  m_currentManager->Vertex( -B, H + B, 0 ); // v2
2068 
2069 
2070  m_currentManager->Shader( SHADER_FONT, ( X + W ) / TEX_X, ( Y + H ) / TEX_Y );
2071  m_currentManager->Vertex( W + B, -B, 0 ); // v1
2072 
2073  m_currentManager->Shader( SHADER_FONT, X / TEX_X, Y / TEX_Y );
2074  m_currentManager->Vertex( -B, H + B, 0 ); // v2
2075 
2076  m_currentManager->Shader( SHADER_FONT, ( X + W ) / TEX_X, Y / TEX_Y );
2077  m_currentManager->Vertex( W + B, H + B, 0 ); // v3
2078 
2079  Translate( VECTOR2D( -XOFF + glyph->advance, -YOFF ) );
2080 
2081  return glyph->advance;
2082 }
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:329
VECTOR2< double > VECTOR2D
Definition: vector2d.h:621
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 2085 of file opengl_gal.cpp.

2086 {
2087  // To draw an overbar, simply draw an overbar
2088  const FONT_GLYPH_TYPE* glyph = LookupGlyph( '_' );
2089  wxCHECK( glyph, /* void */ );
2090 
2091  const float H = glyph->maxy - glyph->miny;
2092 
2093  Save();
2094 
2095  Translate( VECTOR2D( -aLength, -aHeight ) );
2096 
2097  m_currentManager->Reserve( 6 );
2099 
2100  m_currentManager->Shader( 0 );
2101 
2102  m_currentManager->Vertex( 0, 0, 0 ); // v0
2103  m_currentManager->Vertex( aLength, 0, 0 ); // v1
2104  m_currentManager->Vertex( 0, H, 0 ); // v2
2105 
2106  m_currentManager->Vertex( aLength, 0, 0 ); // v1
2107  m_currentManager->Vertex( 0, H, 0 ); // v2
2108  m_currentManager->Vertex( aLength, H, 0 ); // v3
2109 
2110  Restore();
2111 }
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:385
const FONT_GLYPH_TYPE * LookupGlyph(unsigned int aCodepoint)
double b
Blue component.
Definition: color4d.h:386
void Save() override
Save the context.
VERTEX_MANAGER * m_currentManager
Currently used VERTEX_MANAGER (for storing VERTEX_ITEMs).
Definition: opengl_gal.h:329
double a
Alpha component.
Definition: color4d.h:387
COLOR4D m_strokeColor
The color of the outlines.
VECTOR2< double > VECTOR2D
Definition: vector2d.h:621
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:384

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

750 {
751  if( m_isFillEnabled )
752  {
755 
756  /* Draw a triangle that contains the circle, then shade it leaving only the circle.
757  * Parameters given to Shader() are indices of the triangle's vertices
758  * (if you want to understand more, check the vertex shader source [shader.vert]).
759  * Shader uses this coordinates to determine if fragments are inside the circle or not.
760  * Does the calculations in the vertex shader now (pixel alignment)
761  * v2
762  * /\
763  * //\\
764  * v0 /_\/_\ v1
765  */
766  m_currentManager->Shader( SHADER_FILLED_CIRCLE, 1.0, aRadius );
767  m_currentManager->Vertex( aCenterPoint.x, aCenterPoint.y, m_layerDepth );
768 
769  m_currentManager->Shader( SHADER_FILLED_CIRCLE, 2.0, aRadius );
770  m_currentManager->Vertex( aCenterPoint.x, aCenterPoint.y, m_layerDepth );
771 
772  m_currentManager->Shader( SHADER_FILLED_CIRCLE, 3.0, aRadius );
773  m_currentManager->Vertex( aCenterPoint.x, aCenterPoint.y, m_layerDepth );
774  }
775  if( m_isStrokeEnabled )
776  {
779  m_strokeColor.a );
780 
781  /* Draw a triangle that contains the circle, then shade it leaving only the circle.
782  * Parameters given to Shader() are indices of the triangle's vertices
783  * (if you want to understand more, check the vertex shader source [shader.vert]).
784  * and the line width. Shader uses this coordinates to determine if fragments are
785  * inside the circle or not.
786  * v2
787  * /\
788  * //\\
789  * v0 /_\/_\ v1
790  */
792  m_currentManager->Vertex( aCenterPoint.x, // v0
793  aCenterPoint.y, m_layerDepth );
794 
796  m_currentManager->Vertex( aCenterPoint.x, // v1
797  aCenterPoint.y, m_layerDepth );
798 
800  m_currentManager->Vertex( aCenterPoint.x, aCenterPoint.y, // v2
801  m_layerDepth );
802  }
803 }
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:385
double b
Blue component.
Definition: color4d.h:386
double m_layerDepth
The actual layer depth.
VERTEX_MANAGER * m_currentManager
Currently used VERTEX_MANAGER (for storing VERTEX_ITEMs).
Definition: opengl_gal.h:329
double a
Alpha component.
Definition: color4d.h:387
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:384
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 1813 of file opengl_gal.cpp.

1814 {
1815  // Now we should only store the position of the mouse cursor
1816  // The real drawing routines are in blitCursor()
1817  //VECTOR2D screenCursor = m_worldScreenMatrix * aCursorPosition;
1818  //m_cursorPosition = m_screenWorldMatrix * VECTOR2D( screenCursor.x, screenCursor.y );
1819  m_cursorPosition = aCursorPosition;
1820 }
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 1204 of file opengl_gal.cpp.

1207 {
1208  std::vector<VECTOR2D> output;
1209  std::vector<VECTOR2D> pointCtrl;
1210 
1211  pointCtrl.push_back( aStartPoint );
1212  pointCtrl.push_back( aControlPointA );
1213  pointCtrl.push_back( aControlPointB );
1214  pointCtrl.push_back( aEndPoint );
1215 
1216  BEZIER_POLY converter( pointCtrl );
1217  converter.GetPoly( output, aFilterValue );
1218 
1219  DrawPolyline( &output[0], output.size() );
1220 }
void DrawPolyline(const std::deque< VECTOR2D > &aPointList) override
Draw a polyline.
Bezier curves to polygon converter.
Definition: bezier_curves.h:36

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

◆ drawFilledSemiCircle()

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

Draw a filled semicircle.

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

Definition at line 1887 of file opengl_gal.cpp.

1888 {
1889  Save();
1890 
1891  m_currentManager->Reserve( 3 );
1892  m_currentManager->Translate( aCenterPoint.x, aCenterPoint.y, 0.0f );
1893  m_currentManager->Rotate( aAngle, 0.0f, 0.0f, 1.0f );
1894 
1895  /* Draw a triangle that contains the semicircle, then shade it to leave only
1896  * the semicircle. Parameters given to Shader() are indices of the triangle's vertices
1897  * (if you want to understand more, check the vertex shader source [shader.vert]).
1898  * Shader uses these coordinates to determine if fragments are inside the semicircle or not.
1899  * v2
1900  * /\
1901  * /__\
1902  * v0 //__\\ v1
1903  */
1905  m_currentManager->Vertex( -aRadius * 3.0f / sqrt( 3.0f ), 0.0f, m_layerDepth ); // v0
1906 
1908  m_currentManager->Vertex( aRadius * 3.0f / sqrt( 3.0f ), 0.0f, m_layerDepth ); // v1
1909 
1911  m_currentManager->Vertex( 0.0f, aRadius * 2.0f, m_layerDepth ); // v2
1912 
1913  Restore();
1914 }
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:329
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 1394 of file opengl_gal.cpp.

1395 {
1398 
1400 
1401  // sub-pixel lines all render the same
1402  float minorLineWidth = std::fmax( 1.0f,
1404  float majorLineWidth = minorLineWidth * 2.0f;
1405 
1406  // Draw the axis and grid
1407  // For the drawing the start points, end points and increments have
1408  // to be calculated in world coordinates
1409  VECTOR2D worldStartPoint = m_screenWorldMatrix * VECTOR2D( 0.0, 0.0 );
1410  VECTOR2D worldEndPoint = m_screenWorldMatrix * VECTOR2D( m_screenSize );
1411 
1412  // Draw axes if desired
1413  if( m_axesEnabled )
1414  {
1415  SetLineWidth( minorLineWidth );
1417 
1418  DrawLine( VECTOR2D( worldStartPoint.x, 0 ), VECTOR2D( worldEndPoint.x, 0 ) );
1419  DrawLine( VECTOR2D( 0, worldStartPoint.y ), VECTOR2D( 0, worldEndPoint.y ) );
1420  }
1421 
1422  // force flush
1424 
1425  if( !m_gridVisibility || m_gridSize.x == 0 || m_gridSize.y == 0 )
1426  return;
1427 
1428  VECTOR2D gridScreenSize( m_gridSize );
1429 
1430  double gridThreshold = computeMinGridSpacing() / m_worldScale;
1431 
1433  gridThreshold *= 2.0;
1434 
1435  // If we cannot display the grid density, scale down by a tick size and
1436  // try again. Eventually, we get some representation of the grid
1437  while( std::min( gridScreenSize.x, gridScreenSize.y ) <= gridThreshold )
1438  {
1439  gridScreenSize = gridScreenSize * static_cast<double>( m_gridTick );
1440  }
1441 
1442  // Compute grid starting and ending indexes to draw grid points on the
1443  // visible screen area
1444  // Note: later any point coordinate will be offsetted by m_gridOrigin
1445  int gridStartX = KiROUND( ( worldStartPoint.x - m_gridOrigin.x ) / gridScreenSize.x );
1446  int gridEndX = KiROUND( ( worldEndPoint.x - m_gridOrigin.x ) / gridScreenSize.x );
1447  int gridStartY = KiROUND( ( worldStartPoint.y - m_gridOrigin.y ) / gridScreenSize.y );
1448  int gridEndY = KiROUND( ( worldEndPoint.y - m_gridOrigin.y ) / gridScreenSize.y );
1449 
1450  // Ensure start coordinate > end coordinate
1451  SWAP( gridStartX, >, gridEndX );
1452  SWAP( gridStartY, >, gridEndY );
1453 
1454  // Ensure the grid fills the screen
1455  --gridStartX;
1456  ++gridEndX;
1457  --gridStartY;
1458  ++gridEndY;
1459 
1460  glDisable( GL_DEPTH_TEST );
1461  glDisable( GL_TEXTURE_2D );
1462 
1463  if( m_gridStyle == GRID_STYLE::DOTS )
1464  {
1465  glEnable( GL_STENCIL_TEST );
1466  glStencilFunc( GL_ALWAYS, 1, 1 );
1467  glStencilOp( GL_KEEP, GL_KEEP, GL_INCR );
1468  glColor4d( 0.0, 0.0, 0.0, 0.0 );
1469  SetStrokeColor( COLOR4D( 0.0, 0.0, 0.0, 0.0 ) );
1470  }
1471  else
1472  {
1473  glColor4d( m_gridColor.r, m_gridColor.g, m_gridColor.b, m_gridColor.a );
1475  }
1476 
1478  {
1479  // Vertical positions
1480  for( int j = gridStartY; j <= gridEndY; j++ )
1481  {
1482  bool tickY = ( j % m_gridTick == 0 );
1483  const double posY = j * gridScreenSize.y + m_gridOrigin.y;
1484 
1485  // Horizontal positions
1486  for( int i = gridStartX; i <= gridEndX; i++ )
1487  {
1488  bool tickX = ( i % m_gridTick == 0 );
1489  SetLineWidth( ( ( tickX && tickY ) ? majorLineWidth : minorLineWidth ) );
1490  auto lineLen = 2.0 * GetLineWidth();
1491  auto posX = i * gridScreenSize.x + m_gridOrigin.x;
1492 
1493  DrawLine( VECTOR2D( posX - lineLen, posY ), VECTOR2D( posX + lineLen, posY ) );
1494  DrawLine( VECTOR2D( posX, posY - lineLen ), VECTOR2D( posX, posY + lineLen ) );
1495  }
1496  }
1497 
1499  }
1500  else
1501  {
1502  // Vertical lines
1503  for( int j = gridStartY; j <= gridEndY; j++ )
1504  {
1505  const double y = j * gridScreenSize.y + m_gridOrigin.y;
1506 
1507  // If axes are drawn, skip the lines that would cover them
1508  if( m_axesEnabled && y == 0.0 )
1509  continue;
1510 
1511  SetLineWidth( ( j % m_gridTick == 0 ) ? majorLineWidth : minorLineWidth );
1512  VECTOR2D a( gridStartX * gridScreenSize.x + m_gridOrigin.x, y );
1513  VECTOR2D b( gridEndX * gridScreenSize.x + m_gridOrigin.x, y );
1514 
1515  DrawLine( a, b );
1516  }
1517 
1519 
1520  if( m_gridStyle == GRID_STYLE::DOTS )
1521  {
1522  glStencilFunc( GL_NOTEQUAL, 0, 1 );
1523  glColor4d( m_gridColor.r, m_gridColor.g, m_gridColor.b, m_gridColor.a );
1525  }
1526 
1527  // Horizontal lines
1528  for( int i = gridStartX; i <= gridEndX; i++ )
1529  {
1530  const double x = i * gridScreenSize.x + m_gridOrigin.x;
1531 
1532  // If axes are drawn, skip the lines that would cover them
1533  if( m_axesEnabled && x == 0.0 )
1534  continue;
1535 
1536  SetLineWidth( ( i % m_gridTick == 0 ) ? majorLineWidth : minorLineWidth );
1537  VECTOR2D a( x, gridStartY * gridScreenSize.y + m_gridOrigin.y );
1538  VECTOR2D b( x, gridEndY * gridScreenSize.y + m_gridOrigin.y );
1539  DrawLine( a, b );
1540  }
1541 
1543 
1544  if( m_gridStyle == GRID_STYLE::DOTS )
1545  glDisable( GL_STENCIL_TEST );
1546  }
1547 
1548  glEnable( GL_DEPTH_TEST );
1549  glEnable( GL_TEXTURE_2D );
1550 }
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:385
unsigned int m_mainBuffer
Main rendering target.
Definition: opengl_gal.h:338
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:386
Auxiliary rendering target (noncached)
Definition: definitions.h:49
double getWorldPixelSize() const
Definition: opengl_gal.cpp:404
COLOR4D m_gridColor
Color of the grid.
double m_worldScale
The scale factor world->screen.
double a
Alpha component.
Definition: color4d.h:387
VECTOR2< double > VECTOR2D
Definition: vector2d.h:621
bool m_gridVisibility
Should the grid be shown.
OPENGL_COMPOSITOR * m_compositor
Handles multiple rendering targets.
Definition: opengl_gal.h:337
void DrawLine(const VECTOR2D &aStartPoint, const VECTOR2D &aEndPoint) override
Draw a line.
Definition: opengl_gal.cpp:687
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:384
VERTEX_MANAGER * m_nonCachedManager
Container for storing non-cached VERTEX_ITEMs.
Definition: opengl_gal.h:332
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 1661 of file opengl_gal.cpp.

1662 {
1663  auto group = m_groups.find( aGroupNumber );
1664 
1665  if( group != m_groups.end() )
1666  m_cachedManager->DrawItem( *group->second );
1667 }
GROUPS_MAP m_groups
Stores information about VBO objects (groups)
Definition: opengl_gal.h:327
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:331

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

688 {
690 
691  drawLineQuad( aStartPoint, aEndPoint );
692 }
void drawLineQuad(const VECTOR2D &aStartPoint, const VECTOR2D &aEndPoint)
Draw a quad for the line.
double g
Green component.
Definition: color4d.h:385
double b
Blue component.
Definition: color4d.h:386
VERTEX_MANAGER * m_currentManager
Currently used VERTEX_MANAGER (for storing VERTEX_ITEMs).
Definition: opengl_gal.h:329
double a
Alpha component.
Definition: color4d.h:387
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:384

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

1824 {
1825  /* Helper drawing: ____--- v3 ^
1826  * ____---- ... \ \
1827  * ____---- ... \ end \
1828  * v1 ____---- ... ____---- \ width
1829  * ---- ...___---- \ \
1830  * \ ___...-- \ v
1831  * \ ____----... ____---- v2
1832  * ---- ... ____----
1833  * start \ ... ____----
1834  * \... ____----
1835  * ----
1836  * v0
1837  * dots mark triangles' hypotenuses
1838  */
1839 
1840  auto v1 = m_currentManager->GetTransformation()
1841  * glm::vec4( aStartPoint.x, aStartPoint.y, 0.0, 0.0 );
1843  * glm::vec4( aEndPoint.x, aEndPoint.y, 0.0, 0.0 );
1844 
1845  VECTOR2D vs( v2.x - v1.x, v2.y - v1.y );
1846 
1847  m_currentManager->Reserve( 6 );
1848 
1849  // Line width is maintained by the vertex shader
1851  m_currentManager->Vertex( aStartPoint, m_layerDepth );
1852 
1854  m_currentManager->Vertex( aStartPoint, m_layerDepth );
1855 
1857  m_currentManager->Vertex( aEndPoint, m_layerDepth );
1858 
1860  m_currentManager->Vertex( aEndPoint, m_layerDepth );
1861 
1863  m_currentManager->Vertex( aEndPoint, m_layerDepth );
1864 
1866  m_currentManager->Vertex( aStartPoint, m_layerDepth );
1867 }
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:329
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 1063 of file opengl_gal.cpp.

1064 {
1065  wxCHECK( aPointList.size() >= 2, /* void */ );
1066  auto points = std::unique_ptr<GLdouble[]>( new GLdouble[3 * aPointList.size()] );
1067  GLdouble* ptr = points.get();
1068 
1069  for( const VECTOR2D& p : aPointList )
1070  {
1071  *ptr++ = p.x;
1072  *ptr++ = p.y;
1073  *ptr++ = m_layerDepth;
1074  }
1075 
1076  drawPolygon( points.get(), aPointList.size() );
1077 }
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 1080 of file opengl_gal.cpp.

1081 {
1082  wxCHECK( aListSize >= 2, /* void */ );
1083  auto points = std::unique_ptr<GLdouble[]>( new GLdouble[3 * aListSize] );
1084  GLdouble* target = points.get();
1085  const VECTOR2D* src = aPointList;
1086 
1087  for( int i = 0; i < aListSize; ++i )
1088  {
1089  *target++ = src->x;
1090  *target++ = src->y;
1091  *target++ = m_layerDepth;
1092  ++src;
1093  }
1094 
1095  drawPolygon( points.get(), aListSize );
1096 }
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 1168 of file opengl_gal.cpp.

1169 {
1170  if( aPolySet.IsTriangulationUpToDate() )
1171  {
1172  drawTriangulatedPolyset( aPolySet, aStrokeTriangulation );
1173  return;
1174  }
1175 
1176  for( int j = 0; j < aPolySet.OutlineCount(); ++j )
1177  {
1178  const SHAPE_LINE_CHAIN& outline = aPolySet.COutline( j );
1179  DrawPolygon( outline );
1180  }
1181 }
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 containing arcs as well as line segments: A chain of connected line and/or arc s...
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 1184 of file opengl_gal.cpp.

1185 {
1186  wxCHECK( aPolygon.PointCount() >= 2, /* void */ );
1187 
1188  const int pointCount = aPolygon.SegmentCount() + 1;
1189  std::unique_ptr<GLdouble[]> points( new GLdouble[3 * pointCount] );
1190  GLdouble* ptr = points.get();
1191 
1192  for( int i = 0; i < pointCount; ++i )
1193  {
1194  const VECTOR2I& p = aPolygon.CPoint( i );
1195  *ptr++ = p.x;
1196  *ptr++ = p.y;
1197  *ptr++ = m_layerDepth;
1198  }
1199 
1200  drawPolygon( points.get(), pointCount );
1201 }
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 1951 of file opengl_gal.cpp.

1952 {
1953  if( m_isFillEnabled )
1954  {
1957 
1958  // Any non convex polygon needs to be tesselated
1959  // for this purpose the GLU standard functions are used
1960  TessParams params = { m_currentManager, m_tessIntersects };
1961  gluTessBeginPolygon( m_tesselator, &params );
1962  gluTessBeginContour( m_tesselator );
1963 
1964  GLdouble* point = aPoints;
1965 
1966  for( int i = 0; i < aPointCount; ++i )
1967  {
1968  gluTessVertex( m_tesselator, point, point );
1969  point += 3; // 3 coordinates
1970  }
1971 
1972  gluTessEndContour( m_tesselator );
1973  gluTessEndPolygon( m_tesselator );
1974 
1975  // Free allocated intersecting points
1976  m_tessIntersects.clear();
1977  }
1978 
1979  if( m_isStrokeEnabled )
1980  {
1981  drawPolyline(
1982  [&]( int idx )
1983  {
1984  return VECTOR2D( aPoints[idx * 3], aPoints[idx * 3 + 1] );
1985  },
1986  aPointCount );
1987  }
1988 }
bool m_isFillEnabled
Is filling of graphic objects enabled ?
std::deque< boost::shared_array< GLdouble > > m_tessIntersects
Definition: opengl_gal.h:367
double g
Green component.
Definition: color4d.h:385
double b
Blue component.
Definition: color4d.h:386
VERTEX_MANAGER * m_currentManager
Currently used VERTEX_MANAGER (for storing VERTEX_ITEMs).
Definition: opengl_gal.h:329
double a
Alpha component.
Definition: color4d.h:387
bool m_isStrokeEnabled
Are the outlines stroked ?
VECTOR2< double > VECTOR2D
Definition: vector2d.h:621
GLUtesselator * m_tesselator
Definition: opengl_gal.h:366
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:384

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

1026 {
1027  drawPolyline(
1028  [&]( int idx )
1029  {
1030  return aPointList[idx];
1031  },
1032  aPointList.size() );
1033 }
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 1036 of file opengl_gal.cpp.

1037 {
1038  drawPolyline(
1039  [&]( int idx )
1040  {
1041  return aPointList[idx];
1042  },
1043  aListSize );
1044 }
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 1047 of file opengl_gal.cpp.

1048 {
1049  auto numPoints = aLineChain.PointCount();
1050 
1051  if( aLineChain.IsClosed() )
1052  numPoints += 1;
1053 
1054  drawPolyline(
1055  [&]( int idx )
1056  {
1057  return aLineChain.CPoint( idx );
1058  },
1059  numPoints );
1060 }
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 1991 of file opengl_gal.cpp.

1992 {
1993  wxCHECK( aPointCount >= 2, /* return */ );
1994 
1996  int i;
1997 
1998  for( i = 1; i < aPointCount; ++i )
1999  {
2000  auto start = aPointGetter( i - 1 );
2001  auto end = aPointGetter( i );
2002 
2003  drawLineQuad( start, end );
2004  }
2005 }
void drawLineQuad(const VECTOR2D &aStartPoint, const VECTOR2D &aEndPoint)
Draw a quad for the line.
double g
Green component.
Definition: color4d.h:385
double b
Blue component.
Definition: color4d.h:386
VERTEX_MANAGER * m_currentManager
Currently used VERTEX_MANAGER (for storing VERTEX_ITEMs).
Definition: opengl_gal.h:329
double a
Alpha component.
Definition: color4d.h:387
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:384

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

987 {
988  // Compute the diagonal points of the rectangle
989  VECTOR2D diagonalPointA( aEndPoint.x, aStartPoint.y );
990  VECTOR2D diagonalPointB( aStartPoint.x, aEndPoint.y );
991 
992  // Fill the rectangle
993  if( m_isFillEnabled )
994  {
998 
999  m_currentManager->Vertex( aStartPoint.x, aStartPoint.y, m_layerDepth );
1000  m_currentManager->Vertex( diagonalPointA.x, diagonalPointA.y, m_layerDepth );
1001  m_currentManager->Vertex( aEndPoint.x, aEndPoint.y, m_layerDepth );
1002 
1003  m_currentManager->Vertex( aStartPoint.x, aStartPoint.y, m_layerDepth );
1004  m_currentManager->Vertex( aEndPoint.x, aEndPoint.y, m_layerDepth );
1005  m_currentManager->Vertex( diagonalPointB.x, diagonalPointB.y, m_layerDepth );
1006  }
1007 
1008  // Stroke the outline
1009  if( m_isStrokeEnabled )
1010  {
1012  m_strokeColor.a );
1013 
1014  std::deque<VECTOR2D> pointList;
1015  pointList.push_back( aStartPoint );
1016  pointList.push_back( diagonalPointA );
1017  pointList.push_back( aEndPoint );
1018  pointList.push_back( diagonalPointB );
1019  pointList.push_back( aStartPoint );
1020  DrawPolyline( pointList );
1021  }
1022 }
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:385
double b
Blue component.
Definition: color4d.h:386
double m_layerDepth
The actual layer depth.
VERTEX_MANAGER * m_currentManager
Currently used VERTEX_MANAGER (for storing VERTEX_ITEMs).
Definition: opengl_gal.h:329
double a
Alpha component.
Definition: color4d.h:387
bool m_isStrokeEnabled
Are the outlines stroked ?
COLOR4D m_strokeColor
The color of the outlines.
void Color(const COLOR4D &aColor)
Changes currently used color that will be applied to newly added vertices.
void DrawPolyline(const std::deque< VECTOR2D > &aPointList) override
Draw a polyline.
COLOR4D m_fillColor
The fill color.
void Shader(GLfloat aShaderType, GLfloat aParam1=0.0f, GLfloat aParam2=0.0f, GLfloat aParam3=0.0f)
Change currently used shader and its parameters that will be applied to newly added vertices.
double r
Red component.
Definition: color4d.h:384

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

697 {
698  VECTOR2D startEndVector = aEndPoint - aStartPoint;
699  double lineLength = startEndVector.EuclideanNorm();
700 
701  float startx = aStartPoint.x;
702  float starty = aStartPoint.y;
703  float endx = aStartPoint.x + lineLength;
704  float endy = aStartPoint.y + lineLength;
705 
706  // Be careful about floating point rounding. As we draw segments in larger and larger
707  // coordinates, the shader (which uses floats) will lose precision and stop drawing small
708  // segments. In this case, we need to draw a circle for the minimal segment.
709  if( startx == endx || starty == endy )
710  {
711  DrawCircle( aStartPoint, aWidth / 2 );
712  return;
713  }
714 
715  if( m_isFillEnabled || aWidth == 1.0 )
716  {
718 
719  SetLineWidth( aWidth );
720  drawLineQuad( aStartPoint, aEndPoint );
721  }
722  else
723  {
724  auto lineAngle = startEndVector.Angle();
725  // Outlined tracks
726 
727  SetLineWidth( 1.0 );
729  m_strokeColor.a );
730 
731  Save();
732 
733  m_currentManager->Translate( aStartPoint.x, aStartPoint.y, 0.0 );
734  m_currentManager->Rotate( lineAngle, 0.0f, 0.0f, 1.0f );
735 
736  drawLineQuad( VECTOR2D( 0.0, aWidth / 2.0 ), VECTOR2D( lineLength, aWidth / 2.0 ) );
737 
738  drawLineQuad( VECTOR2D( 0.0, -aWidth / 2.0 ), VECTOR2D( lineLength, -aWidth / 2.0 ) );
739 
740  // Draw line caps
741  drawStrokedSemiCircle( VECTOR2D( 0.0, 0.0 ), aWidth / 2, M_PI / 2 );
742  drawStrokedSemiCircle( VECTOR2D( lineLength, 0.0 ), aWidth / 2, -M_PI / 2 );
743 
744  Restore();
745  }
746 }
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:385
virtual void SetLineWidth(float aLineWidth)
Set the line width.
double b
Blue component.
Definition: color4d.h:386
void Save() override
Save the context.
VERTEX_MANAGER * m_currentManager
Currently used VERTEX_MANAGER (for storing VERTEX_ITEMs).
Definition: opengl_gal.h:329
double a
Alpha component.
Definition: color4d.h:387
COLOR4D m_strokeColor
The color of the outlines.
VECTOR2< double > VECTOR2D
Definition: vector2d.h:621
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:384
void DrawCircle(const VECTOR2D &aCenterPoint, double aRadius) override
Draw a circle using world coordinates.
Definition: opengl_gal.cpp:749

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

1871 {
1872  if( m_isFillEnabled )
1873  {
1875  drawFilledSemiCircle( aCenterPoint, aRadius, aAngle );
1876  }
1877 
1878  if( m_isStrokeEnabled )
1879  {
1881  m_strokeColor.a );
1882  drawStrokedSemiCircle( aCenterPoint, aRadius, aAngle );
1883  }
1884 }
bool m_isFillEnabled
Is filling of graphic objects enabled ?
double g
Green component.
Definition: color4d.h:385
double b
Blue component.
Definition: color4d.h:386
VERTEX_MANAGER * m_currentManager
Currently used VERTEX_MANAGER (for storing VERTEX_ITEMs).
Definition: opengl_gal.h:329
double a
Alpha component.
Definition: color4d.h:387
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:384
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 1917 of file opengl_gal.cpp.

1919 {
1920  double outerRadius = aRadius + ( m_lineWidth / 2 );
1921 
1922  Save();
1923 
1924  m_currentManager->Reserve( 3 );
1925  m_currentManager->Translate( aCenterPoint.x, aCenterPoint.y, 0.0f );
1926  m_currentManager->Rotate( aAngle, 0.0f, 0.0f, 1.0f );
1927 
1928  /* Draw a triangle that contains the semicircle, then shade it to leave only
1929  * the semicircle. Parameters given to Shader() are indices of the triangle's vertices
1930  * (if you want to understand more, check the vertex shader source [shader.vert]), the
1931  * radius and the line width. Shader uses these coordinates to determine if fragments are
1932  * inside the semicircle or not.
1933  * v2
1934  * /\
1935  * /__\
1936  * v0 //__\\ v1
1937  */
1939  m_currentManager->Vertex( -outerRadius * 3.0f / sqrt( 3.0f ), 0.0f, m_layerDepth ); // v0
1940 
1942  m_currentManager->Vertex( outerRadius * 3.0f / sqrt( 3.0f ), 0.0f, m_layerDepth ); // v1
1943 
1945  m_currentManager->Vertex( 0.0f, outerRadius * 2.0f, m_layerDepth ); // v2
1946 
1947  Restore();
1948 }
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:329
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 1099 of file opengl_gal.cpp.

1101 {
1104 
1105  if( m_isFillEnabled )
1106  {
1107  for( unsigned int j = 0; j < aPolySet.TriangulatedPolyCount(); ++j )
1108  {
1109  auto triPoly = aPolySet.TriangulatedPolygon( j );
1110 
1111  for( size_t i = 0; i < triPoly->GetTriangleCount(); i++ )
1112  {
1113  VECTOR2I a, b, c;
1114  triPoly->GetTriangle( i, a, b, c );
1118  }
1119  }
1120  }
1121 
1122  if( m_isStrokeEnabled )
1123  {
1124  for( int j = 0; j < aPolySet.OutlineCount(); ++j )
1125  {
1126  const auto& poly = aPolySet.Polygon( j );
1127 
1128  for( const auto& lc : poly )
1129  {
1130  DrawPolyline( lc );
1131  }
1132  }
1133  }
1134 
1135  if( ADVANCED_CFG::GetCfg().m_DrawTriangulationOutlines )
1136  {
1137  aStrokeTriangulation = true;
1138  SetStrokeColor( COLOR4D( 0.0, 1.0, 0.2, 1.0 ) );
1139  }
1140 
1141  if( aStrokeTriangulation )
1142  {
1143  COLOR4D oldStrokeColor = m_strokeColor;
1144  double oldLayerDepth = m_layerDepth;
1145 
1146  SetLayerDepth( m_layerDepth - 1 );
1147 
1148  for( unsigned int j = 0; j < aPolySet.TriangulatedPolyCount(); ++j )
1149  {
1150  auto triPoly = aPolySet.TriangulatedPolygon( j );
1151 
1152  for( size_t i = 0; i < triPoly->GetTriangleCount(); i++ )
1153  {
1154  VECTOR2I a, b, c;
1155  triPoly->GetTriangle( i, a, b, c );
1156  DrawLine( a, b );
1157  DrawLine( b, c );
1158  DrawLine( c, a );
1159  }
1160  }
1161 
1162  SetStrokeColor( oldStrokeColor );
1163  SetLayerDepth( oldLayerDepth );
1164  }
1165 }
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:385
virtual void SetLayerDepth(double aLayerDepth)
Set the depth of the layer (position on the z-axis)
double b
Blue component.
Definition: color4d.h:386
double m_layerDepth
The actual layer depth.
VERTEX_MANAGER * m_currentManager
Currently used VERTEX_MANAGER (for storing VERTEX_ITEMs).
Definition: opengl_gal.h:329
double a
Alpha component.
Definition: color4d.h:387
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:687
void Color(const COLOR4D &aColor)
Changes currently used color that will be applied to newly added vertices.
void DrawPolyline(const std::deque< VECTOR2D > &aPointList) override
Draw a polyline.
virtual void SetStrokeColor(const COLOR4D &aColor)
Set the stroke color.
COLOR4D m_fillColor
The fill color.
static const ADVANCED_CFG & GetCfg()
Get the singleton instance's config, which is shared by all consumers.
void Shader(GLfloat aShaderType, GLfloat aParam1=0.0f, GLfloat aParam2=0.0f, GLfloat aParam3=0.0f)
Change currently used shader and its parameters that will be applied to newly added vertices.
double r
Red component.
Definition: color4d.h:384
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 2375 of file opengl_gal.cpp.

2376 {
2377  m_cachedManager->EnableDepthTest( aEnabled );
2378  m_nonCachedManager->EnableDepthTest( aEnabled );
2379  m_overlayManager->EnableDepthTest( aEnabled );
2380 }
VERTEX_MANAGER * m_overlayManager
Container for storing overlaid VERTEX_ITEMs.
Definition: opengl_gal.h:333
VERTEX_MANAGER * m_cachedManager
Container for storing cached VERTEX_ITEMs.
Definition: opengl_gal.h:331
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:332

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

◆ EndDiffLayer()

void OPENGL_GAL::EndDiffLayer ( )
overridevirtual

Ends rendering of a differential layer.

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

Reimplemented from KIGFX::GAL.

Definition at line 1782 of file opengl_gal.cpp.

1783 {
1784  glBlendEquation( GL_MAX );
1786  glBlendEquation( GL_FUNC_ADD );
1787 
1789 }
virtual void DrawBuffer(unsigned int aBufferHandle) override
Draw the selected buffer to the output buffer.
unsigned int m_mainBuffer
Main rendering target.
Definition: opengl_gal.h:338
VERTEX_MANAGER * m_currentManager
Currently used VERTEX_MANAGER (for storing VERTEX_ITEMs).
Definition: opengl_gal.h:329
OPENGL_COMPOSITOR * m_compositor
Handles multiple rendering targets.
Definition: opengl_gal.h:337
void EndDrawing() const
Finish drawing operations.
unsigned int m_tempBuffer
Temporary rendering target (for diffing etc.)
Definition: opengl_gal.h:340

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

◆ EndDrawing()

void OPENGL_GAL::EndDrawing ( )
overridevirtual

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

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

Reimplemented from KIGFX::GAL.

Definition at line 580 of file opengl_gal.cpp.

581 {
582  wxASSERT_MSG( m_isContextLocked, wxT( "What happened to the context lock?" ) );
583 
584  PROF_TIMER cntTotal("gl-end-total");
585  PROF_TIMER cntEndCached("gl-end-cached");
586  PROF_TIMER cntEndNoncached("gl-end-noncached");
587  PROF_TIMER cntEndOverlay("gl-end-overlay");
588  PROF_TIMER cntComposite("gl-composite");
589  PROF_TIMER cntSwap("gl-swap");
590 
591  cntTotal.Start();
592  // Cached & non-cached containers are rendered to the same buffer
594 
595  cntEndNoncached.Start();
597  cntEndNoncached.Stop();
598 
599  cntEndCached.Start();
601  cntEndCached.Stop();
602 
603  cntEndOverlay.Start();
604  // Overlay container is rendered to a different buffer
605  if( m_overlayBuffer )
607 
609  cntEndOverlay.Stop();
610 
611  cntComposite.Start();
612  // Be sure that the framebuffer is not colorized (happens on specific GPU&drivers combinations)
613  glColor4d( 1.0, 1.0, 1.0, 1.0 );
614 
615  // Draw the remaining contents, blit the rendering targets to the screen, swap the buffers
617 
618  if( m_overlayBuffer )
620 
622  blitCursor();
623 
624  cntComposite.Stop();
625 
626  cntSwap.Start();
627  SwapBuffers();
628  cntSwap.Stop();
629 
630  cntTotal.Stop();
631 
632  KI_TRACE( traceGalProfile, wxT( "Timing: %s %s %s %s %s %s\n" ), cntTotal.to_string(),
633  cntEndCached.to_string(), cntEndNoncached.to_string(), cntEndOverlay.to_string(),
634  cntComposite.to_string(), cntSwap.to_string() );
635 }
unsigned int m_overlayBuffer
Auxiliary rendering target (for menus etc.)
Definition: opengl_gal.h:339
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:333
const wxChar *const traceGalProfile
Flag to enable debug output of GAL performance profiling.
unsigned int m_mainBuffer
Main rendering target.
Definition: opengl_gal.h:338
VERTEX_MANAGER * m_cachedManager
Container for storing cached VERTEX_ITEMs.
Definition: opengl_gal.h:331
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:337
virtual void SetBuffer(unsigned int aBufferHandle) override
Set the selected buffer as the rendering target.
A small class to help profiling.
Definition: profile.h:46
bool m_isContextLocked
Used for assertion checking.
Definition: opengl_gal.h:354
void blitCursor()
Blit cursor into the current screen.
void EndDrawing() const
Finish drawing operations.
#define KI_TRACE(...)
VERTEX_MANAGER * m_nonCachedManager
Container for storing non-cached VERTEX_ITEMs.
Definition: opengl_gal.h:332

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

◆ EndGroup()

void OPENGL_GAL::EndGroup ( )
overridevirtual

End the group.

Reimplemented from KIGFX::GAL.

Definition at line 1654 of file opengl_gal.cpp.

1655 {
1657  m_isGrouping = false;
1658 }
VERTEX_MANAGER * m_cachedManager
Container for storing cached VERTEX_ITEMs.
Definition: opengl_gal.h:331
void FinishItem() const
Clean after adding an item.
bool m_isGrouping
Was a group started?
Definition: opengl_gal.h:353

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

◆ EndNegativesLayer()

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

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

No-op in OpenGL.

Reimplemented in KIGFX::CAIRO_GAL.

Definition at line 853 of file graphics_abstraction_layer.h.

853 {};

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

◆ endUpdate()

void OPENGL_GAL::endUpdate ( )
overrideprivatevirtual

Update handler for OpenGL settings

Reimplemented from KIGFX::GAL.

Definition at line 678 of file opengl_gal.cpp.

679 {
680  if( !m_isInitialized )
681  return;
682 
684 }
VERTEX_MANAGER * m_cachedManager
Container for storing cached VERTEX_ITEMs.
Definition: opengl_gal.h:331
void Unmap()
Unmap vertex buffer.
bool m_isInitialized
Basic initialization flag, has to be done when the window is visible.
Definition: opengl_gal.h:351

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

1578 {
1579  glFlush();
1580 }

◆ GetClearColor()

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

Definition at line 222 of file graphics_abstraction_layer.h.

223  {
224  return m_clearColor;
225  }

References KIGFX::GAL::m_clearColor.

Referenced by EDIT_POINTS::ViewDraw().

◆ getCursorColor()

COLOR4D GAL::getCursorColor ( ) const
protectedinherited

Get the actual cursor color to draw.

Definition at line 267 of file graphics_abstraction_layer.cpp.

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

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

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

◆ GetFillColor()

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

Get the fill color.

Returns
the color for filling a outline.

Definition at line 273 of file graphics_abstraction_layer.h.

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

References KIGFX::GAL::m_fillColor.

◆ GetGlyphSize()

◆ GetGridLineWidth()

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

Get the grid line width.

Returns
the grid line widthDraw the grid

Definition at line 969 of file graphics_abstraction_layer.h.

References KIGFX::GAL::m_gridLineWidth.

◆ GetGridOrigin()

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

Definition at line 894 of file graphics_abstraction_layer.h.

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

References KIGFX::GAL::m_gridOrigin.

Referenced by GRID_HELPER::GetOrigin().

◆ GetGridPoint()

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

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

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

Definition at line 245 of file graphics_abstraction_layer.cpp.

246 {
247 #if 0
248  // This old code expects a non zero grid size, which can be wrong here.
249  return VECTOR2D( KiROUND( ( aPoint.x - m_gridOffset.x ) / m_gridSize.x ) * m_gridSize.x + m_gridOffset.x,
250  KiROUND( ( aPoint.y - m_gridOffset.y ) / m_gridSize.y ) * m_gridSize.y + m_gridOffset.y );
251 #else
252  // if grid size == 0.0 there is no grid, so use aPoint as grid reference position
253  double cx = m_gridSize.x > 0.0 ? KiROUND( ( aPoint.x - m_gridOffset.x ) / m_gridSize.x ) * m_gridSize.x + m_gridOffset.x
254  : aPoint.x;
255  double cy = m_gridSize.y > 0.0 ? KiROUND( ( aPoint.y - m_gridOffset.y ) / m_gridSize.y ) * m_gridSize.y + m_gridOffset.y
256  : aPoint.y;
257 
258  return VECTOR2D( cx, cy );
259 #endif
260 }
VECTOR2D m_gridSize
The grid size.
VECTOR2< double > VECTOR2D
Definition: vector2d.h:621
VECTOR2D m_gridOffset
The grid offset to compensate cursor position.
constexpr ret_type KiROUND(fp_type v)
Round a floating point number to an integer using "round halfway cases away from zero".
Definition: util.h:73

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

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

◆ GetGridSize()

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

◆ GetGridSnapping()

◆ GetGridVisibility()

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

Definition at line 866 of file graphics_abstraction_layer.h.

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

References KIGFX::GAL::m_gridVisibility.

Referenced by EDA_DRAW_PANEL_GAL::SwitchBackend().

◆ GetHorizontalJustify()

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

Return current text horizontal justification setting.

Definition at line 458 of file graphics_abstraction_layer.h.

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

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

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

◆ GetLineWidth()

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

◆ GetLookAtPoint()

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

Get the look at point.

Returns
the look at point.

Definition at line 663 of file graphics_abstraction_layer.h.

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

References KIGFX::GAL::m_lookAtPoint.

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

◆ GetMaxDepth()

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

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

Definition at line 732 of file graphics_abstraction_layer.h.

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

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

◆ GetMinDepth()

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

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

Definition at line 724 of file graphics_abstraction_layer.h.

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

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

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

◆ GetNativePixelSize()

wxSize HIDPI_GL_CANVAS::GetNativePixelSize ( ) const
virtualinherited

Definition at line 41 of file hidpi_gl_canvas.cpp.

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

References HIDPI_GL_CANVAS::GetScaleFactor().

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

◆ GetNativePosition()

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

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

Definition at line 53 of file hidpi_gl_canvas.cpp.

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

References HIDPI_GL_CANVAS::GetScaleFactor().

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

◆ getNewGroupNumber()

unsigned int OPENGL_GAL::getNewGroupNumber ( )
private

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

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

Definition at line 2219 of file opengl_gal.cpp.

2220 {
2221  wxASSERT_MSG( m_groups.size() < std::numeric_limits<unsigned int>::max(),
2222  wxT( "There are no free slots to store a group" ) );
2223 
2224  while( m_groups.find( m_groupCounter ) != m_groups.end() )
2225  m_groupCounter++;
2226 
2227  return m_groupCounter++;
2228 }
GROUPS_MAP m_groups
Stores information about VBO objects (groups)
Definition: opengl_gal.h:327
unsigned int m_groupCounter
Counter used for generating keys for groups.
Definition: opengl_gal.h:328

References m_groupCounter, and m_groups.

Referenced by BeginGroup().

◆ GetRotation()

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

Get the rotation angle.

Returns
The rotation angle (radians).

Definition at line 703 of file graphics_abstraction_layer.h.

704  {
705  return m_rotation;
706  }
double m_rotation
Rotation transformation (radians)

References KIGFX::GAL::m_rotation.

◆ GetScaleFactor()

double HIDPI_GL_CANVAS::GetScaleFactor ( ) const
inherited

◆ GetScreenPixelSize()

◆ getScreenPixelSize()

VECTOR2D OPENGL_GAL::getScreenPixelSize ( ) const
private

Definition at line 411 of file opengl_gal.cpp.

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

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

Referenced by BeginDrawing().

◆ GetScreenWorldMatrix()

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

Get the screen <-> world transformation matrix.

Returns
the transformation matrix.

Definition at line 594 of file graphics_abstraction_layer.h.

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

References KIGFX::GAL::m_screenWorldMatrix.

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

◆ GetStrokeColor()

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

Get the stroke color.

Returns
the color for stroking the outline.

Definition at line 293 of file graphics_abstraction_layer.h.

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

References KIGFX::GAL::m_strokeColor.

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

◆ GetStrokeFont()

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

Definition at line 335 of file graphics_abstraction_layer.h.

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

References KIGFX::GAL::m_strokeFont.

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

◆ GetTarget()

RENDER_TARGET OPENGL_GAL::GetTarget ( ) const
overridevirtual

Get the currently used target for rendering.

Returns
The current rendering target.

Reimplemented from KIGFX::GAL.

Definition at line 1721 of file opengl_gal.cpp.

1722 {
1723  return m_currentTarget;
1724 }
RENDER_TARGET m_currentTarget
Current rendering target.
Definition: opengl_gal.h:341

References m_currentTarget.

Referenced by DrawBitmap().

◆ GetTextLineSize()

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

Compute the X and Y size of a given text.

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

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

Definition at line 183 of file graphics_abstraction_layer.cpp.

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

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

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

◆ GetVerticalJustify()

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

Returns current text vertical justification setting.

Definition at line 476 of file graphics_abstraction_layer.h.

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

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

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

◆ GetVisibleWorldExtents()

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

Definition at line 222 of file graphics_abstraction_layer.cpp.

223 {
224  const MATRIX3x3D& matrix = GetScreenWorldMatrix();
225 
226  VECTOR2D halfSize = VECTOR2D( matrix.GetScale().x * m_screenSize.x * 0.5,
227  matrix.GetScale().y * m_screenSize.y * 0.5 );
228 
229  BOX2D extents;
230  extents.SetOrigin( GetLookAtPoint() - halfSize );
231  extents.SetSize( halfSize * 2 );
232 
233  return extents;
234 }
const MATRIX3x3D & GetScreenWorldMatrix() const
Get the screen <-> world transformation matrix.
Define a general 2D-vector/point.
Definition: vector2d.h:61
VECTOR2< T > GetScale() const
Get the scale components of the matrix.
Definition: matrix3x3.h:265
VECTOR2< double > VECTOR2D
Definition: vector2d.h:621
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 404 of file opengl_gal.cpp.

405 {
406  MATRIX3x3D matrix = GetScreenWorldMatrix();
407  return std::min( std::abs( matrix.GetScale().x ), std::abs( matrix.GetScale().y ) );
408 }
const MATRIX3x3D & GetScreenWorldMatrix() const
Get the screen <-> world transformation matrix.
VECTOR2< T > GetScale() const
Get the scale components of the matrix.
Definition: matrix3x3.h:265

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

Referenced by BeginDrawing(), and DrawGrid().

◆ GetWorldScale()

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

◆ GetWorldScreenMatrix()

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

Get the world <-> screen transformation matrix.

Returns
the transformation matrix.

Definition at line 584 of file graphics_abstraction_layer.h.

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

References KIGFX::GAL::m_worldScreenMatrix.

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

◆ GetZoomFactor()

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

Get the zoom factor.

Returns
the zoom factor.

Definition at line 683 of file graphics_abstraction_layer.h.

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

References KIGFX::GAL::m_zoomFactor.

Referenced by COMMON_TOOLS::doZoomInOut(), KIGFX::PCB_PAINTER::draw(), EDA_DRAW_FRAME::GetZoomLevelIndicator(), 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 1761 of file opengl_gal.cpp.

1762 {
1763  switch( aTarget )
1764  {
1765  default:
1766  case TARGET_TEMP:
1767  case TARGET_CACHED:
1768  case TARGET_NONCACHED: return true;
1769  case TARGET_OVERLAY: return ( m_overlayBuffer != 0 );
1770  }
1771 }
unsigned int m_overlayBuffer
Auxiliary rendering target (for menus etc.)
Definition: opengl_gal.h:339
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
Temporary target for drawing in separate layer.
Definition: definitions.h:51

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

◆ init()

void OPENGL_GAL::init ( )
private

Basic OpenGL initialization and feature checks.

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

Definition at line 2231 of file opengl_gal.cpp.

2232 {
2233  wxASSERT( IsShownOnScreen() );
2234 
2235  wxASSERT_MSG( m_isContextLocked, wxT( "This should only be called from within a locked context." ) );
2236 
2237 // IsDisplayAttr() handles WX_GL_{MAJOR,MINOR}_VERSION correctly only in 3.0.4
2238 // starting with 3.1.0 one should use wxGLContext::IsOk() (done by GL_CONTEXT_MANAGER)
2239 #if wxCHECK_VERSION( 3, 0, 3 ) and !wxCHECK_VERSION( 3, 1, 0 )
2240  const int attr[] = { WX_GL_MAJOR_VERSION, 2, WX_GL_MINOR_VERSION, 1, 0 };
2241 
2242  if( !IsDisplaySupported( attr ) )
2243  throw std::runtime_error( "OpenGL 2.1 or higher is required!" );
2244 #endif /* wxCHECK_VERSION( 3, 0, 3 ) */
2245 
2246  // Check correct initialization from the constructor
2247  if( !m_glMainContext )
2248  throw std::runtime_error( "Could not create the main OpenGL context" );
2249 
2250  if( !m_glPrivContext )
2251  throw std::runtime_error( "Could not create a private OpenGL context" );
2252 
2253  if( m_tesselator == nullptr )
2254  throw std::runtime_error( "Could not create the m_tesselator" );
2255  // End initialization checks
2256 
2257  GLenum err = glewInit();
2258 
2259  if( GLEW_OK != err )
2260  throw std::runtime_error( (const char*) glewGetErrorString( err ) );
2261 
2262  // Check the OpenGL version (minimum 2.1 is required)
2263  if( !GLEW_VERSION_2_1 )
2264  throw std::runtime_error( "OpenGL 2.1 or higher is required!" );
2265 
2266 #if defined( __LINUX__ ) // calling enableGlDebug crashes opengl on some OS (OSX and some Windows)
2267 #ifdef DEBUG
2268  if( GLEW_ARB_debug_output )
2269  enableGlDebug( true );
2270 #endif
2271 #endif
2272 
2273  // Framebuffers have to be supported
2274  if( !GLEW_EXT_framebuffer_object )
2275  throw std::runtime_error( "Framebuffer objects are not supported!" );
2276 
2277  // Vertex buffer has to be supported
2278  if( !GLEW_ARB_vertex_buffer_object )
2279  throw std::runtime_error( "Vertex buffer objects are not supported!" );
2280 
2281  // Prepare shaders
2282  if( !m_shader->IsLinked()
2285  {
2286  throw std::runtime_error( "Cannot compile vertex shader!" );
2287  }
2288 
2289  if( !m_shader->IsLinked()
2292  {
2293  throw std::runtime_error( "Cannot compile fragment shader!" );
2294  }
2295 
2296  if( !m_shader->IsLinked() && !m_shader->Link() )
2297  throw std::runtime_error( "Cannot link the shaders!" );
2298 
2299  // Check if video card supports textures big enough to fit the font atlas
2300  int maxTextureSize;
2301  glGetIntegerv( GL_MAX_TEXTURE_SIZE, &maxTextureSize );
2302 
2303  if( maxTextureSize < (int) font_image.width || maxTextureSize < (int) font_image.height )
2304  {
2305  // TODO implement software texture scaling
2306  // for bitmap fonts and use a higher resolution texture?
2307  throw std::runtime_error( "Requested texture size is not supported" );
2308  }
2309 
2311 
2312  m_cachedManager = new VERTEX_MANAGER( true );
2313  m_nonCachedManager = new VERTEX_MANAGER( false );
2314  m_overlayManager = new VERTEX_MANAGER( false );
2315  m_tempManager = new VERTEX_MANAGER( false );
2316 
2317  // Make VBOs use shaders
2322 
2323  m_isInitialized = true;
2324 }
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:333
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:331
void enableGlDebug(bool aEnable)
Enable or disable OpenGL driver messages output.
Definition: utils.cpp:183
static wxGLContext * m_glMainContext
Parent OpenGL context.
Definition: opengl_gal.h:316
SHADER * m_shader
There is only one shader used for different objects.
Definition: opengl_gal.h:344
bool m_isInitialized
Basic initialization flag, has to be done when the window is visible.
Definition: opengl_gal.h:351
void SetShader(SHADER &aShader) const
Set a shader program that is going to be used during rendering.
GLUtesselator * m_tesselator
Definition: opengl_gal.h:366
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:354
wxGLContext * m_glPrivContext
Canvas-specific OpenGL context.
Definition: opengl_gal.h:317
Class to control vertex container and GPU with possibility of emulating old-style OpenGL 1....
VERTEX_MANAGER * m_tempManager
Container for storing temp (diff mode) VERTEX_ITEMs.
Definition: opengl_gal.h:334
static int SetSwapInterval(int aVal)
Attempts to set the OpenGL swap interval.
Definition: gl_utils.h:42
VERTEX_MANAGER * m_nonCachedManager
Container for storing non-cached VERTEX_ITEMs.
Definition: opengl_gal.h:332

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_tempManager, m_tesselator, KIGFX::VERTEX_MANAGER::SetShader(), GL_UTILS::SetSwapInterval(), KIGFX::SHADER_TYPE_FRAGMENT, KIGFX::SHADER_TYPE_VERTEX, and KIGFX::BUILTIN_FONT::FONT_IMAGE_TYPE::width.

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

◆ IsCairoEngine()

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

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

Reimplemented in KIGFX::CAIRO_GAL_BASE.

Definition at line 80 of file graphics_abstraction_layer.h.

80 { return false; }

Referenced by getShadowLayer().

◆ IsContextLocked()

bool KIGFX::OPENGL_GAL::IsContextLocked ( )
inlineoverridevirtual

Checks the state of the context lock.

Returns
True if the context is currently locked

Reimplemented from KIGFX::GAL.

Definition at line 287 of file opengl_gal.h.

288  {
289  return m_isContextLocked;
290  }
bool m_isContextLocked
Used for assertion checking.
Definition: opengl_gal.h:354

References m_isContextLocked.

◆ IsCursorEnabled()

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

Return information about cursor visibility.

Returns
True if cursor is visible.

Definition at line 1030 of file graphics_abstraction_layer.h.

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

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

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

◆ IsFlippedX()

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

◆ IsFlippedY()

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

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

Definition at line 770 of file graphics_abstraction_layer.h.

771  {
772  return m_globalFlipY;
773  }
bool m_globalFlipY
Flag for Y axis flipping.

References KIGFX::GAL::m_globalFlipY.

◆ IsFontBold()

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

Definition at line 424 of file graphics_abstraction_layer.h.

424 { 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

Definition at line