KiCad PCB EDA Suite
KIGFX::OPENGL_GAL Class Reference

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

#include <opengl_gal.h>

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

Classes

struct  TessParams
 

Public Member Functions

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

Static Public Member Functions

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

Protected Member Functions

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

Protected Attributes

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

Static Protected Attributes

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

Private Types

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

Private Member Functions

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

Private Attributes

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

Static Private Attributes

static const int CIRCLE_POINTS = 64
 The number of points for circle approximation. More...
 
static const int CURVE_POINTS = 32
 The number of points for curve approximation. More...
 
static wxGLContext * m_glMainContext = NULL
 Parent OpenGL context. More...
 
static int m_instanceCounter = 0
 GL GAL instance counter. More...
 
static GLuint g_fontTexture = 0
 Bitmap font texture handle (shared) More...
 
static bool m_isBitmapFontLoaded = false
 Is the bitmap font texture loaded? More...
 

Detailed Description

OpenGL implementation of the Graphics Abstraction Layer.

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

Definition at line 66 of file opengl_gal.h.

Member Typedef Documentation

◆ GROUPS_MAP

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

Definition at line 307 of file opengl_gal.h.

◆ super

typedef GAL KIGFX::OPENGL_GAL::super
private

Super class definition.

Definition at line 293 of file opengl_gal.h.

Constructor & Destructor Documentation

◆ OPENGL_GAL()

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

Definition at line 196 of file opengl_gal.cpp.

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

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, NULL, onPaint(), onSetNativeCursor(), KIGFX::OPENGL_COMPOSITOR::SetAntialiasingMode(), KIGFX::GAL::SetAxesColor(), KIGFX::GAL::SetGridColor(), SetTarget(), skipMouseEvent(), KIGFX::TARGET_NONCACHED, ufm_pixelSizeMultiplier, ufm_screenPixelSize, and ufm_worldPixelSize.

◆ ~OPENGL_GAL()

OPENGL_GAL::~OPENGL_GAL ( )

Definition at line 287 of file opengl_gal.cpp.

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

References ClearCache(), GL_CONTEXT_MANAGER::DestroyCtx(), g_fontTexture, GL_CONTEXT_MANAGER::Get(), GL_CONTEXT_MANAGER::LockCtx(), m_cachedManager, m_compositor, m_glMainContext, m_glPrivContext, m_instanceCounter, m_isBitmapFontLoaded, m_isInitialized, m_nonCachedManager, m_overlayManager, m_shader, m_tesselator, NULL, 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 1023 of file graphics_abstraction_layer.h.

1024  {
1025  m_layerDepth -= 0.05;
1026  }
double m_layerDepth
The actual layer depth.

References KIGFX::GAL::m_layerDepth.

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

◆ beginDrawing()

void OPENGL_GAL::beginDrawing ( )
overrideprivatevirtual

Reimplemented from KIGFX::GAL.

Definition at line 413 of file opengl_gal.cpp.

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

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::GetAntialiasSupersamplingFactor(), HIDPI_GL_CANVAS::GetScaleFactor(), getScreenPixelSize(), getWorldPixelSize(), KIGFX::BUILTIN_FONT::FONT_IMAGE_TYPE::height, init(), KIGFX::OPENGL_COMPOSITOR::Initialize(), IsVisible(), m_cachedManager, m_compositor, MATRIX3x3< T >::m_data, KIGFX::GAL::m_depthRange, KIGFX::GAL::m_fillColor, m_isBitmapFontInitialized, m_isBitmapFontLoaded, m_isContextLocked, m_isFramebufferInitialized, m_isInitialized, m_mainBuffer, m_nonCachedManager, m_overlayBuffer, m_overlayManager, KIGFX::GAL::m_screenSize, m_shader, KIGFX::GAL::m_strokeColor, KIGFX::GAL::m_worldScreenMatrix, PROF_COUNTER::msecs(), KIGFX::BUILTIN_FONT::FONT_IMAGE_TYPE::pixels, KIGFX::OPENGL_COMPOSITOR::SetBuffer(), KIGFX::GAL::SetFillColor(), KIGFX::SHADER::SetParameter(), KIGFX::GAL::SetStrokeColor(), PROF_COUNTER::Stop(), traceGalProfile, ufm_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 1605 of file opengl_gal.cpp.

1606 {
1607  m_isGrouping = true;
1608 
1609  std::shared_ptr<VERTEX_ITEM> newItem = std::make_shared<VERTEX_ITEM>( *m_cachedManager );
1610  int groupNumber = getNewGroupNumber();
1611  m_groups.insert( std::make_pair( groupNumber, newItem ) );
1612 
1613  return groupNumber;
1614 }
GROUPS_MAP m_groups
Stores information about VBO objects (groups)
Definition: opengl_gal.h:309
VERTEX_MANAGER * m_cachedManager
Container for storing cached VERTEX_ITEMs.
Definition: opengl_gal.h:313
unsigned int getNewGroupNumber()
Return a valid key that can be used as a new group number.
bool m_isGrouping
Was a group started?
Definition: opengl_gal.h:333

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

◆ beginUpdate()

void OPENGL_GAL::beginUpdate ( )
overrideprivatevirtual

Reimplemented from KIGFX::GAL.

Definition at line 629 of file opengl_gal.cpp.

630 {
631  wxASSERT_MSG( m_isContextLocked, "GAL_UPDATE_CONTEXT RAII object should have locked context. "
632  "Calling this from anywhere else is not allowed." );
633 
634  wxASSERT_MSG( IsVisible(), "GAL::beginUpdate() must not be entered when GAL is not visible. "
635  "Other update routines will expect everything to be initialized "
636  "which will not be the case." );
637 
638  if( !m_isInitialized )
639  init();
640 
641  m_cachedManager->Map();
642 }
VERTEX_MANAGER * m_cachedManager
Container for storing cached VERTEX_ITEMs.
Definition: opengl_gal.h:313
void init()
Basic OpenGL initialization and feature checks.
bool m_isInitialized
Basic initialization flag, has to be done when the window is visible.
Definition: opengl_gal.h:331
void Map()
Map vertex buffer.
bool m_isContextLocked
Used for assertion checking.
Definition: opengl_gal.h:334
bool IsVisible() const override
Return true if the GAL canvas is visible on the screen.
Definition: opengl_gal.h:106

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

◆ BitmapText()

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

Draw a text using a bitmap font.

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

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

Reimplemented from KIGFX::GAL.

Definition at line 1235 of file opengl_gal.cpp.

1237 {
1238  // Fallback to generic impl (which uses the stroke font) on cases we don't handle
1239  if( IsTextMirrored() || aText.Contains( wxT( "^{" ) ) || aText.Contains( wxT( "_{" ) ) )
1240  return GAL::BitmapText( aText, aPosition, aRotationAngle );
1241 
1242  const UTF8 text( aText );
1243  // Compute text size, so it can be properly justified
1244  VECTOR2D textSize;
1245  float commonOffset;
1246  std::tie( textSize, commonOffset ) = computeBitmapTextSize( text );
1247 
1248  const double SCALE = 1.4 * GetGlyphSize().y / textSize.y;
1249  bool overbar = false;
1250 
1251  int overbarLength = 0;
1252  double overbarHeight = textSize.y;
1253 
1254  Save();
1255 
1257  m_currentManager->Translate( aPosition.x, aPosition.y, m_layerDepth );
1258  m_currentManager->Rotate( aRotationAngle, 0.0f, 0.0f, -1.0f );
1259 
1260  double sx = SCALE * ( m_globalFlipX ? -1.0 : 1.0 );
1261  double sy = SCALE * ( m_globalFlipY ? -1.0 : 1.0 );
1262 
1263  m_currentManager->Scale( sx, sy, 0 );
1264  m_currentManager->Translate( 0, -commonOffset, 0 );
1265 
1266  switch( GetHorizontalJustify() )
1267  {
1269  Translate( VECTOR2D( -textSize.x / 2.0, 0 ) );
1270  break;
1271 
1273  //if( !IsTextMirrored() )
1274  Translate( VECTOR2D( -textSize.x, 0 ) );
1275  break;
1276 
1277  case GR_TEXT_HJUSTIFY_LEFT:
1278  //if( IsTextMirrored() )
1279  //Translate( VECTOR2D( -textSize.x, 0 ) );
1280  break;
1281  }
1282 
1283  switch( GetVerticalJustify() )
1284  {
1285  case GR_TEXT_VJUSTIFY_TOP:
1286  Translate( VECTOR2D( 0, -textSize.y ) );
1287  overbarHeight = -textSize.y / 2.0;
1288  break;
1289 
1291  Translate( VECTOR2D( 0, -textSize.y / 2.0 ) );
1292  overbarHeight = 0;
1293  break;
1294 
1296  break;
1297  }
1298 
1299  int i = 0;
1300 
1301  for( UTF8::uni_iter chIt = text.ubegin(), end = text.uend(); chIt < end; ++chIt )
1302  {
1303  unsigned int c = *chIt;
1304  wxASSERT_MSG( c != '\n' && c != '\r', wxT( "No support for multiline bitmap text yet" ) );
1305 
1306  bool wasOverbar = overbar;
1307 
1308  if( c == '~' )
1309  {
1310  if( ++chIt == end )
1311  break;
1312 
1313  c = *chIt;
1314 
1315  if( c == '~' )
1316  {
1317  // double ~ is really a ~ so go ahead and process the second one
1318 
1319  // so what's a triple ~? It could be a real ~ followed by an overbar, or
1320  // it could be an overbar followed by a real ~. The old algorithm did the
1321  // former so we will too....
1322  }
1323  else
1324  {
1325  overbar = !overbar;
1326  }
1327  }
1328  else if( c == ' ' || c == '}' || c == ')' )
1329  {
1330  overbar = false;
1331  }
1332 
1333  if( wasOverbar && !overbar )
1334  {
1335  drawBitmapOverbar( overbarLength, overbarHeight );
1336  overbarLength = 0;
1337  }
1338 
1339  if( overbar )
1340  overbarLength += drawBitmapChar( c );
1341  else
1342  drawBitmapChar( c );
1343 
1344  ++i;
1345  }
1346 
1347  // Handle the case when overbar is active till the end of the drawn text
1348  m_currentManager->Translate( 0, commonOffset, 0 );
1349 
1350  if( overbar && overbarLength > 0 )
1351  drawBitmapOverbar( overbarLength, overbarHeight );
1352 
1353  Restore();
1354 }
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:359
EDA_TEXT_HJUSTIFY_T GetHorizontalJustify() const
Return current text horizontal justification setting.
double b
Blue component.
Definition: color4d.h:360
double m_layerDepth
The actual layer depth.
const VECTOR2D & GetGlyphSize() const
void Save() override
Save the context.
bool m_globalFlipX
Flag for X axis flipping.
VERTEX_MANAGER * m_currentManager
Currently used VERTEX_MANAGER (for storing VERTEX_ITEMs).
Definition: opengl_gal.h:311
double a
Alpha component.
Definition: color4d.h:361
COLOR4D m_strokeColor
The color of the outlines.
VECTOR2< double > VECTOR2D
Definition: vector2d.h:622
void Translate(GLfloat aX, GLfloat aY, GLfloat aZ)
Multiply the current matrix by a translation matrix, so newly vertices will be translated by the give...
void Color(const COLOR4D &aColor)
Changes currently used color that will be applied to newly added vertices.
uni_iter is a non-mutating iterator that walks through unicode code points in the UTF8 encoded string...
Definition: utf8.h:203
bool m_globalFlipY
Flag for Y axis flipping.
EDA_TEXT_VJUSTIFY_T GetVerticalJustify() const
Returns current text vertical justification setting.
int drawBitmapChar(unsigned long aChar)
Draw a single character using bitmap font.
void Scale(GLfloat aX, GLfloat aY, GLfloat aZ)
Multiply the current matrix by a scaling matrix, so the newly vertices will be scaled by the given fa...
double r
Red component.
Definition: color4d.h:358
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 2131 of file opengl_gal.cpp.

2132 {
2133  if( !IsCursorEnabled() )
2134  return;
2135 
2137 
2138  const int cursorSize = m_fullscreenCursor ? 8000 : 80;
2139 
2140  VECTOR2D cursorBegin = m_cursorPosition - cursorSize / ( 2 * m_worldScale );
2141  VECTOR2D cursorEnd = m_cursorPosition + cursorSize / ( 2 * m_worldScale );
2142  VECTOR2D cursorCenter = ( cursorBegin + cursorEnd ) / 2;
2143 
2144  const COLOR4D cColor = getCursorColor();
2145  const COLOR4D color( cColor.r * cColor.a, cColor.g * cColor.a, cColor.b * cColor.a, 1.0 );
2146 
2147  glActiveTexture( GL_TEXTURE0 );
2148  glDisable( GL_TEXTURE_2D );
2149  glLineWidth( 1.0 );
2150  glColor4d( color.r, color.g, color.b, color.a );
2151 
2152  glBegin( GL_LINES );
2153  glVertex2d( cursorCenter.x, cursorBegin.y );
2154  glVertex2d( cursorCenter.x, cursorEnd.y );
2155 
2156  glVertex2d( cursorBegin.x, cursorCenter.y );
2157  glVertex2d( cursorEnd.x, cursorCenter.y );
2158  glEnd();
2159 }
int color
Definition: DXF_plotter.cpp:60
double g
Green component.
Definition: color4d.h:359
static const unsigned int DIRECT_RENDERING
double b
Blue component.
Definition: color4d.h:360
double m_worldScale
The scale factor world->screen.
VECTOR2D m_cursorPosition
Current cursor position (world coordinates)
double a
Alpha component.
Definition: color4d.h:361
OPENGL_COMPOSITOR * m_compositor
Handles multiple rendering targets.
Definition: opengl_gal.h:318
virtual void SetBuffer(unsigned int aBufferHandle) override
Set the selected buffer as the rendering target.
COLOR4D getCursorColor() const
Get the actual cursor color to draw.
bool m_fullscreenCursor
Shape of the cursor (fullscreen or small cross)
double r
Red component.
Definition: color4d.h:358
bool IsCursorEnabled() const
Return information about cursor visibility.
A color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:98

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

500  {
501  // Bigger arcs need smaller alpha increment to make them look smooth
502  return std::min( 1e6 / aRadius, 2.0 * M_PI / CIRCLE_POINTS );
503  }
CIRCLE_POINTS

Referenced by DrawArc(), and DrawArcSegment().

◆ ChangeGroupColor()

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

Change the color used to draw the group.

Parameters
aGroupNumberis the group number.
aNewColoris the new color.

Reimplemented from KIGFX::GAL.

Definition at line 1633 of file opengl_gal.cpp.

1634 {
1635  auto group = m_groups.find( aGroupNumber );
1636 
1637  if( group != m_groups.end() )
1638  m_cachedManager->ChangeItemColor( *group->second, aNewColor );
1639 }
GROUPS_MAP m_groups
Stores information about VBO objects (groups)
Definition: opengl_gal.h:309
VERTEX_MANAGER * m_cachedManager
Container for storing cached VERTEX_ITEMs.
Definition: opengl_gal.h:313
void ChangeItemColor(const VERTEX_ITEM &aItem, const COLOR4D &aColor) const
Change the color of all vertices owned by an item.

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

◆ ChangeGroupDepth()

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

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

Parameters
aGroupNumberis the group number.
aDepthis the new depth.

Reimplemented from KIGFX::GAL.

Definition at line 1642 of file opengl_gal.cpp.

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

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

References init(), and NULL.

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

1659 {
1660  m_bitmapCache = std::make_unique<GL_BITMAP_CACHE>();
1661 
1662  m_groups.clear();
1663 
1664  if( m_isInitialized )
1666 }
GROUPS_MAP m_groups
Stores information about VBO objects (groups)
Definition: opengl_gal.h:309
VERTEX_MANAGER * m_cachedManager
Container for storing cached VERTEX_ITEMs.
Definition: opengl_gal.h:313
bool m_isInitialized
Basic initialization flag, has to be done when the window is visible.
Definition: opengl_gal.h:331
std::unique_ptr< GL_BITMAP_CACHE > m_bitmapCache
Definition: opengl_gal.h:342
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 1546 of file opengl_gal.cpp.

1547 {
1548  // Clear screen
1550 
1551  // NOTE: Black used here instead of m_clearColor; it will be composited later
1552  glClearColor( 0, 0, 0, 1 );
1553  glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT );
1554 }
static const unsigned int DIRECT_RENDERING
OPENGL_COMPOSITOR * m_compositor
Handles multiple rendering targets.
Definition: opengl_gal.h:318
virtual void SetBuffer(unsigned int aBufferHandle) override
Set the selected buffer as the rendering target.

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

◆ ClearTarget()

void OPENGL_GAL::ClearTarget ( RENDER_TARGET  aTarget)
overridevirtual

Clear the target for rendering.

Parameters
aTargetis the target to be cleared.

Reimplemented from KIGFX::GAL.

Definition at line 1689 of file opengl_gal.cpp.

1690 {
1691  // Save the current state
1692  unsigned int oldTarget = m_compositor->GetBuffer();
1693 
1694  switch( aTarget )
1695  {
1696  // Cached and noncached items are rendered to the same buffer
1697  default:
1698  case TARGET_CACHED:
1699  case TARGET_NONCACHED:
1701  break;
1702 
1703  case TARGET_OVERLAY:
1704  if( m_overlayBuffer )
1706  break;
1707  }
1708 
1709  if( aTarget != TARGET_OVERLAY )
1711  else if( m_overlayBuffer )
1713 
1714  // Restore the previous state
1715  m_compositor->SetBuffer( oldTarget );
1716 }
unsigned int m_overlayBuffer
Auxiliary rendering target (for menus etc.)
Definition: opengl_gal.h:320
static const COLOR4D BLACK
Definition: color4d.h:368
unsigned int m_mainBuffer
Main rendering target.
Definition: opengl_gal.h:319
Auxiliary rendering target (noncached)
Definition: definitions.h:49
virtual void ClearBuffer(const COLOR4D &aColor) override
Clear the selected buffer (set by the SetBuffer() function).
OPENGL_COMPOSITOR * m_compositor
Handles multiple rendering targets.
Definition: opengl_gal.h:318
Items that may change while the view stays the same (noncached)
Definition: definitions.h:50
virtual void SetBuffer(unsigned int aBufferHandle) override
Set the selected buffer as the rendering target.
Main rendering target (cached)
Definition: definitions.h:48
virtual unsigned int GetBuffer() const override
Return currently used buffer handle.

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

◆ computeBitmapTextSize()

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

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

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

Definition at line 2053 of file opengl_gal.cpp.

2054 {
2055  static const FONT_GLYPH_TYPE* defaultGlyph = LookupGlyph( '(' ); // for strange chars
2056  static const FONT_GLYPH_TYPE* lineGlyph = LookupGlyph( '_' ); // for overbar thickness
2057 
2058  VECTOR2D textSize( 0, 0 );
2059  float commonOffset = std::numeric_limits<float>::max();
2060  bool in_overbar = false;
2061  float char_height = font_information.max_y - defaultGlyph->miny;
2062 
2063  for( UTF8::uni_iter chIt = aText.ubegin(), end = aText.uend(); chIt < end; ++chIt )
2064  {
2065  if( *chIt == '~' )
2066  {
2067  if( ++chIt == end )
2068  break;
2069 
2070  if( *chIt == '~' )
2071  {
2072  // double ~ is really a ~ so go ahead and process the second one
2073 
2074  // so what's a triple ~? It could be a real ~ followed by an overbar, or
2075  // it could be an overbar followed by a real ~. The old algorithm did the
2076  // former so we will too....
2077  }
2078  else
2079  {
2080  // single ~ toggles overbar
2081  in_overbar = !in_overbar;
2082  }
2083  }
2084  else if( in_overbar && ( *chIt == ' ' || *chIt == '}' || *chIt == ')' ) )
2085  {
2086  in_overbar = false;
2087  }
2088 
2089  const FONT_GLYPH_TYPE* glyph = LookupGlyph( *chIt );
2090 
2091  if( !glyph // Not coded in font
2092  || *chIt == '-' || *chIt == '_' ) // Strange size of these 2 chars
2093  {
2094  glyph = defaultGlyph;
2095  }
2096 
2097  if( glyph )
2098  {
2099  textSize.x += glyph->advance;
2100 
2101  if( in_overbar )
2102  {
2103  const float H = lineGlyph->maxy - lineGlyph->miny;
2104  textSize.y = std::max<float>( textSize.y, char_height + 1.5 * H );
2105  }
2106  }
2107  }
2108 
2109  textSize.y = std::max<float>( textSize.y, char_height );
2110  commonOffset = std::min<float>( font_information.max_y - defaultGlyph->maxy, commonOffset );
2111  textSize.y -= commonOffset;
2112 
2113  return std::make_pair( textSize, commonOffset );
2114 }
uni_iter uend() const
Return a uni_iter initialized to the end of "this" UTF8 byte sequence.
Definition: utf8.h:287
const FONT_GLYPH_TYPE * LookupGlyph(unsigned int aCodepoint)
uni_iter ubegin() const
Returns a uni_iter initialized to the start of "this" UTF8 byte sequence.
Definition: utf8.h:279
FONT_INFO_TYPE font_information
Definition: gl_resources.cpp:3
#define H(x, y, z)
Definition: md5_hash.cpp:17
uni_iter is a non-mutating iterator that walks through unicode code points in the UTF8 encoded string...
Definition: utf8.h:203

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

Referenced by BitmapText().

◆ computeMinGridSpacing()

double GAL::computeMinGridSpacing ( ) const
protectedinherited

compute minimum grid spacing from the grid settings

Returns
the minimum spacing to use for drawing the grid

Definition at line 230 of file graphics_abstraction_layer.cpp.

231 {
232  // just return the current value. This could be cleverer and take
233  // into account other settings in future
234  return m_gridMinSpacing;
235 }
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 1078 of file graphics_abstraction_layer.h.

1079  {
1081  }
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 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 2330 of file opengl_gal.cpp.

2331 {
2332  auto pixelSize = m_worldScale;
2333 
2334  m_lookAtPoint.x = roundr( m_lookAtPoint.x, pixelSize );
2335  m_lookAtPoint.y = roundr( m_lookAtPoint.y, pixelSize );
2336 
2338 }
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.
static double roundr(double f, double r)

References KIGFX::GAL::ComputeWorldScreenMatrix(), KIGFX::GAL::m_lookAtPoint, KIGFX::GAL::m_worldScale, roundr(), 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 1651 of file opengl_gal.cpp.

1652 {
1653  // Frees memory in the container as well
1654  m_groups.erase( aGroupNumber );
1655 }
GROUPS_MAP m_groups
Stores information about VBO objects (groups)
Definition: opengl_gal.h:309

References m_groups.

◆ DrawArc()

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

Draw an arc.

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

Reimplemented from KIGFX::GAL.

Definition at line 773 of file opengl_gal.cpp.

775 {
776  if( aRadius <= 0 )
777  return;
778 
779  // Swap the angles, if start angle is greater than end angle
780  SWAP( aStartAngle, >, aEndAngle );
781 
782  const double alphaIncrement = calcAngleStep( aRadius );
783 
784  Save();
785  m_currentManager->Translate( aCenterPoint.x, aCenterPoint.y, 0.0 );
786 
787  if( m_isFillEnabled )
788  {
789  double alpha;
792 
793  // Triangle fan
794  for( alpha = aStartAngle; ( alpha + alphaIncrement ) < aEndAngle; )
795  {
797  m_currentManager->Vertex( 0.0, 0.0, m_layerDepth );
798  m_currentManager->Vertex( cos( alpha ) * aRadius, sin( alpha ) * aRadius,
799  m_layerDepth );
800  alpha += alphaIncrement;
801  m_currentManager->Vertex( cos( alpha ) * aRadius, sin( alpha ) * aRadius,
802  m_layerDepth );
803  }
804 
805  // The last missing triangle
806  const VECTOR2D endPoint( cos( aEndAngle ) * aRadius, sin( aEndAngle ) * aRadius );
807 
809  m_currentManager->Vertex( 0.0, 0.0, m_layerDepth );
810  m_currentManager->Vertex( cos( alpha ) * aRadius, sin( alpha ) * aRadius, m_layerDepth );
811  m_currentManager->Vertex( endPoint.x, endPoint.y, m_layerDepth );
812  }
813 
814  if( m_isStrokeEnabled )
815  {
817  m_strokeColor.a );
818 
819  VECTOR2D p( cos( aStartAngle ) * aRadius, sin( aStartAngle ) * aRadius );
820  double alpha;
821 
822  for( alpha = aStartAngle + alphaIncrement; alpha <= aEndAngle; alpha += alphaIncrement )
823  {
824  VECTOR2D p_next( cos( alpha ) * aRadius, sin( alpha ) * aRadius );
825  DrawLine( p, p_next );
826 
827  p = p_next;
828  }
829 
830  // Draw the last missing part
831  if( alpha != aEndAngle )
832  {
833  VECTOR2D p_last( cos( aEndAngle ) * aRadius, sin( aEndAngle ) * aRadius );
834  DrawLine( p, p_last );
835  }
836  }
837 
838  Restore();
839 }
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:359
double b
Blue component.
Definition: color4d.h:360
double m_layerDepth
The actual layer depth.
void Save() override
Save the context.
VERTEX_MANAGER * m_currentManager
Currently used VERTEX_MANAGER (for storing VERTEX_ITEMs).
Definition: opengl_gal.h:311
double a
Alpha component.
Definition: color4d.h:361
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:499
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:654
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:358

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

◆ DrawArcSegment()

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

Draw an arc segment.

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

TODO: Unify Arc routines

Parameters
aCenterPointis the center point of the arc.
aRadiusis the arc radius.
aStartAngleis the start angle of the arc.
aEndAngleis the end angle of the arc.
aWidthis the thickness of the arc (pen size).

Reimplemented from KIGFX::GAL.

Definition at line 842 of file opengl_gal.cpp.

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

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

◆ DrawBitmap()

void OPENGL_GAL::DrawBitmap ( const BITMAP_BASE aBitmap)
overridevirtual

Draw a bitmap image.

Reimplemented from KIGFX::GAL.

Definition at line 1180 of file opengl_gal.cpp.

1181 {
1182  // We have to calculate the pixel size in users units to draw the image.
1183  // m_worldUnitLength is a factor used for converting IU to inches
1184  double scale = 1.0 / ( aBitmap.GetPPI() * m_worldUnitLength );
1185  double w = (double) aBitmap.GetSizePixels().x * scale;
1186  double h = (double) aBitmap.GetSizePixels().y * scale;
1187 
1188  auto xform = m_currentManager->GetTransformation();
1189 
1190  glm::vec4 v0 = xform * glm::vec4( -w / 2, -h / 2, 0.0, 0.0 );
1191  glm::vec4 v1 = xform * glm::vec4( w / 2, h / 2, 0.0, 0.0 );
1192  glm::vec4 trans = xform[3];
1193 
1194  auto texture_id = m_bitmapCache->RequestBitmap( &aBitmap );
1195 
1196  if( !glIsTexture( texture_id ) ) // ensure the bitmap texture is still valid
1197  return;
1198 
1199  auto oldTarget = GetTarget();
1200 
1201  glPushMatrix();
1202  glTranslated( trans.x, trans.y, trans.z );
1203 
1205  glEnable( GL_TEXTURE_2D );
1206  glActiveTexture( GL_TEXTURE0 );
1207  glBindTexture( GL_TEXTURE_2D, texture_id );
1208 
1209  glBegin( GL_QUADS );
1210  glColor4f( 1.0, 1.0, 1.0, 1.0 );
1211  glTexCoord2f( 0.0, 0.0 );
1212  glVertex3f( v0.x, v0.y, m_layerDepth );
1213  glColor4f( 1.0, 1.0, 1.0, 1.0 );
1214  glTexCoord2f( 1.0, 0.0 );
1215  glVertex3f( v1.x, v0.y, m_layerDepth );
1216  glColor4f( 1.0, 1.0, 1.0, 1.0 );
1217  glTexCoord2f( 1.0, 1.0 );
1218  glVertex3f( v1.x, v1.y, m_layerDepth );
1219  glColor4f( 1.0, 1.0, 1.0, 1.0 );
1220  glTexCoord2f( 0.0, 1.0 );
1221  glVertex3f( v0.x, v1.y, m_layerDepth );
1222  glEnd();
1223 
1224  SetTarget( oldTarget );
1225  glBindTexture( GL_TEXTURE_2D, 0 );
1226 
1227 #ifdef DISABLE_BITMAP_CACHE
1228  glDeleteTextures( 1, &texture_id );
1229 #endif
1230 
1231  glPopMatrix();
1232 }
const glm::mat4 & GetTransformation() const
double m_layerDepth
The actual layer depth.
Auxiliary rendering target (noncached)
Definition: definitions.h:49
RENDER_TARGET GetTarget() const override
Get the currently used target for rendering.
VERTEX_MANAGER * m_currentManager
Currently used VERTEX_MANAGER (for storing VERTEX_ITEMs).
Definition: opengl_gal.h:311
void SetTarget(RENDER_TARGET aTarget) override
Set the target for rendering.
const int scale
wxSize GetSizePixels() const
Definition: bitmap_base.h:124
std::unique_ptr< GL_BITMAP_CACHE > m_bitmapCache
Definition: opengl_gal.h:342
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 1947 of file opengl_gal.cpp.

1948 {
1949  const float TEX_X = font_image.width;
1950  const float TEX_Y = font_image.height;
1951 
1952  // handle space
1953  if( aChar == ' ' )
1954  {
1955  const FONT_GLYPH_TYPE* g = LookupGlyph( 'x' );
1956  wxASSERT( g );
1957 
1958  if( !g ) // Should not happen.
1959  return 0;
1960 
1961  Translate( VECTOR2D( g->advance, 0 ) );
1962  return g->advance;
1963  }
1964 
1965  const FONT_GLYPH_TYPE* glyph = LookupGlyph( aChar );
1966 
1967  // If the glyph is not found (happens for many esoteric unicode chars)
1968  // shows a '?' instead.
1969  if( !glyph )
1970  glyph = LookupGlyph( '?' );
1971 
1972  if( !glyph ) // Should not happen.
1973  return 0;
1974 
1975  const float X = glyph->atlas_x + font_information.smooth_pixels;
1976  const float Y = glyph->atlas_y + font_information.smooth_pixels;
1977  const float XOFF = glyph->minx;
1978 
1979  // adjust for height rounding
1980  const float round_adjust = ( glyph->maxy - glyph->miny )
1981  - float( glyph->atlas_h - font_information.smooth_pixels * 2 );
1982  const float top_adjust = font_information.max_y - glyph->maxy;
1983  const float YOFF = round_adjust + top_adjust;
1984  const float W = glyph->atlas_w - font_information.smooth_pixels * 2;
1985  const float H = glyph->atlas_h - font_information.smooth_pixels * 2;
1986  const float B = 0;
1987 
1988  m_currentManager->Reserve( 6 );
1989  Translate( VECTOR2D( XOFF, YOFF ) );
1990 
1991  /* Glyph:
1992  * v0 v1
1993  * +--+
1994  * | /|
1995  * |/ |
1996  * +--+
1997  * v2 v3
1998  */
1999  m_currentManager->Shader( SHADER_FONT, X / TEX_X, ( Y + H ) / TEX_Y );
2000  m_currentManager->Vertex( -B, -B, 0 ); // v0
2001 
2002  m_currentManager->Shader( SHADER_FONT, ( X + W ) / TEX_X, ( Y + H ) / TEX_Y );
2003  m_currentManager->Vertex( W + B, -B, 0 ); // v1
2004 
2005  m_currentManager->Shader( SHADER_FONT, X / TEX_X, Y / TEX_Y );
2006  m_currentManager->Vertex( -B, H + B, 0 ); // v2
2007 
2008 
2009  m_currentManager->Shader( SHADER_FONT, ( X + W ) / TEX_X, ( Y + H ) / TEX_Y );
2010  m_currentManager->Vertex( W + B, -B, 0 ); // v1
2011 
2012  m_currentManager->Shader( SHADER_FONT, X / TEX_X, Y / TEX_Y );
2013  m_currentManager->Vertex( -B, H + B, 0 ); // v2
2014 
2015  m_currentManager->Shader( SHADER_FONT, ( X + W ) / TEX_X, Y / TEX_Y );
2016  m_currentManager->Vertex( W + B, H + B, 0 ); // v3
2017 
2018  Translate( VECTOR2D( -XOFF + glyph->advance, -YOFF ) );
2019 
2020  return glyph->advance;
2021 }
void Translate(const VECTOR2D &aTranslation) override
Translate the context.
bool Reserve(unsigned int aSize)
Allocate space for vertices, so it will be used with subsequent Vertex() calls.
bool Vertex(const VERTEX &aVertex)
Add a vertex with the given coordinates to the currently set item.
const FONT_GLYPH_TYPE * LookupGlyph(unsigned int aCodepoint)
VERTEX_MANAGER * m_currentManager
Currently used VERTEX_MANAGER (for storing VERTEX_ITEMs).
Definition: opengl_gal.h:311
VECTOR2< double > VECTOR2D
Definition: vector2d.h:622
FONT_IMAGE_TYPE font_image
Definition: gl_resources.cpp:4
FONT_INFO_TYPE font_information
Definition: gl_resources.cpp:3
#define H(x, y, z)
Definition: md5_hash.cpp:17
void Shader(GLfloat aShaderType, GLfloat aParam1=0.0f, GLfloat aParam2=0.0f, GLfloat aParam3=0.0f)
Change currently used shader and its parameters that will be applied to newly added vertices.

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

Referenced by BitmapText().

◆ drawBitmapOverbar()

void OPENGL_GAL::drawBitmapOverbar ( double  aLength,
double  aHeight 
)
private

Draw an overbar over the currently drawn text.

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

Parameters
aLengthis the width of the overbar.
aHeightis the height for the overbar.

Definition at line 2024 of file opengl_gal.cpp.

2025 {
2026  // To draw an overbar, simply draw an overbar
2027  const FONT_GLYPH_TYPE* glyph = LookupGlyph( '_' );
2028  wxCHECK( glyph, /* void */ );
2029 
2030  const float H = glyph->maxy - glyph->miny;
2031 
2032  Save();
2033 
2034  Translate( VECTOR2D( -aLength, -aHeight - 1.5 * H ) );
2035 
2036  m_currentManager->Reserve( 6 );
2038 
2039  m_currentManager->Shader( 0 );
2040 
2041  m_currentManager->Vertex( 0, 0, 0 ); // v0
2042  m_currentManager->Vertex( aLength, 0, 0 ); // v1
2043  m_currentManager->Vertex( 0, H, 0 ); // v2
2044 
2045  m_currentManager->Vertex( aLength, 0, 0 ); // v1
2046  m_currentManager->Vertex( 0, H, 0 ); // v2
2047  m_currentManager->Vertex( aLength, H, 0 ); // v3
2048 
2049  Restore();
2050 }
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:359
const FONT_GLYPH_TYPE * LookupGlyph(unsigned int aCodepoint)
double b
Blue component.
Definition: color4d.h:360
void Save() override
Save the context.
VERTEX_MANAGER * m_currentManager
Currently used VERTEX_MANAGER (for storing VERTEX_ITEMs).
Definition: opengl_gal.h:311
double a
Alpha component.
Definition: color4d.h:361
COLOR4D m_strokeColor
The color of the outlines.
VECTOR2< double > VECTOR2D
Definition: vector2d.h:622
void Color(const COLOR4D &aColor)
Changes currently used color that will be applied to newly added vertices.
#define H(x, y, z)
Definition: md5_hash.cpp:17
void Shader(GLfloat aShaderType, GLfloat aParam1=0.0f, GLfloat aParam2=0.0f, GLfloat aParam3=0.0f)
Change currently used shader and its parameters that will be applied to newly added vertices.
double r
Red component.
Definition: color4d.h:358

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

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

1753 {
1754  // Now we should only store the position of the mouse cursor
1755  // The real drawing routines are in blitCursor()
1756  //VECTOR2D screenCursor = m_worldScreenMatrix * aCursorPosition;
1757  //m_cursorPosition = m_screenWorldMatrix * VECTOR2D( screenCursor.x, screenCursor.y );
1758  m_cursorPosition = aCursorPosition;
1759 }
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 1161 of file opengl_gal.cpp.

1164 {
1165  std::vector<VECTOR2D> output;
1166  std::vector<VECTOR2D> pointCtrl;
1167 
1168  pointCtrl.push_back( aStartPoint );
1169  pointCtrl.push_back( aControlPointA );
1170  pointCtrl.push_back( aControlPointB );
1171  pointCtrl.push_back( aEndPoint );
1172 
1173  BEZIER_POLY converter( pointCtrl );
1174  converter.GetPoly( output, aFilterValue );
1175 
1176  DrawPolyline( &output[0], output.size() );
1177 }
void DrawPolyline(const std::deque< VECTOR2D > &aPointList) override
Draw a polyline.
Definition: opengl_gal.cpp:988
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 1826 of file opengl_gal.cpp.

1827 {
1828  Save();
1829 
1830  m_currentManager->Reserve( 3 );
1831  m_currentManager->Translate( aCenterPoint.x, aCenterPoint.y, 0.0f );
1832  m_currentManager->Rotate( aAngle, 0.0f, 0.0f, 1.0f );
1833 
1834  /* Draw a triangle that contains the semicircle, then shade it to leave only
1835  * the semicircle. Parameters given to Shader() are indices of the triangle's vertices
1836  * (if you want to understand more, check the vertex shader source [shader.vert]).
1837  * Shader uses these coordinates to determine if fragments are inside the semicircle or not.
1838  * v2
1839  * /\
1840  * /__\
1841  * v0 //__\\ v1
1842  */
1844  m_currentManager->Vertex( -aRadius * 3.0f / sqrt( 3.0f ), 0.0f, m_layerDepth ); // v0
1845 
1847  m_currentManager->Vertex( aRadius * 3.0f / sqrt( 3.0f ), 0.0f, m_layerDepth ); // v1
1848 
1850  m_currentManager->Vertex( 0.0f, aRadius * 2.0f, m_layerDepth ); // v2
1851 
1852  Restore();
1853 }
bool Reserve(unsigned int aSize)
Allocate space for vertices, so it will be used with subsequent Vertex() calls.
void Restore() override
Restore the context.
bool Vertex(const VERTEX &aVertex)
Add a vertex with the given coordinates to the currently set item.
void Rotate(GLfloat aAngle, GLfloat aX, GLfloat aY, GLfloat aZ)
Multiply the current matrix by a rotation matrix, so the newly vertices will be rotated by the given ...
double m_layerDepth
The actual layer depth.
void Save() override
Save the context.
VERTEX_MANAGER * m_currentManager
Currently used VERTEX_MANAGER (for storing VERTEX_ITEMs).
Definition: opengl_gal.h:311
void Translate(GLfloat aX, GLfloat aY, GLfloat aZ)
Multiply the current matrix by a translation matrix, so newly vertices will be translated by the give...
void Shader(GLfloat aShaderType, GLfloat aParam1=0.0f, GLfloat aParam2=0.0f, GLfloat aParam3=0.0f)
Change currently used shader and its parameters that will be applied to newly added vertices.

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

Referenced by drawSemiCircle().

◆ DrawGrid()

void OPENGL_GAL::DrawGrid ( )
overridevirtual

Reimplemented from KIGFX::GAL.

Definition at line 1357 of file opengl_gal.cpp.

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

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

1625 {
1626  auto group = m_groups.find( aGroupNumber );
1627 
1628  if( group != m_groups.end() )
1629  m_cachedManager->DrawItem( *group->second );
1630 }
GROUPS_MAP m_groups
Stores information about VBO objects (groups)
Definition: opengl_gal.h:309
void DrawItem(const VERTEX_ITEM &aItem) const
Draw an item to the buffer.
VERTEX_MANAGER * m_cachedManager
Container for storing cached VERTEX_ITEMs.
Definition: opengl_gal.h:313

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

◆ DrawLine()

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

Draw a line.

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

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

Reimplemented from KIGFX::GAL.

Definition at line 654 of file opengl_gal.cpp.

655 {
657 
658  drawLineQuad( aStartPoint, aEndPoint );
659 }
void drawLineQuad(const VECTOR2D &aStartPoint, const VECTOR2D &aEndPoint)
Draw a quad for the line.
double g
Green component.
Definition: color4d.h:359
double b
Blue component.
Definition: color4d.h:360
VERTEX_MANAGER * m_currentManager
Currently used VERTEX_MANAGER (for storing VERTEX_ITEMs).
Definition: opengl_gal.h:311
double a
Alpha component.
Definition: color4d.h:361
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:358

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

1763 {
1764  /* Helper drawing: ____--- v3 ^
1765  * ____---- ... \ \
1766  * ____---- ... \ end \
1767  * v1 ____---- ... ____---- \ width
1768  * ---- ...___---- \ \
1769  * \ ___...-- \ v
1770  * \ ____----... ____---- v2
1771  * ---- ... ____----
1772  * start \ ... ____----
1773  * \... ____----
1774  * ----
1775  * v0
1776  * dots mark triangles' hypotenuses
1777  */
1778 
1779  auto v1 = m_currentManager->GetTransformation()
1780  * glm::vec4( aStartPoint.x, aStartPoint.y, 0.0, 0.0 );
1782  * glm::vec4( aEndPoint.x, aEndPoint.y, 0.0, 0.0 );
1783 
1784  VECTOR2D vs( v2.x - v1.x, v2.y - v1.y );
1785 
1786  m_currentManager->Reserve( 6 );
1787 
1788  // Line width is maintained by the vertex shader
1790  m_currentManager->Vertex( aStartPoint, m_layerDepth );
1791 
1793  m_currentManager->Vertex( aStartPoint, m_layerDepth );
1794 
1796  m_currentManager->Vertex( aEndPoint, m_layerDepth );
1797 
1799  m_currentManager->Vertex( aEndPoint, m_layerDepth );
1800 
1802  m_currentManager->Vertex( aEndPoint, m_layerDepth );
1803 
1805  m_currentManager->Vertex( aStartPoint, m_layerDepth );
1806 }
const glm::mat4 & GetTransformation() const
VECTOR2I v2(1, 0)
Test suite for KiCad math code.
bool Reserve(unsigned int aSize)
Allocate space for vertices, so it will be used with subsequent Vertex() calls.
bool Vertex(const VERTEX &aVertex)
Add a vertex with the given coordinates to the currently set item.
double m_layerDepth
The actual layer depth.
VERTEX_MANAGER * m_currentManager
Currently used VERTEX_MANAGER (for storing VERTEX_ITEMs).
Definition: opengl_gal.h:311
void Shader(GLfloat aShaderType, GLfloat aParam1=0.0f, GLfloat aParam2=0.0f, GLfloat aParam3=0.0f)
Change currently used shader and its parameters that will be applied to newly added vertices.
float m_lineWidth
The line width.

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

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

◆ DrawPolygon() [1/4]

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

Draw a polygon.

Parameters
aPointListis the list of the polygon points.

Reimplemented from KIGFX::GAL.

Definition at line 1026 of file opengl_gal.cpp.

1027 {
1028  wxCHECK( aPointList.size() >= 2, /* void */ );
1029  auto points = std::unique_ptr<GLdouble[]>( new GLdouble[3 * aPointList.size()] );
1030  GLdouble* ptr = points.get();
1031 
1032  for( const VECTOR2D& p : aPointList )
1033  {
1034  *ptr++ = p.x;
1035  *ptr++ = p.y;
1036  *ptr++ = m_layerDepth;
1037  }
1038 
1039  drawPolygon( points.get(), aPointList.size() );
1040 }
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 1043 of file opengl_gal.cpp.

1044 {
1045  wxCHECK( aListSize >= 2, /* void */ );
1046  auto points = std::unique_ptr<GLdouble[]>( new GLdouble[3 * aListSize] );
1047  GLdouble* target = points.get();
1048  const VECTOR2D* src = aPointList;
1049 
1050  for( int i = 0; i < aListSize; ++i )
1051  {
1052  *target++ = src->x;
1053  *target++ = src->y;
1054  *target++ = m_layerDepth;
1055  ++src;
1056  }
1057 
1058  drawPolygon( points.get(), aListSize );
1059 }
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)
overridevirtual

Reimplemented from KIGFX::GAL.

Definition at line 1125 of file opengl_gal.cpp.

1126 {
1127  if( aPolySet.IsTriangulationUpToDate() )
1128  {
1129  drawTriangulatedPolyset( aPolySet );
1130  return;
1131  }
1132 
1133  for( int j = 0; j < aPolySet.OutlineCount(); ++j )
1134  {
1135  const SHAPE_LINE_CHAIN& outline = aPolySet.COutline( j );
1136  DrawPolygon( outline );
1137  }
1138 }
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
void drawTriangulatedPolyset(const SHAPE_POLY_SET &aPoly)
Draw a set of polygons with a cached triangulation.
SHAPE_LINE_CHAIN.
const SHAPE_LINE_CHAIN & COutline(int aIndex) const

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

◆ DrawPolygon() [4/4]

void OPENGL_GAL::DrawPolygon ( const SHAPE_LINE_CHAIN aPolySet)
overridevirtual

Reimplemented from KIGFX::GAL.

Definition at line 1141 of file opengl_gal.cpp.

1142 {
1143  wxCHECK( aPolygon.PointCount() >= 2, /* void */ );
1144 
1145  const int pointCount = aPolygon.SegmentCount() + 1;
1146  std::unique_ptr<GLdouble[]> points( new GLdouble[3 * pointCount] );
1147  GLdouble* ptr = points.get();
1148 
1149  for( int i = 0; i < pointCount; ++i )
1150  {
1151  const VECTOR2I& p = aPolygon.CPoint( i );
1152  *ptr++ = p.x;
1153  *ptr++ = p.y;
1154  *ptr++ = m_layerDepth;
1155  }
1156 
1157  drawPolygon( points.get(), pointCount );
1158 }
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 1890 of file opengl_gal.cpp.

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

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

989 {
990  drawPolyline(
991  [&]( int idx )
992  {
993  return aPointList[idx];
994  },
995  aPointList.size() );
996 }
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 999 of file opengl_gal.cpp.

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

1011 {
1012  auto numPoints = aLineChain.PointCount();
1013 
1014  if( aLineChain.IsClosed() )
1015  numPoints += 1;
1016 
1017  drawPolyline(
1018  [&]( int idx )
1019  {
1020  return aLineChain.CPoint( idx );
1021  },
1022  numPoints );
1023 }
int PointCount() const
Function PointCount()
const VECTOR2I & CPoint(int aIndex) const
Function Point()
bool IsClosed() const override
Function IsClosed()
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 1930 of file opengl_gal.cpp.

1931 {
1932  wxCHECK( aPointCount >= 2, /* return */ );
1933 
1935  int i;
1936 
1937  for( i = 1; i < aPointCount; ++i )
1938  {
1939  auto start = aPointGetter( i - 1 );
1940  auto end = aPointGetter( i );
1941 
1942  drawLineQuad( start, end );
1943  }
1944 }
void drawLineQuad(const VECTOR2D &aStartPoint, const VECTOR2D &aEndPoint)
Draw a quad for the line.
double g
Green component.
Definition: color4d.h:359
double b
Blue component.
Definition: color4d.h:360
VERTEX_MANAGER * m_currentManager
Currently used VERTEX_MANAGER (for storing VERTEX_ITEMs).
Definition: opengl_gal.h:311
double a
Alpha component.
Definition: color4d.h:361
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:358

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

950 {
951  // Compute the diagonal points of the rectangle
952  VECTOR2D diagonalPointA( aEndPoint.x, aStartPoint.y );
953  VECTOR2D diagonalPointB( aStartPoint.x, aEndPoint.y );
954 
955  // Fill the rectangle
956  if( m_isFillEnabled )
957  {
961 
962  m_currentManager->Vertex( aStartPoint.x, aStartPoint.y, m_layerDepth );
963  m_currentManager->Vertex( diagonalPointA.x, diagonalPointA.y, m_layerDepth );
964  m_currentManager->Vertex( aEndPoint.x, aEndPoint.y, m_layerDepth );
965 
966  m_currentManager->Vertex( aStartPoint.x, aStartPoint.y, m_layerDepth );
967  m_currentManager->Vertex( aEndPoint.x, aEndPoint.y, m_layerDepth );
968  m_currentManager->Vertex( diagonalPointB.x, diagonalPointB.y, m_layerDepth );
969  }
970 
971  // Stroke the outline
972  if( m_isStrokeEnabled )
973  {
975  m_strokeColor.a );
976 
977  std::deque<VECTOR2D> pointList;
978  pointList.push_back( aStartPoint );
979  pointList.push_back( diagonalPointA );
980  pointList.push_back( aEndPoint );
981  pointList.push_back( diagonalPointB );
982  pointList.push_back( aStartPoint );
983  DrawPolyline( pointList );
984  }
985 }
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:359
double b
Blue component.
Definition: color4d.h:360
double m_layerDepth
The actual layer depth.
VERTEX_MANAGER * m_currentManager
Currently used VERTEX_MANAGER (for storing VERTEX_ITEMs).
Definition: opengl_gal.h:311
double a
Alpha component.
Definition: color4d.h:361
bool m_isStrokeEnabled
Are the outlines stroked ?
COLOR4D m_strokeColor
The color of the outlines.
void Color(const COLOR4D &aColor)
Changes currently used color that will be applied to newly added vertices.
void DrawPolyline(const std::deque< VECTOR2D > &aPointList) override
Draw a polyline.
Definition: opengl_gal.cpp:988
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:358

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

664 {
665  VECTOR2D startEndVector = aEndPoint - aStartPoint;
666  double lineLength = startEndVector.EuclideanNorm();
667 
668  float startx = aStartPoint.x;
669  float starty = aStartPoint.y;
670  float endx = aStartPoint.x + lineLength;
671  float endy = aStartPoint.y + lineLength;
672 
673  // Be careful about floating point rounding. As we draw segments in larger and larger
674  // coordinates, the shader (which uses floats) will lose precision and stop drawing small
675  // segments. In this case, we need to draw a circle for the minimal segment.
676  if( startx == endx || starty == endy )
677  {
678  DrawCircle( aStartPoint, aWidth / 2 );
679  return;
680  }
681 
682  if( m_isFillEnabled || aWidth == 1.0 )
683  {
685 
686  SetLineWidth( aWidth );
687  drawLineQuad( aStartPoint, aEndPoint );
688  }
689  else
690  {
691  auto lineAngle = startEndVector.Angle();
692  // Outlined tracks
693 
694  SetLineWidth( 1.0 );
696  m_strokeColor.a );
697 
698  Save();
699 
700  m_currentManager->Translate( aStartPoint.x, aStartPoint.y, 0.0 );
701  m_currentManager->Rotate( lineAngle, 0.0f, 0.0f, 1.0f );
702 
703  drawLineQuad( VECTOR2D( 0.0, aWidth / 2.0 ), VECTOR2D( lineLength, aWidth / 2.0 ) );
704 
705  drawLineQuad( VECTOR2D( 0.0, -aWidth / 2.0 ), VECTOR2D( lineLength, -aWidth / 2.0 ) );
706 
707  // Draw line caps
708  drawStrokedSemiCircle( VECTOR2D( 0.0, 0.0 ), aWidth / 2, M_PI / 2 );
709  drawStrokedSemiCircle( VECTOR2D( lineLength, 0.0 ), aWidth / 2, -M_PI / 2 );
710 
711  Restore();
712  }
713 }
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:359
virtual void SetLineWidth(float aLineWidth)
Set the line width.
double b
Blue component.
Definition: color4d.h:360
void Save() override
Save the context.
VERTEX_MANAGER * m_currentManager
Currently used VERTEX_MANAGER (for storing VERTEX_ITEMs).
Definition: opengl_gal.h:311
double a
Alpha component.
Definition: color4d.h:361
COLOR4D m_strokeColor
The color of the outlines.
VECTOR2< double > VECTOR2D
Definition: vector2d.h:622
void Translate(GLfloat aX, GLfloat aY, GLfloat aZ)
Multiply the current matrix by a translation matrix, so newly vertices will be translated by the give...
double Angle() const
Compute the angle of the vector.
Definition: vector2d.h:307
void Color(const COLOR4D &aColor)
Changes currently used color that will be applied to newly added vertices.
void drawStrokedSemiCircle(const VECTOR2D &aCenterPoint, double aRadius, double aAngle)
Draw a stroked semicircle.
COLOR4D m_fillColor
The fill color.
T EuclideanNorm() const
Compute the Euclidean norm of the vector, which is defined as sqrt(x ** 2 + y ** 2).
Definition: vector2d.h:293
double r
Red component.
Definition: color4d.h:358
void DrawCircle(const VECTOR2D &aCenterPoint, double aRadius) override
Draw a circle using world coordinates.
Definition: opengl_gal.cpp:716

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

1810 {
1811  if( m_isFillEnabled )
1812  {
1814  drawFilledSemiCircle( aCenterPoint, aRadius, aAngle );
1815  }
1816 
1817  if( m_isStrokeEnabled )
1818  {
1820  m_strokeColor.a );
1821  drawStrokedSemiCircle( aCenterPoint, aRadius, aAngle );
1822  }
1823 }
bool m_isFillEnabled
Is filling of graphic objects enabled ?
double g
Green component.
Definition: color4d.h:359
double b
Blue component.
Definition: color4d.h:360
VERTEX_MANAGER * m_currentManager
Currently used VERTEX_MANAGER (for storing VERTEX_ITEMs).
Definition: opengl_gal.h:311
double a
Alpha component.
Definition: color4d.h:361
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:358
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 1856 of file opengl_gal.cpp.

1858 {
1859  double outerRadius = aRadius + ( m_lineWidth / 2 );
1860 
1861  Save();
1862 
1863  m_currentManager->Reserve( 3 );
1864  m_currentManager->Translate( aCenterPoint.x, aCenterPoint.y, 0.0f );
1865  m_currentManager->Rotate( aAngle, 0.0f, 0.0f, 1.0f );
1866 
1867  /* Draw a triangle that contains the semicircle, then shade it to leave only
1868  * the semicircle. Parameters given to Shader() are indices of the triangle's vertices
1869  * (if you want to understand more, check the vertex shader source [shader.vert]), the
1870  * radius and the line width. Shader uses these coordinates to determine if fragments are
1871  * inside the semicircle or not.
1872  * v2
1873  * /\
1874  * /__\
1875  * v0 //__\\ v1
1876  */
1878  m_currentManager->Vertex( -outerRadius * 3.0f / sqrt( 3.0f ), 0.0f, m_layerDepth ); // v0
1879 
1881  m_currentManager->Vertex( outerRadius * 3.0f / sqrt( 3.0f ), 0.0f, m_layerDepth ); // v1
1882 
1884  m_currentManager->Vertex( 0.0f, outerRadius * 2.0f, m_layerDepth ); // v2
1885 
1886  Restore();
1887 }
bool Reserve(unsigned int aSize)
Allocate space for vertices, so it will be used with subsequent Vertex() calls.
void Restore() override
Restore the context.
bool Vertex(const VERTEX &aVertex)
Add a vertex with the given coordinates to the currently set item.
void Rotate(GLfloat aAngle, GLfloat aX, GLfloat aY, GLfloat aZ)
Multiply the current matrix by a rotation matrix, so the newly vertices will be rotated by the given ...
double m_layerDepth
The actual layer depth.
void Save() override
Save the context.
VERTEX_MANAGER * m_currentManager
Currently used VERTEX_MANAGER (for storing VERTEX_ITEMs).
Definition: opengl_gal.h:311
void Translate(GLfloat aX, GLfloat aY, GLfloat aZ)
Multiply the current matrix by a translation matrix, so newly vertices will be translated by the give...
void Shader(GLfloat aShaderType, GLfloat aParam1=0.0f, GLfloat aParam2=0.0f, GLfloat aParam3=0.0f)
Change currently used shader and its parameters that will be applied to newly added vertices.
float m_lineWidth
The line width.

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

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

◆ drawTriangulatedPolyset()

void OPENGL_GAL::drawTriangulatedPolyset ( const SHAPE_POLY_SET aPoly)
private

Draw a set of polygons with a cached triangulation.

Way faster than drawPolygon.

Definition at line 1062 of file opengl_gal.cpp.

1063 {
1066 
1067  if( m_isFillEnabled )
1068  {
1069  for( unsigned int j = 0; j < aPolySet.TriangulatedPolyCount(); ++j )
1070  {
1071  auto triPoly = aPolySet.TriangulatedPolygon( j );
1072 
1073  for( size_t i = 0; i < triPoly->GetTriangleCount(); i++ )
1074  {
1075  VECTOR2I a, b, c;
1076  triPoly->GetTriangle( i, a, b, c );
1080  }
1081  }
1082  }
1083 
1084  if( m_isStrokeEnabled )
1085  {
1086  for( int j = 0; j < aPolySet.OutlineCount(); ++j )
1087  {
1088  const auto& poly = aPolySet.Polygon( j );
1089 
1090  for( const auto& lc : poly )
1091  {
1092  DrawPolyline( lc );
1093  }
1094  }
1095  }
1096 
1097  if( ADVANCED_CFG::GetCfg().m_DrawTriangulationOutlines )
1098  {
1099  COLOR4D oldStrokeColor = m_strokeColor;
1100  double oldLayerDepth = m_layerDepth;
1101 
1102  SetLayerDepth( m_layerDepth - 1 );
1103  SetStrokeColor( COLOR4D( 0.0, 1.0, 0.2, 1.0 ) );
1104 
1105  for( unsigned int j = 0; j < aPolySet.TriangulatedPolyCount(); ++j )
1106  {
1107  auto triPoly = aPolySet.TriangulatedPolygon( j );
1108 
1109  for( size_t i = 0; i < triPoly->GetTriangleCount(); i++ )
1110  {
1111  VECTOR2I a, b, c;
1112  triPoly->GetTriangle( i, a, b, c );
1113  DrawLine( a, b );
1114  DrawLine( b, c );
1115  DrawLine( c, a );
1116  }
1117  }
1118 
1119  SetStrokeColor( oldStrokeColor );
1120  SetLayerDepth( oldLayerDepth );
1121  }
1122 }
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:359
virtual void SetLayerDepth(double aLayerDepth)
Set the depth of the layer (position on the z-axis)
double b
Blue component.
Definition: color4d.h:360
double m_layerDepth
The actual layer depth.
VERTEX_MANAGER * m_currentManager
Currently used VERTEX_MANAGER (for storing VERTEX_ITEMs).
Definition: opengl_gal.h:311
double a
Alpha component.
Definition: color4d.h:361
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:654
void Color(const COLOR4D &aColor)
Changes currently used color that will be applied to newly added vertices.
void DrawPolyline(const std::deque< VECTOR2D > &aPointList) override
Draw a polyline.
Definition: opengl_gal.cpp:988
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:358
A color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:98

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

2317 {
2318  m_cachedManager->EnableDepthTest( aEnabled );
2319  m_nonCachedManager->EnableDepthTest( aEnabled );
2320  m_overlayManager->EnableDepthTest( aEnabled );
2321 }
VERTEX_MANAGER * m_overlayManager
Container for storing overlaid VERTEX_ITEMs.
Definition: opengl_gal.h:315
VERTEX_MANAGER * m_cachedManager
Container for storing cached VERTEX_ITEMs.
Definition: opengl_gal.h:313
void EnableDepthTest(bool aEnabled)
Enable/disable Z buffer depth test.
VERTEX_MANAGER * m_nonCachedManager
Container for storing non-cached VERTEX_ITEMs.
Definition: opengl_gal.h:314

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

◆ endDrawing()

void OPENGL_GAL::endDrawing ( )
overrideprivatevirtual

Update handler for OpenGL settings

Reimplemented from KIGFX::GAL.

Definition at line 564 of file opengl_gal.cpp.

565 {
566  wxASSERT_MSG( m_isContextLocked, "What happened to the context lock?" );
567 
568 #ifdef __WXDEBUG__
569  PROF_COUNTER totalRealTime( "OPENGL_GAL::endDrawing()", true );
570 #endif /* __WXDEBUG__ */
571 
572  // Cached & non-cached containers are rendered to the same buffer
576 
577  // Overlay container is rendered to a different buffer
578  if( m_overlayBuffer )
580 
582 
583  // Be sure that the framebuffer is not colorized (happens on specific GPU&drivers combinations)
584  glColor4d( 1.0, 1.0, 1.0, 1.0 );
585 
586  // Draw the remaining contents, blit the rendering targets to the screen, swap the buffers
588 
589  if( m_overlayBuffer )
591 
593  blitCursor();
594 
595  SwapBuffers();
596 
597 #ifdef __WXDEBUG__
598  totalRealTime.Stop();
599  wxLogTrace( traceGalProfile, wxT( "OPENGL_GAL::endDrawing(): %.1f ms" ),
600  totalRealTime.msecs() );
601 #endif /* __WXDEBUG__ */
602 }
unsigned int m_overlayBuffer
Auxiliary rendering target (for menus etc.)
Definition: opengl_gal.h:320
virtual void DrawBuffer(unsigned int aBufferHandle) override
Draw the selected buffer to the output buffer.
VERTEX_MANAGER * m_overlayManager
Container for storing overlaid VERTEX_ITEMs.
Definition: opengl_gal.h:315
const wxChar *const traceGalProfile
Flag to enable debug output of GAL performance profiling.
unsigned int m_mainBuffer
Main rendering target.
Definition: opengl_gal.h:319
A small class to help profiling.
Definition: profile.h:45
VERTEX_MANAGER * m_cachedManager
Container for storing cached VERTEX_ITEMs.
Definition: opengl_gal.h:313
virtual void Present() override
Call this to present the output buffer to the screen.
OPENGL_COMPOSITOR * m_compositor
Handles multiple rendering targets.
Definition: opengl_gal.h:318
virtual void SetBuffer(unsigned int aBufferHandle) override
Set the selected buffer as the rendering target.
bool m_isContextLocked
Used for assertion checking.
Definition: opengl_gal.h:334
void blitCursor()
Blit cursor into the current screen.
void EndDrawing() const
Finish drawing operations.
VERTEX_MANAGER * m_nonCachedManager
Container for storing non-cached VERTEX_ITEMs.
Definition: opengl_gal.h:314

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

◆ EndGroup()

void OPENGL_GAL::EndGroup ( )
overridevirtual

End the group.

Reimplemented from KIGFX::GAL.

Definition at line 1617 of file opengl_gal.cpp.

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

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

◆ endUpdate()

void OPENGL_GAL::endUpdate ( )
overrideprivatevirtual

Reimplemented from KIGFX::GAL.

Definition at line 645 of file opengl_gal.cpp.

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

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

◆ Flush()

void OPENGL_GAL::Flush ( )
overridevirtual

Force all remaining objects to be drawn.

Reimplemented from KIGFX::GAL.

Definition at line 1540 of file opengl_gal.cpp.

1541 {
1542  glFlush();
1543 }

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

◆ getCursorColor()

COLOR4D GAL::getCursorColor ( ) const
protectedinherited

Get the actual cursor color to draw.

Definition at line 260 of file graphics_abstraction_layer.cpp.

261 {
263 
264  // dim the cursor if it's only on because it was forced
265  // (this helps to provide a hint for active tools)
266  if( !m_isCursorEnabled )
267  color.a = color.a * 0.5;
268 
269  return color;
270 }
int color
Definition: DXF_plotter.cpp:60
bool m_isCursorEnabled
Is the cursor enabled?
COLOR4D m_cursorColor
Cursor color.
A color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:98

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

References KIGFX::GAL::m_gridLineWidth.

◆ GetGridOrigin()

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

Definition at line 861 of file graphics_abstraction_layer.h.

862  {
863  return m_gridOrigin;
864  }
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 238 of file graphics_abstraction_layer.cpp.

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

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

834 { 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(), 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().

◆ GetNativePixelSize()

wxSize HIDPI_GL_CANVAS::GetNativePixelSize ( ) const
virtualinherited

Definition at line 46 of file hidpi_gl_canvas.cpp.

47 {
48  wxSize size = wxGLCanvas::GetClientSize();
49 
50  const double scaleFactor = GetScaleFactor();
51  size.x *= scaleFactor;
52  size.y *= scaleFactor;
53 
54  return size;
55 }
double GetScaleFactor() const
Get the current scale factor.

References HIDPI_GL_CANVAS::GetScaleFactor().

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

◆ getNewGroupNumber()

unsigned int OPENGL_GAL::getNewGroupNumber ( )
private

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

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

Definition at line 2162 of file opengl_gal.cpp.

2163 {
2164  wxASSERT_MSG( m_groups.size() < std::numeric_limits<unsigned int>::max(),
2165  wxT( "There are no free slots to store a group" ) );
2166 
2167  while( m_groups.find( m_groupCounter ) != m_groups.end() )
2168  m_groupCounter++;
2169 
2170  return m_groupCounter++;
2171 }
GROUPS_MAP m_groups
Stores information about VBO objects (groups)
Definition: opengl_gal.h:309
unsigned int m_groupCounter
Counter used for generating keys for groups.
Definition: opengl_gal.h:310

References m_groupCounter, and m_groups.

Referenced by BeginGroup().

◆ GetRotation()

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

Get the rotation angle.

Returns
The rotation angle (radians).

Definition at line 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

Get the current scale factor.

Definition at line 64 of file hidpi_gl_canvas.cpp.

65 {
66  return m_scale_factor;
67 }
double m_scale_factor
The current scale factor (e.g.

References HIDPI_GL_CANVAS::m_scale_factor.

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

◆ GetScreenPixelSize()

◆ getScreenPixelSize()

VECTOR2D OPENGL_GAL::getScreenPixelSize ( ) const
private

Definition at line 406 of file opengl_gal.cpp.

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

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

Referenced by beginDrawing().

◆ GetScreenWorldMatrix()

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

Get the screen <-> world transformation matrix.

Returns
the transformation matrix.

Definition at line 594 of file graphics_abstraction_layer.h.

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

References KIGFX::GAL::m_screenWorldMatrix.

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

◆ GetStrokeColor()

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

Get the stroke color.

Returns
the color for stroking the outline.

Definition at line 293 of file graphics_abstraction_layer.h.

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

References KIGFX::GAL::m_strokeColor.

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

◆ GetStrokeFont()

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

Definition at line 335 of file graphics_abstraction_layer.h.

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

References KIGFX::GAL::m_strokeFont.

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

1684 {
1685  return m_currentTarget;
1686 }
RENDER_TARGET m_currentTarget
Current rendering target.
Definition: opengl_gal.h:321

References m_currentTarget.

Referenced by DrawBitmap().

◆ GetTextLineSize()

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

Compute the X and Y size of a given text.

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

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

Definition at line 177 of file graphics_abstraction_layer.cpp.

178 {
179  // Compute the X and Y size of a given text.
180  // Because computeTextLineSize expects a one line text,
181  // aText is expected to be only one line text.
182  return m_strokeFont.computeTextLineSize( aText );
183 }
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 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(), 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 215 of file graphics_abstraction_layer.cpp.

216 {
217  const MATRIX3x3D& matrix = GetScreenWorldMatrix();
218 
219  VECTOR2D halfSize = VECTOR2D( matrix.GetScale().x * m_screenSize.x * 0.5,
220  matrix.GetScale().y * m_screenSize.y * 0.5 );
221 
222  BOX2D extents;
223  extents.SetOrigin( GetLookAtPoint() - halfSize );
224  extents.SetSize( halfSize * 2 );
225 
226  return extents;
227 }
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:269
VECTOR2< double > VECTOR2D
Definition: vector2d.h:622
const VECTOR2D & GetLookAtPoint() const
Get the look at point.
void SetOrigin(const Vec &pos)
Definition: box2.h:210
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 399 of file opengl_gal.cpp.

400 {
401  MATRIX3x3D matrix = GetScreenWorldMatrix();
402  return std::min( std::abs( matrix.GetScale().x ), std::abs( matrix.GetScale().y ) );
403 }
const MATRIX3x3D & GetScreenWorldMatrix() const
Get the screen <-> world transformation matrix.
VECTOR2< T > GetScale() const
Get the scale components of the matrix.
Definition: matrix3x3.h:269

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

Referenced by beginDrawing(), and DrawGrid().

◆ GetWorldScale()

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

◆ GetWorldScreenMatrix()

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

Get the world <-> screen transformation matrix.

Returns
the transformation matrix.

Definition at line 584 of file graphics_abstraction_layer.h.

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

References KIGFX::GAL::m_worldScreenMatrix.

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

◆ GetZoomFactor()

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

Get the zoom factor.

Returns
the zoom factor.

Definition at line 683 of file graphics_abstraction_layer.h.

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

References KIGFX::GAL::m_zoomFactor.

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

◆ HasTarget()

bool OPENGL_GAL::HasTarget ( RENDER_TARGET  aTarget)
overridevirtual

Return true if the target exists.

Parameters
aTargetis the target to be checked.

Reimplemented from KIGFX::GAL.

Definition at line 1719 of file opengl_gal.cpp.

1720 {
1721  switch( aTarget )
1722  {
1723  default:
1724  case TARGET_CACHED:
1725  case TARGET_NONCACHED: return true;
1726  case TARGET_OVERLAY: return ( m_overlayBuffer != 0 );
1727  }
1728 }
unsigned int m_overlayBuffer
Auxiliary rendering target (for menus etc.)
Definition: opengl_gal.h:320
Auxiliary rendering target (noncached)
Definition: definitions.h:49
Items that may change while the view stays the same (noncached)
Definition: definitions.h:50
Main rendering target (cached)
Definition: definitions.h:48

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

◆ init()

void OPENGL_GAL::init ( )
private

Basic OpenGL initialization and feature checks.

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

Definition at line 2174 of file opengl_gal.cpp.

2175 {
2176  wxASSERT( IsShownOnScreen() );
2177 
2178  wxASSERT_MSG( m_isContextLocked, "This should only be called from within a locked context." );
2179 
2180 // IsDisplayAttr() handles WX_GL_{MAJOR,MINOR}_VERSION correctly only in 3.0.4
2181 // starting with 3.1.0 one should use wxGLContext::IsOk() (done by GL_CONTEXT_MANAGER)
2182 #if wxCHECK_VERSION( 3, 0, 3 ) and !wxCHECK_VERSION( 3, 1, 0 )
2183  const int attr[] = { WX_GL_MAJOR_VERSION, 2, WX_GL_MINOR_VERSION, 1, 0 };
2184 
2185  if( !IsDisplaySupported( attr ) )
2186  throw std::runtime_error( "OpenGL 2.1 or higher is required!" );
2187 #endif /* wxCHECK_VERSION( 3, 0, 3 ) */
2188 
2189  // Check correct initialization from the constructor
2190  if( !m_glMainContext )
2191  throw std::runtime_error( "Could not create the main OpenGL context" );
2192 
2193  if( !m_glPrivContext )
2194  throw std::runtime_error( "Could not create a private OpenGL context" );
2195 
2196  if( m_tesselator == NULL )
2197  throw std::runtime_error( "Could not create the m_tesselator" );
2198  // End initialization checks
2199 
2200  GLenum err = glewInit();
2201 
2202  if( GLEW_OK != err )
2203  throw std::runtime_error( (const char*) glewGetErrorString( err ) );
2204 
2205  // Check the OpenGL version (minimum 2.1 is required)
2206  if( !GLEW_VERSION_2_1 )
2207  throw std::runtime_error( "OpenGL 2.1 or higher is required!" );
2208 
2209 #if defined( __LINUX__ ) // calling enableGlDebug crashes opengl on some OS (OSX and some Windows)
2210 #ifdef DEBUG
2211  if( GLEW_ARB_debug_output )
2212  enableGlDebug( true );
2213 #endif
2214 #endif
2215 
2216  // Framebuffers have to be supported
2217  if( !GLEW_EXT_framebuffer_object )
2218  throw std::runtime_error( "Framebuffer objects are not supported!" );
2219 
2220  // Vertex buffer has to be supported
2221  if( !GLEW_ARB_vertex_buffer_object )
2222  throw std::runtime_error( "Vertex buffer objects are not supported!" );
2223 
2224  // Prepare shaders
2225  if( !m_shader->IsLinked()
2228  {
2229  throw std::runtime_error( "Cannot compile vertex shader!" );
2230  }
2231 
2232  if( !m_shader->IsLinked()
2235  {
2236  throw std::runtime_error( "Cannot compile fragment shader!" );
2237  }
2238 
2239  if( !m_shader->IsLinked() && !m_shader->Link() )
2240  throw std::runtime_error( "Cannot link the shaders!" );
2241 
2242  // Check if video card supports textures big enough to fit the font atlas
2243  int maxTextureSize;
2244  glGetIntegerv( GL_MAX_TEXTURE_SIZE, &maxTextureSize );
2245 
2246  if( maxTextureSize < (int) font_image.width || maxTextureSize < (int) font_image.height )
2247  {
2248  // TODO implement software texture scaling
2249  // for bitmap fonts and use a higher resolution texture?
2250  throw std::runtime_error( "Requested texture size is not supported" );
2251  }
2252 
2254 
2255  m_cachedManager = new VERTEX_MANAGER( true );
2256  m_nonCachedManager = new VERTEX_MANAGER( false );
2257  m_overlayManager = new VERTEX_MANAGER( false );
2258 
2259  // Make VBOs use shaders
2263 
2264  m_isInitialized = true;
2265 }
bool IsLinked() const
Return true if shaders are linked correctly.
Definition: shader.h:118
bool LoadShaderFromStrings(SHADER_TYPE aShaderType, Args &&... aArgs)
Add a shader and compile the shader sources.
Definition: shader.h:93
VERTEX_MANAGER * m_overlayManager
Container for storing overlaid VERTEX_ITEMs.
Definition: opengl_gal.h:315
Fragment shader.
Definition: shader.h:47
bool Link()
Link the shaders.
Definition: shader.cpp:100
VERTEX_MANAGER * m_cachedManager
Container for storing cached VERTEX_ITEMs.
Definition: opengl_gal.h:313
void enableGlDebug(bool aEnable)
Enable or disable OpenGL driver messages output.
Definition: utils.cpp:179
static wxGLContext * m_glMainContext
Parent OpenGL context.
Definition: opengl_gal.h:298
#define NULL
SHADER * m_shader
There is only one shader used for different objects.
Definition: opengl_gal.h:324
bool m_isInitialized
Basic initialization flag, has to be done when the window is visible.
Definition: opengl_gal.h:331
void SetShader(SHADER &aShader) const
Set a shader program that is going to be used during rendering.
GLUtesselator * m_tesselator
Definition: opengl_gal.h:345
FONT_IMAGE_TYPE font_image
Definition: gl_resources.cpp:4
Vertex shader.
Definition: shader.h:46
bool m_isContextLocked
Used for assertion checking.
Definition: opengl_gal.h:334
wxGLContext * m_glPrivContext
Canvas-specific OpenGL context.
Definition: opengl_gal.h:299
Class to control vertex container and GPU with possibility of emulating old-style OpenGL 1....
static int SetSwapInterval(int aVal)
Attempts to set the OpenGL swap interval.
Definition: gl_utils.h:40
VERTEX_MANAGER * m_nonCachedManager
Container for storing non-cached VERTEX_ITEMs.
Definition: opengl_gal.h:314

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

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

◆ IsCairoEngine()

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

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

Reimplemented in KIGFX::CAIRO_GAL_BASE.

Definition at line 80 of file graphics_abstraction_layer.h.

80 { return false; }

Referenced by getShadowLayer().

◆ IsContextLocked()

bool KIGFX::OPENGL_GAL::IsContextLocked ( )
inlineoverridevirtual

Parameters passed to the GLU tesselator.

Reimplemented from KIGFX::GAL.

Definition at line 276 of file opengl_gal.h.

References m_isContextLocked.

◆ IsCursorEnabled()

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

Return information about cursor visibility.

Returns
True if cursor is visible.

Definition at line 997 of file graphics_abstraction_layer.h.

998  {
1000  }
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

◆ IsInitialized()

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

Return the initialization status for the canvas.

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

Reimplemented from KIGFX::GAL.

Definition at line 99 of file opengl_gal.h.

◆ IsOpenGlEngine()

bool KIGFX::OPENGL_GAL::IsOpenGlEngine ( )
inlineoverridevirtual

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

Reimplemented from KIGFX::GAL.

Definition at line 96 of file opengl_gal.h.

96 { return true; }

◆ IsTextMirrored()

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

◆ IsVisible()

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

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

Reimplemented from KIGFX::GAL.

Definition at line 106 of file opengl_gal.h.

107  {
108  return IsShownOnScreen() && !GetClientRect().IsEmpty();
109  }

Referenced by beginDrawing(), and beginUpdate().