KiCad PCB EDA Suite
KIGFX::OPENGL_GAL Class Reference

Class OpenGL_GAL is the 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"))
 Constructor OPENGL_GAL. More...
 
 ~OPENGL_GAL ()
 
bool IsOpenGlEngine () override
 Returns true if the GAL engine is a opengl based type. More...
 
bool IsInitialized () const override
 Returns the initalization status for the canvas. More...
 
bool IsVisible () const override
 

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
 Draws a text using a bitmap font. More...
 
void DrawGrid () override
 

More...
 
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
 Changes the color used to draw the group. More...
 
void ChangeGroupDepth (int aGroupNumber, int aDepth) override
 Changes 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
 Sets the target for rendering. More...
 
RENDER_TARGET GetTarget () const override
 Gets the currently used target for rendering. More...
 
void ClearTarget (RENDER_TARGET aTarget) override
 Clears the target for rendering. More...
 
virtual bool HasTarget (RENDER_TARGET aTarget) override
 Returns true if the target exists. More...
 
void SetNegativeDrawMode (bool aSetting) override
 Sets negative draw mode in the renderer. More...
 
void ComputeWorldScreenMatrix () override
 Compute the world <-> screen transformation matrix. 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
 Parameters passed to the GLU tesselator. More...
 
virtual bool IsCairoEngine ()
 Returns true if the GAL engine is a cairo based type. More...
 
const VECTOR2IGetScreenPixelSize () const
 Returns 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)
 Draws 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
 Returns 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...
 
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
 Returns the minimum depth in the currently used range (the top). More...
 
double GetMaxDepth () const
 Returns 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)
 Sets 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
 Returns 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)
 Enables 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
 Function GetGridPoint() 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
 Returns information about cursor visibility. More...
 
void SetCursorColor (const COLOR4D &aCursorColor)
 Set the cursor color. More...
 
void AdvanceDepth ()
 Changes the current depth to deeper, so it is possible to draw objects right beneath other. More...
 
void PushDepth ()
 Stores current drawing depth on the depth stack. More...
 
void PopDepth ()
 Restores 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
 Gets 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_OPTIONSoptions
 
UTIL::LINK observerLink
 
std::stack< double > depthStack
 Stored depth values. More...
 
VECTOR2I screenSize
 Screen size in screen coordinates. More...
 
double worldUnitLength
 The unit length of the world coordinates [inch]. More...
 
double screenDPI
 The dots per inch of the screen. More...
 
VECTOR2D lookAtPoint
 Point to be looked at in world space. More...
 
double zoomFactor
 The zoom factor. More...
 
double rotation
 Rotation transformation (radians) More...
 
MATRIX3x3D worldScreenMatrix
 World transformation. More...
 
MATRIX3x3D screenWorldMatrix
 Screen transformation. More...
 
double worldScale
 The scale factor world->screen. More...
 
bool globalFlipX
 Flag for X axis flipping. More...
 
bool globalFlipY
 Flag for Y axis flipping. More...
 
float lineWidth
 The line width. More...
 
bool isFillEnabled
 Is filling of graphic objects enabled ? More...
 
bool isStrokeEnabled
 Are the outlines stroked ? More...
 
COLOR4D fillColor
 The fill color. More...
 
COLOR4D strokeColor
 The color of the outlines. More...
 
COLOR4D m_clearColor
 
double layerDepth
 The actual layer depth. More...
 
VECTOR2D depthRange
 Range of the depth. More...
 
bool gridVisibility
 Should the grid be shown. More...
 
GRID_STYLE gridStyle
 Grid display style. More...
 
VECTOR2D gridSize
 The grid size. More...
 
VECTOR2D gridOrigin
 The grid origin. More...
 
VECTOR2D gridOffset
 The grid offset to compensate cursor position. More...
 
COLOR4D gridColor
 Color of the grid. More...
 
COLOR4D axesColor
 Color of the axes. More...
 
bool axesEnabled
 Should the axes be drawn. More...
 
int gridTick
 Every tick line gets the double width. More...
 
float gridLineWidth
 Line width of the grid. More...
 
int gridMinSpacing
 Minimum screen size of the grid (pixels) below which the grid is not drawn. More...
 
bool isCursorEnabled
 Is the cursor enabled? More...
 
bool forceDisplayCursor
 Always show cursor. More...
 
COLOR4D cursorColor
 Cursor color. More...
 
bool fullscreenCursor
 Shape of the cursor (fullscreen or small cross) More...
 
VECTOR2D cursorPosition
 Current cursor position (world coordinates) More...
 
STROKE_FONT strokeFont
 Instance of object that stores information about how to draw texts. 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
 Private: 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
 Function updatedGalDisplayOptions. 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)
 Draws a filled polygon. More...
 
void drawTriangulatedPolyset (const SHAPE_POLY_SET &aPoly)
 Draws a set of polygons with a cached triangulation. More...
 
int drawBitmapChar (unsigned long aChar)
 Draws a single character using bitmap font. More...
 
void drawBitmapOverbar (double aLength, double aHeight)
 Draws an overbar over the currently drawn text. More...
 
std::pair< VECTOR2D, float > computeBitmapTextSize (const UTF8 &aText) const
 Computes 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 blitCursor ()
 Blits cursor into the current screen. More...
 
unsigned int getNewGroupNumber ()
 Returns 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 * glPrivContext
 Canvas-specific OpenGL context. More...
 
wxEvtHandler * mouseListener
 
wxEvtHandler * paintListener
 
GROUPS_MAP groups
 Stores informations about VBO objects (groups) More...
 
unsigned int groupCounter
 Counter used for generating keys for groups. More...
 
VERTEX_MANAGERcurrentManager
 Currently used VERTEX_MANAGER (for storing VERTEX_ITEMs) More...
 
VERTEX_MANAGERcachedManager
 Container for storing cached VERTEX_ITEMs. More...
 
VERTEX_MANAGERnonCachedManager
 Container for storing non-cached VERTEX_ITEMs. More...
 
VERTEX_MANAGERoverlayManager
 Container for storing overlaid VERTEX_ITEMs. More...
 
OPENGL_COMPOSITORcompositor
 Handles multiple rendering targets. More...
 
unsigned int mainBuffer
 Main rendering target. More...
 
unsigned int overlayBuffer
 Auxiliary rendering target (for menus etc.) More...
 
RENDER_TARGET currentTarget
 Current rendering target. More...
 
SHADERshader
 There is only one shader used for different objects. More...
 
bool isFramebufferInitialized
 Are the framebuffers initialized? More...
 
bool isBitmapFontInitialized
 Is the shader set to use bitmap fonts? More...
 
bool isInitialized
 Basic initialization flag, has to be done when the window is visible. More...
 
bool isGrouping
 Was a group started? More...
 
bool isContextLocked
 Used for assertion checking. More...
 
int lockClientCookie
 
GLint ufm_worldPixelSize
 
GLint ufm_screenPixelSize
 
GLint ufm_pixelSizeMultiplier
 
std::unique_ptr< GL_BITMAP_CACHEbitmapCache
 
GLUtesselator * tesselator
 The tessellator. More...
 
std::deque< boost::shared_array< GLdouble > > tessIntersects
 Storage for intersecting points. More...
 

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 * glMainContext = NULL
 Parent OpenGL context. More...
 
static int instanceCounter = 0
 GL GAL instance counter. More...
 
static GLuint fontTexture = 0
 Bitmap font texture handle (shared) More...
 
static bool isBitmapFontLoaded = false
 Is the bitmap font texture loaded? More...
 

Detailed Description

Class OpenGL_GAL is the 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 65 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 299 of file opengl_gal.h.

◆ super

typedef GAL KIGFX::OPENGL_GAL::super
private

Super class definition.

Definition at line 285 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" ) 
)

Constructor OPENGL_GAL.

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  mouseListener( aMouseListener ),
203  paintListener( aPaintListener ),
204  currentManager( nullptr ),
205  cachedManager( nullptr ),
206  nonCachedManager( nullptr ),
207  overlayManager( nullptr ),
208  mainBuffer( 0 ),
209  overlayBuffer( 0 ),
210  isContextLocked( false ),
211  lockClientCookie( 0 )
212 {
213  if( glMainContext == NULL )
214  {
216 
218  }
219  else
220  {
222  }
223 
224  shader = new SHADER();
225  ++instanceCounter;
226 
227  bitmapCache = std::make_unique<GL_BITMAP_CACHE>( );
228 
231 
232  // Initialize the flags
233  isFramebufferInitialized = false;
234  isBitmapFontInitialized = false;
235  isInitialized = false;
236  isGrouping = false;
237  groupCounter = 0;
238 
239  // Connecting the event handlers
240  Connect( wxEVT_PAINT, wxPaintEventHandler( OPENGL_GAL::onPaint ) );
241 
242  // Mouse events are skipped to the parent
243  Connect( wxEVT_MOTION, wxMouseEventHandler( OPENGL_GAL::skipMouseEvent ) );
244  Connect( wxEVT_LEFT_DOWN, wxMouseEventHandler( OPENGL_GAL::skipMouseEvent ) );
245  Connect( wxEVT_LEFT_UP, wxMouseEventHandler( OPENGL_GAL::skipMouseEvent ) );
246  Connect( wxEVT_LEFT_DCLICK, wxMouseEventHandler( OPENGL_GAL::skipMouseEvent ) );
247  Connect( wxEVT_MIDDLE_DOWN, wxMouseEventHandler( OPENGL_GAL::skipMouseEvent ) );
248  Connect( wxEVT_MIDDLE_UP, wxMouseEventHandler( OPENGL_GAL::skipMouseEvent ) );
249  Connect( wxEVT_MIDDLE_DCLICK, wxMouseEventHandler( OPENGL_GAL::skipMouseEvent ) );
250  Connect( wxEVT_RIGHT_DOWN, wxMouseEventHandler( OPENGL_GAL::skipMouseEvent ) );
251  Connect( wxEVT_RIGHT_UP, wxMouseEventHandler( OPENGL_GAL::skipMouseEvent ) );
252  Connect( wxEVT_RIGHT_DCLICK, wxMouseEventHandler( OPENGL_GAL::skipMouseEvent ) );
253  Connect( wxEVT_MOUSEWHEEL, wxMouseEventHandler( OPENGL_GAL::skipMouseEvent ) );
254 #if wxCHECK_VERSION( 3, 1, 0 ) || defined( USE_OSX_MAGNIFY_EVENT )
255  Connect( wxEVT_MAGNIFY, wxMouseEventHandler( OPENGL_GAL::skipMouseEvent ) );
256 #endif
257 #if defined _WIN32 || defined _WIN64
258  Connect( wxEVT_ENTER_WINDOW, wxMouseEventHandler( OPENGL_GAL::skipMouseEvent ) );
259 #endif
260 
261  SetSize( aParent->GetClientSize() );
263 
264  // Grid color settings are different in Cairo and OpenGL
265  SetGridColor( COLOR4D( 0.8, 0.8, 0.8, 0.1 ) );
266  SetAxesColor( COLOR4D( BLUE ) );
267 
268  // Tesselator initialization
269  tesselator = gluNewTess();
271 
272  gluTessProperty( tesselator, GLU_TESS_WINDING_RULE, GLU_TESS_WINDING_POSITIVE );
273 
275 
276  // Avoid unitialized variables:
277  ufm_worldPixelSize = 1;
280 }
virtual wxSize GetNativePixelSize() const
VERTEX_MANAGER * currentManager
Currently used VERTEX_MANAGER (for storing VERTEX_ITEMs)
Definition: opengl_gal.h:302
static wxGLContext * glMainContext
Parent OpenGL context.
Definition: opengl_gal.h:290
unsigned int overlayBuffer
Auxiliary rendering target (for menus etc.)
Definition: opengl_gal.h:310
bool isBitmapFontInitialized
Is the shader set to use bitmap fonts?
Definition: opengl_gal.h:319
VERTEX_MANAGER * overlayManager
Container for storing overlaid VERTEX_ITEMs.
Definition: opengl_gal.h:305
GAL_DISPLAY_OPTIONS & options
std::unique_ptr< GL_BITMAP_CACHE > bitmapCache
Definition: opengl_gal.h:329
static void InitTesselatorCallbacks(GLUtesselator *aTesselator)
bool isContextLocked
Used for assertion checking.
Definition: opengl_gal.h:323
SHADER * shader
There is only one shader used for different objects.
Definition: opengl_gal.h:314
VECTOR2< int > VECTOR2I
Definition: vector2d.h:594
bool isGrouping
Was a group started?
Definition: opengl_gal.h:322
OPENGL_ANTIALIASING_MODE gl_antialiasing_mode
VERTEX_MANAGER * nonCachedManager
Container for storing non-cached VERTEX_ITEMs.
Definition: opengl_gal.h:304
Auxiliary rendering target (noncached)
Definition: definitions.h:49
static int instanceCounter
GL GAL instance counter.
Definition: opengl_gal.h:292
void SetAntialiasingMode(OPENGL_ANTIALIASING_MODE aMode)
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()
Function Get returns the GL_CONTEXT_MANAGER instance (singleton).
GAL(GAL_DISPLAY_OPTIONS &aOptions)
void SetGridColor(const COLOR4D &aGridColor)
Set the grid color.
OPENGL_COMPOSITOR * compositor
Handles multiple rendering targets.
Definition: opengl_gal.h:308
#define NULL
unsigned int mainBuffer
Main rendering target.
Definition: opengl_gal.h:309
wxEvtHandler * mouseListener
Definition: opengl_gal.h:293
void SetAxesColor(const COLOR4D &aAxesColor)
Set the axes color.
static const int glAttributes[]
Definition: opengl_gal.cpp:79
void onPaint(wxPaintEvent &aEvent)
This is the OnPaint event handler.
GLint ufm_screenPixelSize
Definition: opengl_gal.h:326
bool isFramebufferInitialized
Are the framebuffers initialized?
Definition: opengl_gal.h:317
Class SHADER provides the access to the OpenGL shaders.
Definition: shader.h:76
GLUtesselator * tesselator
The tessellator.
Definition: opengl_gal.h:352
VERTEX_MANAGER * cachedManager
Container for storing cached VERTEX_ITEMs.
Definition: opengl_gal.h:303
GLint ufm_worldPixelSize
Definition: opengl_gal.h:325
wxEvtHandler * paintListener
Definition: opengl_gal.h:294
void SetTarget(RENDER_TARGET aTarget) override
Sets the target for rendering.
Definition: color4d.h:57
bool isInitialized
Basic initialization flag, has to be done when the window is visible.
Definition: opengl_gal.h:320
unsigned int groupCounter
Counter used for generating keys for groups.
Definition: opengl_gal.h:301
VECTOR2I screenSize
Screen size in screen coordinates.
wxGLContext * glPrivContext
Canvas-specific OpenGL context.
Definition: opengl_gal.h:291
wxGLContext * CreateCtx(wxGLCanvas *aCanvas, const wxGLContext *aOther=NULL)
Function CreateCtx creates a managed OpenGL context.
GLint ufm_pixelSizeMultiplier
Definition: opengl_gal.h:327
void skipMouseEvent(wxMouseEvent &aEvent)
Skip the mouse event to the parent.
COLOR4D is the color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:100

References bitmapCache, BLUE, compositor, GL_CONTEXT_MANAGER::CreateCtx(), GL_CONTEXT_MANAGER::Get(), HIDPI_GL_CANVAS::GetNativePixelSize(), KIGFX::GAL_DISPLAY_OPTIONS::gl_antialiasing_mode, glMainContext, glPrivContext, groupCounter, InitTesselatorCallbacks(), instanceCounter, isBitmapFontInitialized, isFramebufferInitialized, isGrouping, isInitialized, NULL, onPaint(), KIGFX::GAL::options, KIGFX::GAL::screenSize, KIGFX::OPENGL_COMPOSITOR::SetAntialiasingMode(), KIGFX::GAL::SetAxesColor(), KIGFX::GAL::SetGridColor(), SetTarget(), shader, skipMouseEvent(), KIGFX::TARGET_NONCACHED, tesselator, ufm_pixelSizeMultiplier, ufm_screenPixelSize, and ufm_worldPixelSize.

◆ ~OPENGL_GAL()

OPENGL_GAL::~OPENGL_GAL ( )

Definition at line 283 of file opengl_gal.cpp.

284 {
286 
287  --instanceCounter;
288  glFlush();
289  gluDeleteTess( tesselator );
290  ClearCache();
291 
292  delete compositor;
293 
294  if( isInitialized )
295  {
296  delete cachedManager;
297  delete nonCachedManager;
298  delete overlayManager;
299  }
300 
302 
303  // If it was the main context, then it will be deleted
304  // when the last OpenGL GAL instance is destroyed (a few lines below)
307 
308  delete shader;
309 
310  // Are we destroying the last GAL instance?
311  if( instanceCounter == 0 )
312  {
314 
315  if( isBitmapFontLoaded )
316  {
317  glDeleteTextures( 1, &fontTexture );
318  isBitmapFontLoaded = false;
319  }
320 
324  }
325 }
static wxGLContext * glMainContext
Parent OpenGL context.
Definition: opengl_gal.h:290
static GLuint fontTexture
Bitmap font texture handle (shared)
Definition: opengl_gal.h:296
VERTEX_MANAGER * overlayManager
Container for storing overlaid VERTEX_ITEMs.
Definition: opengl_gal.h:305
SHADER * shader
There is only one shader used for different objects.
Definition: opengl_gal.h:314
void UnlockCtx(wxGLContext *aContext)
Function UnlockCtx allows other canvases to bind an OpenGL context.
VERTEX_MANAGER * nonCachedManager
Container for storing non-cached VERTEX_ITEMs.
Definition: opengl_gal.h:304
static int instanceCounter
GL GAL instance counter.
Definition: opengl_gal.h:292
static GL_CONTEXT_MANAGER & Get()
Function Get returns the GL_CONTEXT_MANAGER instance (singleton).
OPENGL_COMPOSITOR * compositor
Handles multiple rendering targets.
Definition: opengl_gal.h:308
#define NULL
void ClearCache() override
Delete all data created during caching of graphic items.
GLUtesselator * tesselator
The tessellator.
Definition: opengl_gal.h:352
void LockCtx(wxGLContext *aContext, wxGLCanvas *aCanvas)
Function LockCtx sets a context as current and prevents other canvases from switching it.
VERTEX_MANAGER * cachedManager
Container for storing cached VERTEX_ITEMs.
Definition: opengl_gal.h:303
bool isInitialized
Basic initialization flag, has to be done when the window is visible.
Definition: opengl_gal.h:320
wxGLContext * glPrivContext
Canvas-specific OpenGL context.
Definition: opengl_gal.h:291
void DestroyCtx(wxGLContext *aContext)
Function DestroyCtx destroys a managed OpenGL context.
static bool isBitmapFontLoaded
Is the bitmap font texture loaded?
Definition: opengl_gal.h:318

References cachedManager, ClearCache(), compositor, GL_CONTEXT_MANAGER::DestroyCtx(), fontTexture, GL_CONTEXT_MANAGER::Get(), glMainContext, glPrivContext, instanceCounter, isBitmapFontLoaded, isInitialized, GL_CONTEXT_MANAGER::LockCtx(), nonCachedManager, NULL, overlayManager, shader, tesselator, and GL_CONTEXT_MANAGER::UnlockCtx().

Member Function Documentation

◆ AdvanceDepth()

void KIGFX::GAL::AdvanceDepth ( )
inlineinherited

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

Definition at line 992 of file graphics_abstraction_layer.h.

993  {
994  layerDepth -= 0.05;
995  }
double layerDepth
The actual layer depth.

References KIGFX::GAL::layerDepth.

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

◆ beginDrawing()

void OPENGL_GAL::beginDrawing ( )
overrideprivatevirtual

Reimplemented from KIGFX::GAL.

Definition at line 408 of file opengl_gal.cpp.

409 {
410 #ifdef __WXDEBUG__
411  PROF_COUNTER totalRealTime( "OPENGL_GAL::beginDrawing()", true );
412 #endif /* __WXDEBUG__ */
413 
414  wxASSERT_MSG( isContextLocked, "GAL_DRAWING_CONTEXT RAII object should have locked context. "
415  "Calling GAL::beginDrawing() directly is not allowed." );
416 
417  wxASSERT_MSG( IsVisible(), "GAL::beginDrawing() must not be entered when GAL is not visible. "
418  "Other drawing routines will expect everything to be initialized "
419  "which will not be the case." );
420 
421  if( !isInitialized )
422  init();
423 
424  // Set up the view port
425  glMatrixMode( GL_PROJECTION );
426  glLoadIdentity();
427 
428  // Create the screen transformation (Do the RH-LH conversion here)
429  glOrtho( 0, (GLint) screenSize.x, (GLsizei) screenSize.y, 0, -depthRange.x, -depthRange.y );
430 
432  {
433  // Prepare rendering target buffers
436  try
437  {
439  }
440  catch( const std::runtime_error& error )
441  {
442  wxLogVerbose( "Could not create a framebuffer for overlays.\n" );
443  overlayBuffer = 0;
444  }
446  }
447 
448  compositor->Begin();
449 
450  // Disable 2D Textures
451  glDisable( GL_TEXTURE_2D );
452 
453  glShadeModel( GL_FLAT );
454 
455  // Enable the depth buffer
456  glEnable( GL_DEPTH_TEST );
457  glDepthFunc( GL_LESS );
458 
459  // Setup blending, required for transparent objects
460  glEnable( GL_BLEND );
461  glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );
462 
463  glMatrixMode( GL_MODELVIEW );
464 
465  // Set up the world <-> screen transformation
467  GLdouble matrixData[16] = { 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1 };
468  matrixData[0] = worldScreenMatrix.m_data[0][0];
469  matrixData[1] = worldScreenMatrix.m_data[1][0];
470  matrixData[2] = worldScreenMatrix.m_data[2][0];
471  matrixData[4] = worldScreenMatrix.m_data[0][1];
472  matrixData[5] = worldScreenMatrix.m_data[1][1];
473  matrixData[6] = worldScreenMatrix.m_data[2][1];
474  matrixData[12] = worldScreenMatrix.m_data[0][2];
475  matrixData[13] = worldScreenMatrix.m_data[1][2];
476  matrixData[14] = worldScreenMatrix.m_data[2][2];
477  glLoadMatrixd( matrixData );
478 
479  // Set defaults
482 
483  // Remove all previously stored items
486 
490 
492  {
493  // Keep bitmap font texture always bound to the second texturing unit
494  const GLint FONT_TEXTURE_UNIT = 2;
495 
496  // Either load the font atlas to video memory, or simply bind it to a texture unit
497  if( !isBitmapFontLoaded )
498  {
499  glActiveTexture( GL_TEXTURE0 + FONT_TEXTURE_UNIT );
500  glGenTextures( 1, &fontTexture );
501  glBindTexture( GL_TEXTURE_2D, fontTexture );
502  glTexImage2D( GL_TEXTURE_2D, 0, GL_RGB8, font_image.width, font_image.height,
503  0, GL_RGB, GL_UNSIGNED_BYTE, font_image.pixels );
504  glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
505  glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
506  checkGlError( "loading bitmap font" );
507 
508  glActiveTexture( GL_TEXTURE0 );
509 
510  isBitmapFontLoaded = true;
511  }
512  else
513  {
514  glActiveTexture( GL_TEXTURE0 + FONT_TEXTURE_UNIT );
515  glBindTexture( GL_TEXTURE_2D, fontTexture );
516  glActiveTexture( GL_TEXTURE0 );
517  }
518 
519  // Set shader parameter
520  GLint ufm_fontTexture = shader->AddParameter( "fontTexture" );
521  GLint ufm_fontTextureWidth = shader->AddParameter( "fontTextureWidth" );
522  ufm_worldPixelSize = shader->AddParameter( "worldPixelSize" );
523  ufm_screenPixelSize = shader->AddParameter( "screenPixelSize" );
524  ufm_pixelSizeMultiplier = shader->AddParameter( "pixelSizeMultiplier" );
525 
526  shader->Use();
527  shader->SetParameter( ufm_fontTexture, (int) FONT_TEXTURE_UNIT );
528  shader->SetParameter( ufm_fontTextureWidth, (int) font_image.width );
529  shader->Deactivate();
530  checkGlError( "setting bitmap font sampler as shader parameter" );
531 
533  }
534 
535  shader->Use();
538  double pixelSizeMultiplier = compositor->GetAntialiasSupersamplingFactor();
539  shader->SetParameter( ufm_pixelSizeMultiplier, (float) pixelSizeMultiplier );
540  shader->Deactivate();
541 
542  // Something betreen BeginDrawing and EndDrawing seems to depend on
543  // this texture unit being active, but it does not assure it itself.
544  glActiveTexture( GL_TEXTURE0 );
545 
546  // Unbind buffers - set compositor for direct drawing
548 
549 #ifdef __WXDEBUG__
550  totalRealTime.Stop();
551  wxLogTrace( "GAL_PROFILE", wxT( "OPENGL_GAL::beginDrawing(): %.1f ms" ), totalRealTime.msecs() );
552 #endif /* __WXDEBUG__ */
553 }
virtual void SetFillColor(const COLOR4D &aColor)
Set the fill color.
int GetAntialiasSupersamplingFactor() const
unsigned int overlayBuffer
Auxiliary rendering target (for menus etc.)
Definition: opengl_gal.h:310
virtual void Begin() override
Function Begin() Call this at the beginning of each frame.
void BeginDrawing() const
Function BeginDrawing() prepares buffers and items to start drawing.
bool isBitmapFontInitialized
Is the shader set to use bitmap fonts?
Definition: opengl_gal.h:319
void Use()
Use the shader.
Definition: shader.h:132
static GLuint fontTexture
Bitmap font texture handle (shared)
Definition: opengl_gal.h:296
VERTEX_MANAGER * overlayManager
Container for storing overlaid VERTEX_ITEMs.
Definition: opengl_gal.h:305
VECTOR2D getScreenPixelSize() const
Definition: opengl_gal.cpp:401
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:139
double GetScaleFactor() const
Get the current scale factor.
bool isContextLocked
Used for assertion checking.
Definition: opengl_gal.h:323
COLOR4D fillColor
The fill color.
VECTOR2D depthRange
Range of the depth.
int checkGlError(const std::string &aInfo, bool aThrow)
Checks if one of recent OpenGL operations has failed.
Definition: utils.cpp:32
SHADER * shader
There is only one shader used for different objects.
Definition: opengl_gal.h:314
static const unsigned int DIRECT_RENDERING
The class PROF_COUNTER is a small class to help profiling.
Definition: profile.h:44
VERTEX_MANAGER * nonCachedManager
Container for storing non-cached VERTEX_ITEMs.
Definition: opengl_gal.h:304
T m_data[3][3]
Definition: matrix3x3.h:64
double getWorldPixelSize() const
Definition: opengl_gal.cpp:394
void init()
Basic OpenGL initialization and feature checks.
OPENGL_COMPOSITOR * compositor
Handles multiple rendering targets.
Definition: opengl_gal.h:308
unsigned int mainBuffer
Main rendering target.
Definition: opengl_gal.h:309
COLOR4D strokeColor
The color of the outlines.
int AddParameter(const std::string &aParameterName)
Add a parameter to the parameter queue.
Definition: shader.cpp:126
GLint ufm_screenPixelSize
Definition: opengl_gal.h:326
void Deactivate()
Deactivate the shader and use the default OpenGL program.
Definition: shader.h:141
bool isFramebufferInitialized
Are the framebuffers initialized?
Definition: opengl_gal.h:317
FONT_IMAGE_TYPE font_image
Definition: gl_resources.cpp:4
unsigned char pixels[1024 *1024 *3]
Definition: gl_resources.h:38
MATRIX3x3D worldScreenMatrix
World transformation.
virtual void SetBuffer(unsigned int aBufferHandle) override
Function SetBuffer() sets the selected buffer as the rendering target.
VERTEX_MANAGER * cachedManager
Container for storing cached VERTEX_ITEMs.
Definition: opengl_gal.h:303
virtual void Initialize() override
Function Reset() performs primary initialiation, necessary to use the object.
GLint ufm_worldPixelSize
Definition: opengl_gal.h:325
virtual void SetStrokeColor(const COLOR4D &aColor)
Set the stroke color.
bool isInitialized
Basic initialization flag, has to be done when the window is visible.
Definition: opengl_gal.h:320
VECTOR2I screenSize
Screen size in screen coordinates.
virtual unsigned int CreateBuffer() override
Function CreateBuffer() prepares a new buffer that may be used as a rendering target.
bool IsVisible() const override
Definition: opengl_gal.h:106
GLint ufm_pixelSizeMultiplier
Definition: opengl_gal.h:327
void Clear() const
Function Clear() removes all the stored vertices from the container.
static bool isBitmapFontLoaded
Is the bitmap font texture loaded?
Definition: opengl_gal.h:318

References KIGFX::SHADER::AddParameter(), KIGFX::OPENGL_COMPOSITOR::Begin(), KIGFX::VERTEX_MANAGER::BeginDrawing(), cachedManager, checkGlError(), KIGFX::VERTEX_MANAGER::Clear(), compositor, ComputeWorldScreenMatrix(), KIGFX::OPENGL_COMPOSITOR::CreateBuffer(), KIGFX::SHADER::Deactivate(), KIGFX::GAL::depthRange, KIGFX::OPENGL_COMPOSITOR::DIRECT_RENDERING, KIGFX::GAL::fillColor, KIGFX::BUILTIN_FONT::font_image, fontTexture, KIGFX::OPENGL_COMPOSITOR::GetAntialiasSupersamplingFactor(), HIDPI_GL_CANVAS::GetScaleFactor(), getScreenPixelSize(), getWorldPixelSize(), KIGFX::BUILTIN_FONT::FONT_IMAGE_TYPE::height, init(), KIGFX::OPENGL_COMPOSITOR::Initialize(), isBitmapFontInitialized, isBitmapFontLoaded, isContextLocked, isFramebufferInitialized, isInitialized, IsVisible(), MATRIX3x3< T >::m_data, mainBuffer, PROF_COUNTER::msecs(), nonCachedManager, overlayBuffer, overlayManager, KIGFX::BUILTIN_FONT::FONT_IMAGE_TYPE::pixels, KIGFX::GAL::screenSize, KIGFX::OPENGL_COMPOSITOR::SetBuffer(), KIGFX::GAL::SetFillColor(), KIGFX::SHADER::SetParameter(), KIGFX::GAL::SetStrokeColor(), shader, PROF_COUNTER::Stop(), KIGFX::GAL::strokeColor, ufm_pixelSizeMultiplier, ufm_screenPixelSize, ufm_worldPixelSize, KIGFX::SHADER::Use(), KIGFX::BUILTIN_FONT::FONT_IMAGE_TYPE::width, KIGFX::GAL::worldScreenMatrix, 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 1569 of file opengl_gal.cpp.

1570 {
1571  isGrouping = true;
1572 
1573  std::shared_ptr<VERTEX_ITEM> newItem = std::make_shared<VERTEX_ITEM>( *cachedManager );
1574  int groupNumber = getNewGroupNumber();
1575  groups.insert( std::make_pair( groupNumber, newItem ) );
1576 
1577  return groupNumber;
1578 }
bool isGrouping
Was a group started?
Definition: opengl_gal.h:322
GROUPS_MAP groups
Stores informations about VBO objects (groups)
Definition: opengl_gal.h:300
VERTEX_MANAGER * cachedManager
Container for storing cached VERTEX_ITEMs.
Definition: opengl_gal.h:303
unsigned int getNewGroupNumber()
Returns a valid key that can be used as a new group number.

References cachedManager, getNewGroupNumber(), groups, and isGrouping.

◆ beginUpdate()

void OPENGL_GAL::beginUpdate ( )
overrideprivatevirtual

Reimplemented from KIGFX::GAL.

Definition at line 619 of file opengl_gal.cpp.

620 {
621  wxASSERT_MSG( isContextLocked, "GAL_UPDATE_CONTEXT RAII object should have locked context. "
622  "Calling this from anywhere else is not allowed." );
623 
624  wxASSERT_MSG( IsVisible(), "GAL::beginUpdate() must not be entered when GAL is not visible. "
625  "Other update routines will expect everything to be initialized "
626  "which will not be the case." );
627 
628  if( !isInitialized )
629  init();
630 
631  cachedManager->Map();
632 }
bool isContextLocked
Used for assertion checking.
Definition: opengl_gal.h:323
void init()
Basic OpenGL initialization and feature checks.
void Map()
Function Map() maps vertex buffer.
VERTEX_MANAGER * cachedManager
Container for storing cached VERTEX_ITEMs.
Definition: opengl_gal.h:303
bool isInitialized
Basic initialization flag, has to be done when the window is visible.
Definition: opengl_gal.h:320
bool IsVisible() const override
Definition: opengl_gal.h:106

References cachedManager, init(), isContextLocked, isInitialized, IsVisible(), and KIGFX::VERTEX_MANAGER::Map().

◆ BitmapText()

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

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

1209 {
1210  wxASSERT_MSG( !IsTextMirrored(), "No support for mirrored text using bitmap fonts." );
1211 
1212  const UTF8 text( aText );
1213  // Compute text size, so it can be properly justified
1214  VECTOR2D textSize;
1215  float commonOffset;
1216  std::tie( textSize, commonOffset ) = computeBitmapTextSize( text );
1217 
1218  const double SCALE = 1.4 * GetGlyphSize().y / textSize.y;
1219  bool overbar = false;
1220 
1221  int overbarLength = 0;
1222  double overbarHeight = textSize.y;
1223 
1224  Save();
1225 
1227  currentManager->Translate( aPosition.x, aPosition.y, layerDepth );
1228  currentManager->Rotate( aRotationAngle, 0.0f, 0.0f, -1.0f );
1229 
1230  double sx = SCALE * ( globalFlipX ? -1.0 : 1.0 );
1231  double sy = SCALE * ( globalFlipY ? -1.0 : 1.0 );
1232 
1233  currentManager->Scale( sx, sy, 0 );
1234  currentManager->Translate( 0, -commonOffset, 0 );
1235 
1236  switch( GetHorizontalJustify() )
1237  {
1239  Translate( VECTOR2D( -textSize.x / 2.0, 0 ) );
1240  break;
1241 
1243  //if( !IsTextMirrored() )
1244  Translate( VECTOR2D( -textSize.x, 0 ) );
1245  break;
1246 
1247  case GR_TEXT_HJUSTIFY_LEFT:
1248  //if( IsTextMirrored() )
1249  //Translate( VECTOR2D( -textSize.x, 0 ) );
1250  break;
1251  }
1252 
1253  switch( GetVerticalJustify() )
1254  {
1255  case GR_TEXT_VJUSTIFY_TOP:
1256  Translate( VECTOR2D( 0, -textSize.y ) );
1257  overbarHeight = -textSize.y / 2.0;
1258  break;
1259 
1261  Translate( VECTOR2D( 0, -textSize.y / 2.0 ) );
1262  overbarHeight = 0;
1263  break;
1264 
1266  break;
1267  }
1268 
1269  int i = 0;
1270 
1271  for( UTF8::uni_iter chIt = text.ubegin(), end = text.uend(); chIt < end; ++chIt )
1272  {
1273  unsigned int c = *chIt;
1274  wxASSERT_MSG( c != '\n' && c != '\r', wxT( "No support for multiline bitmap text yet" ) );
1275 
1276  bool wasOverbar = overbar;
1277 
1278  if( c == '~' )
1279  {
1280  if( ++chIt == end )
1281  break;
1282 
1283  c = *chIt;
1284 
1285  if( c == '~' )
1286  {
1287  // double ~ is really a ~ so go ahead and process the second one
1288 
1289  // so what's a triple ~? It could be a real ~ followed by an overbar, or
1290  // it could be an overbar followed by a real ~. The old algorithm did the
1291  // former so we will too....
1292  }
1293  else
1294  {
1295  overbar = !overbar;
1296  }
1297  }
1298 
1299  if( wasOverbar && !overbar )
1300  {
1301  drawBitmapOverbar( overbarLength, overbarHeight );
1302  overbarLength = 0;
1303  }
1304 
1305  if( overbar )
1306  overbarLength += drawBitmapChar( c );
1307  else
1308  drawBitmapChar( c );
1309 
1310  ++i;
1311  }
1312 
1313  // Handle the case when overbar is active till the end of the drawn text
1314  currentManager->Translate( 0, commonOffset, 0 );
1315 
1316  if( overbar && overbarLength > 0 )
1317  drawBitmapOverbar( overbarLength, overbarHeight );
1318 
1319  Restore();
1320 }
UTF8 is an 8 bit string that is assuredly encoded in UTF8, and supplies special conversion support to...
Definition: utf8.h:73
VERTEX_MANAGER * currentManager
Currently used VERTEX_MANAGER (for storing VERTEX_ITEMs)
Definition: opengl_gal.h:302
double layerDepth
The actual layer depth.
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)
Function Rotate() multiplies the current matrix by a rotation matrix, so the newly vertices will be r...
double g
Green component.
Definition: color4d.h:375
bool globalFlipX
Flag for X axis flipping.
EDA_TEXT_HJUSTIFY_T GetHorizontalJustify() const
Returns current text horizontal justification setting.
double b
Blue component.
Definition: color4d.h:376
const VECTOR2D & GetGlyphSize() const
void Save() override
Save the context.
double a
Alpha component.
Definition: color4d.h:377
VECTOR2< double > VECTOR2D
Definition: vector2d.h:593
COLOR4D strokeColor
The color of the outlines.
void Translate(GLfloat aX, GLfloat aY, GLfloat aZ)
Function Translate() multiplies the current matrix by a translation matrix, so newly vertices will be...
void Color(const COLOR4D &aColor)
Function Color() 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:207
bool globalFlipY
Flag for Y axis flipping.
EDA_TEXT_VJUSTIFY_T GetVerticalJustify() const
Returns current text vertical justification setting.
int drawBitmapChar(unsigned long aChar)
Draws a single character using bitmap font.
void Scale(GLfloat aX, GLfloat aY, GLfloat aZ)
Function Scale() multiplies the current matrix by a scaling matrix, so the newly vertices will be sca...
double r
Red component.
Definition: color4d.h:374
std::pair< VECTOR2D, float > computeBitmapTextSize(const UTF8 &aText) const
Computes a size of text drawn using bitmap font with current text setting applied.
void drawBitmapOverbar(double aLength, double aHeight)
Draws an overbar over the currently drawn text.

References KIGFX::COLOR4D::a, KIGFX::COLOR4D::b, KIGFX::VERTEX_MANAGER::Color(), computeBitmapTextSize(), currentManager, drawBitmapChar(), drawBitmapOverbar(), KIGFX::COLOR4D::g, KIGFX::GAL::GetGlyphSize(), KIGFX::GAL::GetHorizontalJustify(), KIGFX::GAL::GetVerticalJustify(), KIGFX::GAL::globalFlipX, KIGFX::GAL::globalFlipY, 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(), KIGFX::GAL::layerDepth, KIGFX::COLOR4D::r, Restore(), KIGFX::VERTEX_MANAGER::Rotate(), Save(), KIGFX::VERTEX_MANAGER::Scale(), KIGFX::GAL::strokeColor, Translate(), KIGFX::VERTEX_MANAGER::Translate(), UTF8::ubegin(), UTF8::uend(), VECTOR2< T >::x, and VECTOR2< T >::y.

◆ blitCursor()

void OPENGL_GAL::blitCursor ( )
private

Blits cursor into the current screen.

Definition at line 2045 of file opengl_gal.cpp.

2046 {
2047  if( !IsCursorEnabled() )
2048  return;
2049 
2051 
2052  const int cursorSize = fullscreenCursor ? 8000 : 80;
2053 
2054  VECTOR2D cursorBegin = cursorPosition - cursorSize / ( 2 * worldScale );
2055  VECTOR2D cursorEnd = cursorPosition + cursorSize / ( 2 * worldScale );
2056  VECTOR2D cursorCenter = ( cursorBegin + cursorEnd ) / 2;
2057 
2058  const COLOR4D cColor = getCursorColor();
2059  const COLOR4D color( cColor.r * cColor.a, cColor.g * cColor.a,
2060  cColor.b * cColor.a, 1.0 );
2061 
2062  glActiveTexture( GL_TEXTURE0 );
2063  glDisable( GL_TEXTURE_2D );
2064  glLineWidth( 1.0 );
2065  glColor4d( color.r, color.g, color.b, color.a );
2066 
2067  glBegin( GL_LINES );
2068  glVertex2d( cursorCenter.x, cursorBegin.y );
2069  glVertex2d( cursorCenter.x, cursorEnd.y );
2070 
2071  glVertex2d( cursorBegin.x, cursorCenter.y );
2072  glVertex2d( cursorEnd.x, cursorCenter.y );
2073  glEnd();
2074 }
VECTOR2D cursorPosition
Current cursor position (world coordinates)
int color
Definition: DXF_plotter.cpp:60
double g
Green component.
Definition: color4d.h:375
static const unsigned int DIRECT_RENDERING
double b
Blue component.
Definition: color4d.h:376
double a
Alpha component.
Definition: color4d.h:377
OPENGL_COMPOSITOR * compositor
Handles multiple rendering targets.
Definition: opengl_gal.h:308
bool fullscreenCursor
Shape of the cursor (fullscreen or small cross)
virtual void SetBuffer(unsigned int aBufferHandle) override
Function SetBuffer() sets the selected buffer as the rendering target.
COLOR4D getCursorColor() const
Gets the actual cursor color to draw.
double worldScale
The scale factor world->screen.
double r
Red component.
Definition: color4d.h:374
bool IsCursorEnabled() const
Returns information about cursor visibility.
COLOR4D is the color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:100

References KIGFX::COLOR4D::a, KIGFX::COLOR4D::b, color, compositor, KIGFX::GAL::cursorPosition, KIGFX::OPENGL_COMPOSITOR::DIRECT_RENDERING, KIGFX::GAL::fullscreenCursor, KIGFX::COLOR4D::g, KIGFX::GAL::getCursorColor(), KIGFX::GAL::IsCursorEnabled(), KIGFX::COLOR4D::r, KIGFX::OPENGL_COMPOSITOR::SetBuffer(), KIGFX::GAL::worldScale, 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 475 of file opengl_gal.h.

476  {
477  // Bigger arcs need smaller alpha increment to make them look smooth
478  return std::min( 1e6 / aRadius, 2.0 * M_PI / CIRCLE_POINTS );
479  }
CIRCLE_POINTS

Referenced by DrawArc(), and DrawArcSegment().

◆ ChangeGroupColor()

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

Changes the color used to draw the group.

Parameters
aGroupNumberis the group number.
aNewColoris the new color.

Reimplemented from KIGFX::GAL.

Definition at line 1595 of file opengl_gal.cpp.

1596 {
1597  if( groups[aGroupNumber] )
1598  cachedManager->ChangeItemColor( *groups[aGroupNumber], aNewColor );
1599 }
GROUPS_MAP groups
Stores informations about VBO objects (groups)
Definition: opengl_gal.h:300
VERTEX_MANAGER * cachedManager
Container for storing cached VERTEX_ITEMs.
Definition: opengl_gal.h:303
void ChangeItemColor(const VERTEX_ITEM &aItem, const COLOR4D &aColor) const
Function ChangeItemColor() changes the color of all vertices owned by an item.

References cachedManager, KIGFX::VERTEX_MANAGER::ChangeItemColor(), and groups.

◆ ChangeGroupDepth()

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

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

Parameters
aGroupNumberis the group number.
aDepthis the new depth.

Reimplemented from KIGFX::GAL.

Definition at line 1602 of file opengl_gal.cpp.

1603 {
1604  if( groups[aGroupNumber] )
1605  cachedManager->ChangeItemDepth( *groups[aGroupNumber], aDepth );
1606 }
void ChangeItemDepth(const VERTEX_ITEM &aItem, GLfloat aDepth) const
Function ChangeItemDepth() changes the depth of all vertices owned by an item.
GROUPS_MAP groups
Stores informations about VBO objects (groups)
Definition: opengl_gal.h:300
VERTEX_MANAGER * cachedManager
Container for storing cached VERTEX_ITEMs.
Definition: opengl_gal.h:303

References cachedManager, KIGFX::VERTEX_MANAGER::ChangeItemDepth(), and 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 328 of file opengl_gal.cpp.

329 {
330  wxFrame* testFrame = new wxFrame( NULL, wxID_ANY, wxT( "" ), wxDefaultPosition, wxSize( 1, 1 ),
331  wxFRAME_TOOL_WINDOW | wxNO_BORDER );
332  KIGFX::OPENGL_GAL* opengl_gal = new KIGFX::OPENGL_GAL( aOptions, testFrame );
333 
334  testFrame->Raise();
335  testFrame->Show();
336 
337  try
338  {
339  GAL_CONTEXT_LOCKER lock( opengl_gal );
340  opengl_gal->init();
341  }
342  catch( std::runtime_error& err )
343  {
344  //Test failed
345  delete opengl_gal;
346  delete testFrame;
347  return wxString( err.what() );
348  }
349 
350  //Test passed
351  delete opengl_gal;
352  delete testFrame;
353  return wxEmptyString;
354 }
Class OpenGL_GAL is the OpenGL implementation of the Graphics Abstraction Layer.
Definition: opengl_gal.h:65
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 1616 of file opengl_gal.cpp.

1617 {
1618  bitmapCache = std::make_unique<GL_BITMAP_CACHE>( );
1619 
1620  groups.clear();
1621 
1622  if( isInitialized )
1623  cachedManager->Clear();
1624 }
std::unique_ptr< GL_BITMAP_CACHE > bitmapCache
Definition: opengl_gal.h:329
GROUPS_MAP groups
Stores informations about VBO objects (groups)
Definition: opengl_gal.h:300
VERTEX_MANAGER * cachedManager
Container for storing cached VERTEX_ITEMs.
Definition: opengl_gal.h:303
bool isInitialized
Basic initialization flag, has to be done when the window is visible.
Definition: opengl_gal.h:320
void Clear() const
Function Clear() removes all the stored vertices from the container.

References bitmapCache, cachedManager, KIGFX::VERTEX_MANAGER::Clear(), groups, and 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 1511 of file opengl_gal.cpp.

1512 {
1513  // Clear screen
1515  // NOTE: Black used here instead of m_clearColor; it will be composited later
1516  glClearColor( 0, 0, 0, 1 );
1517  glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT );
1518 }
static const unsigned int DIRECT_RENDERING
OPENGL_COMPOSITOR * compositor
Handles multiple rendering targets.
Definition: opengl_gal.h:308
virtual void SetBuffer(unsigned int aBufferHandle) override
Function SetBuffer() sets the selected buffer as the rendering target.

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

◆ ClearTarget()

void OPENGL_GAL::ClearTarget ( RENDER_TARGET  aTarget)
overridevirtual

Clears the target for rendering.

Parameters
aTargetis the target to be cleared.

Reimplemented from KIGFX::GAL.

Definition at line 1655 of file opengl_gal.cpp.

1656 {
1657  // Save the current state
1658  unsigned int oldTarget = compositor->GetBuffer();
1659 
1660  switch( aTarget )
1661  {
1662  // Cached and noncached items are rendered to the same buffer
1663  default:
1664  case TARGET_CACHED:
1665  case TARGET_NONCACHED:
1667  break;
1668 
1669  case TARGET_OVERLAY:
1670  if( overlayBuffer )
1672  break;
1673  }
1674 
1675 
1676  if( aTarget != TARGET_OVERLAY )
1678  else if( overlayBuffer )
1680 
1681  // Restore the previous state
1682  compositor->SetBuffer( oldTarget );
1683 }
unsigned int overlayBuffer
Auxiliary rendering target (for menus etc.)
Definition: opengl_gal.h:310
Auxiliary rendering target (noncached)
Definition: definitions.h:49
static const COLOR4D BLACK
Definition: color4d.h:384
OPENGL_COMPOSITOR * compositor
Handles multiple rendering targets.
Definition: opengl_gal.h:308
unsigned int mainBuffer
Main rendering target.
Definition: opengl_gal.h:309
virtual void ClearBuffer(const COLOR4D &aColor) override
Function ClearBuffer() clears the selected buffer (set by the SetBuffer() function).
Items that may change while the view stays the same (noncached)
Definition: definitions.h:50
virtual void SetBuffer(unsigned int aBufferHandle) override
Function SetBuffer() sets the selected buffer as the rendering target.
Main rendering target (cached)
Definition: definitions.h:48
virtual unsigned int GetBuffer() const override
Function GetBuffer() returns currently used buffer handle.

References KIGFX::COLOR4D::BLACK, KIGFX::OPENGL_COMPOSITOR::ClearBuffer(), compositor, KIGFX::OPENGL_COMPOSITOR::GetBuffer(), KIGFX::GAL::m_clearColor, mainBuffer, 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

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

1996 {
1997  VECTOR2D textSize( 0, 0 );
1998  float commonOffset = std::numeric_limits<float>::max();
1999  static const auto defaultGlyph = LookupGlyph( '(' ); // for strange chars
2000 
2001  for( UTF8::uni_iter chIt = aText.ubegin(), end = aText.uend(); chIt < end; ++chIt )
2002  {
2003  unsigned int c = *chIt;
2004 
2005  const FONT_GLYPH_TYPE* glyph = LookupGlyph( c );
2006  // Debug: show not coded char in the atlas
2007  // Be carefull before allowing the assert: it usually crash kicad
2008  // when the assert is made during a paint event.
2009  // wxASSERT_MSG( glyph, wxString::Format( "missing char in font: code 0x%x <%c>", c, c ) );
2010 
2011  if( !glyph || // Not coded in font
2012  c == '-' || c == '_' ) // Strange size of these 2 chars
2013  {
2014  glyph = defaultGlyph;
2015  }
2016 
2017  if( glyph )
2018  {
2019  textSize.x += glyph->advance;
2020  }
2021  }
2022 
2023  textSize.y = std::max<float>( textSize.y, font_information.max_y - defaultGlyph->miny );
2024  commonOffset = std::min<float>( font_information.max_y - defaultGlyph->maxy, commonOffset );
2025  textSize.y -= commonOffset;
2026 
2027  return std::make_pair( textSize, commonOffset );
2028 }
uni_iter uend() const
Function uend returns a uni_iter initialized to the end of "this" UTF8 byte sequence.
Definition: utf8.h:294
const FONT_GLYPH_TYPE * LookupGlyph(unsigned int aCodepoint)
uni_iter ubegin() const
Function ubegin returns a uni_iter initialized to the start of "this" UTF8 byte sequence.
Definition: utf8.h:285
FONT_INFO_TYPE font_information
Definition: gl_resources.cpp:3
uni_iter is a non-mutating iterator that walks through unicode code points in the UTF8 encoded string...
Definition: utf8.h:207

References KIGFX::BUILTIN_FONT::FONT_GLYPH_TYPE::advance, KIGFX::BUILTIN_FONT::font_information, KIGFX::BUILTIN_FONT::LookupGlyph(), KIGFX::BUILTIN_FONT::FONT_INFO_TYPE::max_y, 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 212 of file graphics_abstraction_layer.cpp.

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

References KIGFX::GAL::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 1094 of file graphics_abstraction_layer.h.

1095  {
1097  }
double zoomFactor
The zoom factor.
double worldUnitLength
The unit length of the world coordinates [inch].
double worldScale
The scale factor world->screen.
double screenDPI
The dots per inch of the screen.

References KIGFX::GAL::screenDPI, KIGFX::GAL::worldScale, KIGFX::GAL::worldUnitLength, and KIGFX::GAL::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 2241 of file opengl_gal.cpp.

2242 {
2243  auto pixelSize = worldScale;
2244 
2245  lookAtPoint.x = roundr( lookAtPoint.x, pixelSize );
2246  lookAtPoint.y = roundr( lookAtPoint.y, pixelSize );
2247 
2249 }
virtual void ComputeWorldScreenMatrix()
Compute the world <-> screen transformation matrix.
VECTOR2D lookAtPoint
Point to be looked at in world space.
double worldScale
The scale factor world->screen.
static double roundr(double f, double r)

References KIGFX::GAL::ComputeWorldScreenMatrix(), KIGFX::GAL::lookAtPoint, roundr(), KIGFX::GAL::worldScale, 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 1609 of file opengl_gal.cpp.

1610 {
1611  // Frees memory in the container as well
1612  groups.erase( aGroupNumber );
1613 }
GROUPS_MAP groups
Stores informations about VBO objects (groups)
Definition: opengl_gal.h:300

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

765 {
766  if( aRadius <= 0 )
767  return;
768 
769  // Swap the angles, if start angle is greater than end angle
770  SWAP( aStartAngle, >, aEndAngle );
771 
772  const double alphaIncrement = calcAngleStep( aRadius );
773 
774  Save();
775  currentManager->Translate( aCenterPoint.x, aCenterPoint.y, 0.0 );
776 
777  if( isFillEnabled )
778  {
779  double alpha;
782 
783  // Triangle fan
784  for( alpha = aStartAngle; ( alpha + alphaIncrement ) < aEndAngle; )
785  {
786  currentManager->Reserve( 3 );
787  currentManager->Vertex( 0.0, 0.0, layerDepth );
788  currentManager->Vertex( cos( alpha ) * aRadius, sin( alpha ) * aRadius, layerDepth );
789  alpha += alphaIncrement;
790  currentManager->Vertex( cos( alpha ) * aRadius, sin( alpha ) * aRadius, layerDepth );
791  }
792 
793  // The last missing triangle
794  const VECTOR2D endPoint( cos( aEndAngle ) * aRadius, sin( aEndAngle ) * aRadius );
795 
796  currentManager->Reserve( 3 );
797  currentManager->Vertex( 0.0, 0.0, layerDepth );
798  currentManager->Vertex( cos( alpha ) * aRadius, sin( alpha ) * aRadius, layerDepth );
799  currentManager->Vertex( endPoint.x, endPoint.y, layerDepth );
800  }
801 
802  if( isStrokeEnabled )
803  {
805 
806  VECTOR2D p( cos( aStartAngle ) * aRadius, sin( aStartAngle ) * aRadius );
807  double alpha;
808 
809  for( alpha = aStartAngle + alphaIncrement; alpha <= aEndAngle; alpha += alphaIncrement )
810  {
811  VECTOR2D p_next( cos( alpha ) * aRadius, sin( alpha ) * aRadius );
812  DrawLine( p, p_next );
813 
814  p = p_next;
815  }
816 
817  // Draw the last missing part
818  if( alpha != aEndAngle )
819  {
820  VECTOR2D p_last( cos( aEndAngle ) * aRadius, sin( aEndAngle ) * aRadius );
821  DrawLine( p, p_last );
822  }
823  }
824 
825  Restore();
826 }
VERTEX_MANAGER * currentManager
Currently used VERTEX_MANAGER (for storing VERTEX_ITEMs)
Definition: opengl_gal.h:302
double layerDepth
The actual layer depth.
bool Reserve(unsigned int aSize)
Function Reserve() allocates space for vertices, so it will be used with subsequent Vertex() calls.
void Restore() override
Restore the context.
bool Vertex(const VERTEX &aVertex)
Function Vertex() adds a vertex with the given coordinates to the currently set item.
double g
Green component.
Definition: color4d.h:375
COLOR4D fillColor
The fill color.
double b
Blue component.
Definition: color4d.h:376
void Save() override
Save the context.
double a
Alpha component.
Definition: color4d.h:377
bool isStrokeEnabled
Are the outlines stroked ?
double calcAngleStep(double aRadius) const
Compute the angle step when drawing arcs/circles approximated with lines.
Definition: opengl_gal.h:475
COLOR4D strokeColor
The color of the outlines.
void Translate(GLfloat aX, GLfloat aY, GLfloat aZ)
Function Translate() multiplies the current matrix by a translation matrix, so newly vertices will be...
void DrawLine(const VECTOR2D &aStartPoint, const VECTOR2D &aEndPoint) override
Draw a line.
Definition: opengl_gal.cpp:644
void Color(const COLOR4D &aColor)
Function Color() changes currently used color that will be applied to newly added vertices.
bool isFillEnabled
Is filling of graphic objects enabled ?
#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)
Function Shader() changes currently used shader and its parameters that will be applied to newly adde...
double r
Red component.
Definition: color4d.h:374

References KIGFX::COLOR4D::a, KIGFX::COLOR4D::b, calcAngleStep(), KIGFX::VERTEX_MANAGER::Color(), currentManager, DrawLine(), KIGFX::GAL::fillColor, KIGFX::COLOR4D::g, KIGFX::GAL::isFillEnabled, KIGFX::GAL::isStrokeEnabled, KIGFX::GAL::layerDepth, KIGFX::COLOR4D::r, KIGFX::VERTEX_MANAGER::Reserve(), Restore(), Save(), KIGFX::VERTEX_MANAGER::Shader(), KIGFX::SHADER_NONE, KIGFX::GAL::strokeColor, 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 829 of file opengl_gal.cpp.

831 {
832  if( aRadius <= 0 )
833  {
834  // Arcs of zero radius are a circle of aWidth diameter
835  if( aWidth > 0 )
836  DrawCircle( aCenterPoint, aWidth / 2.0 );
837 
838  return;
839  }
840 
841  // Swap the angles, if start angle is greater than end angle
842  SWAP( aStartAngle, >, aEndAngle );
843 
844  double alphaIncrement = calcAngleStep( aRadius );
845 
846  // Refinement: Use a segment count multiple of 2, because we have a control point
847  // on the middle of the arc, and the look is better if it is on a segment junction
848  // because there is no approx error
849  int seg_count = KiROUND( (aEndAngle -aStartAngle ) / alphaIncrement );
850 
851  if( seg_count %2 != 0 )
852  seg_count += 1;
853 
854  // Recalculate alphaIncrement with a even integer number of segment
855  alphaIncrement = (aEndAngle -aStartAngle ) / seg_count;
856 
857  Save();
858  currentManager->Translate( aCenterPoint.x, aCenterPoint.y, 0.0 );
859 
860  if( isStrokeEnabled )
861  {
863 
864  double width = aWidth / 2.0;
865  VECTOR2D startPoint( cos( aStartAngle ) * aRadius,
866  sin( aStartAngle ) * aRadius );
867  VECTOR2D endPoint( cos( aEndAngle ) * aRadius,
868  sin( aEndAngle ) * aRadius );
869 
870  drawStrokedSemiCircle( startPoint, width, aStartAngle + M_PI );
871  drawStrokedSemiCircle( endPoint, width, aEndAngle );
872 
873  VECTOR2D pOuter( cos( aStartAngle ) * ( aRadius + width ),
874  sin( aStartAngle ) * ( aRadius + width ) );
875 
876  VECTOR2D pInner( cos( aStartAngle ) * ( aRadius - width ),
877  sin( aStartAngle ) * ( aRadius - width ) );
878 
879  double alpha;
880 
881  for( alpha = aStartAngle + alphaIncrement; alpha <= aEndAngle; alpha += alphaIncrement )
882  {
883  VECTOR2D pNextOuter( cos( alpha ) * ( aRadius + width ),
884  sin( alpha ) * ( aRadius + width ) );
885  VECTOR2D pNextInner( cos( alpha ) * ( aRadius - width ),
886  sin( alpha ) * ( aRadius - width ) );
887 
888  DrawLine( pOuter, pNextOuter );
889  DrawLine( pInner, pNextInner );
890 
891  pOuter = pNextOuter;
892  pInner = pNextInner;
893  }
894 
895  // Draw the last missing part
896  if( alpha != aEndAngle )
897  {
898  VECTOR2D pLastOuter( cos( aEndAngle ) * ( aRadius + width ),
899  sin( aEndAngle ) * ( aRadius + width ) );
900  VECTOR2D pLastInner( cos( aEndAngle ) * ( aRadius - width ),
901  sin( aEndAngle ) * ( aRadius - width ) );
902 
903  DrawLine( pOuter, pLastOuter );
904  DrawLine( pInner, pLastInner );
905  }
906  }
907 
908  if( isFillEnabled )
909  {
911  SetLineWidth( aWidth );
912 
913  VECTOR2D p( cos( aStartAngle ) * aRadius, sin( aStartAngle ) * aRadius );
914  double alpha;
915 
916  for( alpha = aStartAngle + alphaIncrement; alpha <= aEndAngle; alpha += alphaIncrement )
917  {
918  VECTOR2D p_next( cos( alpha ) * aRadius, sin( alpha ) * aRadius );
919  DrawLine( p, p_next );
920 
921  p = p_next;
922  }
923 
924  // Draw the last missing part
925  if( alpha != aEndAngle )
926  {
927  VECTOR2D p_last( cos( aEndAngle ) * aRadius, sin( aEndAngle ) * aRadius );
928  DrawLine( p, p_last );
929  }
930  }
931 
932  Restore();
933 }
VERTEX_MANAGER * currentManager
Currently used VERTEX_MANAGER (for storing VERTEX_ITEMs)
Definition: opengl_gal.h:302
void Restore() override
Restore the context.
double g
Green component.
Definition: color4d.h:375
COLOR4D fillColor
The fill color.
virtual void SetLineWidth(float aLineWidth)
Set the line width.
double b
Blue component.
Definition: color4d.h:376
void Save() override
Save the context.
double a
Alpha component.
Definition: color4d.h:377
bool isStrokeEnabled
Are the outlines stroked ?
double calcAngleStep(double aRadius) const
Compute the angle step when drawing arcs/circles approximated with lines.
Definition: opengl_gal.h:475
COLOR4D strokeColor
The color of the outlines.
void Translate(GLfloat aX, GLfloat aY, GLfloat aZ)
Function Translate() multiplies the current matrix by a translation matrix, so newly vertices will be...
void DrawLine(const VECTOR2D &aStartPoint, const VECTOR2D &aEndPoint) override
Draw a line.
Definition: opengl_gal.cpp:644
void Color(const COLOR4D &aColor)
Function Color() 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.
bool isFillEnabled
Is filling of graphic objects enabled ?
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:374
void DrawCircle(const VECTOR2D &aCenterPoint, double aRadius) override
Draw a circle using world coordinates.
Definition: opengl_gal.cpp:707

References KIGFX::COLOR4D::a, KIGFX::COLOR4D::b, calcAngleStep(), KIGFX::VERTEX_MANAGER::Color(), currentManager, DrawCircle(), DrawLine(), drawStrokedSemiCircle(), KIGFX::GAL::fillColor, KIGFX::COLOR4D::g, KIGFX::GAL::isFillEnabled, KIGFX::GAL::isStrokeEnabled, KiROUND(), KIGFX::COLOR4D::r, Restore(), Save(), KIGFX::GAL::SetLineWidth(), KIGFX::GAL::strokeColor, 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 1152 of file opengl_gal.cpp.

1153 {
1154  // We have to calculate the pixel size in users units to draw the image.
1155  // worldUnitLength is a factor used for converting IU to inches
1156  double scale = 1.0 / ( aBitmap.GetPPI() * worldUnitLength );
1157  double w = (double) aBitmap.GetSizePixels().x * scale;
1158  double h = (double) aBitmap.GetSizePixels().y * scale;
1159 
1160  auto xform = currentManager->GetTransformation();
1161 
1162  glm::vec4 v0 = xform * glm::vec4( -w/2, -h/2, 0.0, 0.0 );
1163  glm::vec4 v1 = xform * glm::vec4( w/2, h/2, 0.0, 0.0 );
1164  glm::vec4 trans = xform[3];
1165 
1166  auto texture_id = bitmapCache->RequestBitmap( &aBitmap );
1167 
1168  if( !glIsTexture( texture_id ) ) // ensure the bitmap texture is still valid
1169  return;
1170 
1171  auto oldTarget = GetTarget();
1172 
1173  glPushMatrix();
1174  glTranslated( trans.x, trans.y, trans.z );
1175 
1177  glEnable(GL_TEXTURE_2D);
1178  glActiveTexture( GL_TEXTURE0 );
1179  glBindTexture( GL_TEXTURE_2D, texture_id );
1180 
1181  glBegin( GL_QUADS );
1182  glColor4f( 1.0, 1.0, 1.0, 1.0 );
1183  glTexCoord2f( 0.0, 0.0 );
1184  glVertex3f( v0.x, v0.y, layerDepth );
1185  glColor4f( 1.0, 1.0, 1.0, 1.0 );
1186  glTexCoord2f( 1.0, 0.0 );
1187  glVertex3f( v1.x, v0.y, layerDepth );
1188  glColor4f( 1.0, 1.0, 1.0, 1.0 );
1189  glTexCoord2f( 1.0, 1.0 );
1190  glVertex3f( v1.x, v1.y, layerDepth );
1191  glColor4f( 1.0, 1.0, 1.0, 1.0 );
1192  glTexCoord2f( 0.0, 1.0 );
1193  glVertex3f( v0.x, v1.y, layerDepth );
1194  glEnd();
1195 
1196  SetTarget( oldTarget );
1197  glBindTexture( GL_TEXTURE_2D, 0 );
1198 
1199 #ifdef DISABLE_BITMAP_CACHE
1200  glDeleteTextures( 1, &texture_id );
1201 #endif
1202 
1203  glPopMatrix();
1204 }
VERTEX_MANAGER * currentManager
Currently used VERTEX_MANAGER (for storing VERTEX_ITEMs)
Definition: opengl_gal.h:302
const glm::mat4 & GetTransformation() const
double layerDepth
The actual layer depth.
std::unique_ptr< GL_BITMAP_CACHE > bitmapCache
Definition: opengl_gal.h:329
Auxiliary rendering target (noncached)
Definition: definitions.h:49
RENDER_TARGET GetTarget() const override
Gets the currently used target for rendering.
double worldUnitLength
The unit length of the world coordinates [inch].
void SetTarget(RENDER_TARGET aTarget) override
Sets the target for rendering.
const int scale
wxSize GetSizePixels() const
Function GetSizePixels.
Definition: bitmap_base.h:141
int GetPPI() const
Definition: bitmap_base.h:153

References bitmapCache, currentManager, BITMAP_BASE::GetPPI(), BITMAP_BASE::GetSizePixels(), GetTarget(), KIGFX::VERTEX_MANAGER::GetTransformation(), KIGFX::GAL::layerDepth, scale, SetTarget(), KIGFX::TARGET_NONCACHED, and KIGFX::GAL::worldUnitLength.

◆ drawBitmapChar()

int OPENGL_GAL::drawBitmapChar ( unsigned long  aChar)
private

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

1891 {
1892  const float TEX_X = font_image.width;
1893  const float TEX_Y = font_image.height;
1894 
1895  // handle space
1896  if( aChar == ' ' )
1897  {
1898  const FONT_GLYPH_TYPE* g = LookupGlyph( 'x' );
1899  wxASSERT( g );
1900 
1901  if( !g ) // Should not happen.
1902  return 0;
1903 
1904  Translate( VECTOR2D( g->advance, 0 ) );
1905  return g->advance;
1906  }
1907 
1908  const FONT_GLYPH_TYPE* glyph = LookupGlyph( aChar );
1909 
1910  // If the glyph is not found (happens for many esotheric unicode chars)
1911  // shows a '?' instead.
1912  if( !glyph )
1913  glyph = LookupGlyph( '?' );
1914 
1915  if( !glyph ) // Should not happen.
1916  return 0;
1917 
1918  const float X = glyph->atlas_x + font_information.smooth_pixels;
1919  const float Y = glyph->atlas_y + font_information.smooth_pixels;
1920  const float XOFF = glyph->minx;
1921 
1922  // adjust for height rounding
1923  const float round_adjust = ( glyph->maxy - glyph->miny )
1924  - float( glyph->atlas_h - font_information.smooth_pixels * 2 );
1925  const float top_adjust = font_information.max_y - glyph->maxy;
1926  const float YOFF = round_adjust + top_adjust;
1927  const float W = glyph->atlas_w - font_information.smooth_pixels *2;
1928  const float H = glyph->atlas_h - font_information.smooth_pixels *2;
1929  const float B = 0;
1930 
1931  currentManager->Reserve( 6 );
1932  Translate( VECTOR2D( XOFF, YOFF ) );
1933  /* Glyph:
1934  * v0 v1
1935  * +--+
1936  * | /|
1937  * |/ |
1938  * +--+
1939  * v2 v3
1940  */
1941  currentManager->Shader( SHADER_FONT, X / TEX_X, ( Y + H ) / TEX_Y );
1942  currentManager->Vertex( -B, -B, 0 ); // v0
1943 
1944  currentManager->Shader( SHADER_FONT, ( X + W ) / TEX_X, ( Y + H ) / TEX_Y );
1945  currentManager->Vertex( W + B, -B, 0 ); // v1
1946 
1947  currentManager->Shader( SHADER_FONT, X / TEX_X, Y / TEX_Y );
1948  currentManager->Vertex( -B, H + B, 0 ); // v2
1949 
1950 
1951  currentManager->Shader( SHADER_FONT, ( X + W ) / TEX_X, ( Y + H ) / TEX_Y );
1952  currentManager->Vertex( W + B, -B, 0 ); // v1
1953 
1954  currentManager->Shader( SHADER_FONT, X / TEX_X, Y / TEX_Y );
1955  currentManager->Vertex( -B, H + B, 0 ); // v2
1956 
1957  currentManager->Shader( SHADER_FONT, ( X + W ) / TEX_X, Y / TEX_Y );
1958  currentManager->Vertex( W + B, H + B, 0 ); // v3
1959 
1960  Translate( VECTOR2D( -XOFF + glyph->advance, -YOFF ) );
1961 
1962  return glyph->advance;
1963 }
VERTEX_MANAGER * currentManager
Currently used VERTEX_MANAGER (for storing VERTEX_ITEMs)
Definition: opengl_gal.h:302
void Translate(const VECTOR2D &aTranslation) override
Translate the context.
bool Reserve(unsigned int aSize)
Function Reserve() allocates space for vertices, so it will be used with subsequent Vertex() calls.
bool Vertex(const VERTEX &aVertex)
Function Vertex() adds a vertex with the given coordinates to the currently set item.
const FONT_GLYPH_TYPE * LookupGlyph(unsigned int aCodepoint)
VECTOR2< double > VECTOR2D
Definition: vector2d.h:593
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)
Function Shader() changes currently used shader and its parameters that will be applied to newly adde...

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, currentManager, KIGFX::BUILTIN_FONT::font_image, KIGFX::BUILTIN_FONT::font_information, H, KIGFX::BUILTIN_FONT::FONT_IMAGE_TYPE::height, 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::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

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

1967 {
1968  // To draw an overbar, simply draw an overbar
1969  const FONT_GLYPH_TYPE* glyph = LookupGlyph( '_' );
1970  wxCHECK( glyph, /* void */ );
1971 
1972  const float H = glyph->maxy - glyph->miny;
1973 
1974  Save();
1975 
1976  Translate( VECTOR2D( -aLength, -aHeight-1.5*H ) );
1977 
1978  currentManager->Reserve( 6 );
1980 
1981  currentManager->Shader( 0 );
1982 
1983  currentManager->Vertex( 0, 0, 0 ); // v0
1984  currentManager->Vertex( aLength, 0, 0 ); // v1
1985  currentManager->Vertex( 0, H, 0 ); // v2
1986 
1987  currentManager->Vertex( aLength, 0, 0 ); // v1
1988  currentManager->Vertex( 0, H, 0 ); // v2
1989  currentManager->Vertex( aLength, H, 0 ); // v3
1990 
1991  Restore();
1992 }
VERTEX_MANAGER * currentManager
Currently used VERTEX_MANAGER (for storing VERTEX_ITEMs)
Definition: opengl_gal.h:302
void Translate(const VECTOR2D &aTranslation) override
Translate the context.
bool Reserve(unsigned int aSize)
Function Reserve() allocates space for vertices, so it will be used with subsequent Vertex() calls.
void Restore() override
Restore the context.
bool Vertex(const VERTEX &aVertex)
Function Vertex() adds a vertex with the given coordinates to the currently set item.
double g
Green component.
Definition: color4d.h:375
const FONT_GLYPH_TYPE * LookupGlyph(unsigned int aCodepoint)
double b
Blue component.
Definition: color4d.h:376
void Save() override
Save the context.
VECTOR2< double > VECTOR2D
Definition: vector2d.h:593
COLOR4D strokeColor
The color of the outlines.
void Color(const COLOR4D &aColor)
Function Color() 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)
Function Shader() changes currently used shader and its parameters that will be applied to newly adde...
double r
Red component.
Definition: color4d.h:374

References KIGFX::COLOR4D::b, KIGFX::VERTEX_MANAGER::Color(), currentManager, KIGFX::COLOR4D::g, H, KIGFX::BUILTIN_FONT::LookupGlyph(), 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(), KIGFX::GAL::strokeColor, 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 707 of file opengl_gal.cpp.

708 {
709  if( isFillEnabled )
710  {
711  currentManager->Reserve( 3 );
713 
714  /* Draw a triangle that contains the circle, then shade it leaving only the circle.
715  * Parameters given to Shader() are indices of the triangle's vertices
716  * (if you want to understand more, check the vertex shader source [shader.vert]).
717  * Shader uses this coordinates to determine if fragments are inside the circle or not.
718  * Does the calculations in the vertex shader now (pixel alignment)
719  * v2
720  * /\
721  * //\\
722  * v0 /_\/_\ v1
723  */
724  currentManager->Shader( SHADER_FILLED_CIRCLE, 1.0, aRadius );
725  currentManager->Vertex( aCenterPoint.x, aCenterPoint.y, layerDepth );
726 
727  currentManager->Shader( SHADER_FILLED_CIRCLE, 2.0, aRadius );
728  currentManager->Vertex( aCenterPoint.x, aCenterPoint.y, layerDepth );
729 
730  currentManager->Shader( SHADER_FILLED_CIRCLE, 3.0, aRadius );
731  currentManager->Vertex( aCenterPoint.x, aCenterPoint.y, layerDepth );
732  }
733  if( isStrokeEnabled )
734  {
735  currentManager->Reserve( 3 );
737 
738  /* Draw a triangle that contains the circle, then shade it leaving only the circle.
739  * Parameters given to Shader() are indices of the triangle's vertices
740  * (if you want to understand more, check the vertex shader source [shader.vert]).
741  * and the line width. Shader uses this coordinates to determine if fragments are
742  * inside the circle or not.
743  * v2
744  * /\
745  * //\\
746  * v0 /_\/_\ v1
747  */
749  currentManager->Vertex( aCenterPoint.x, // v0
750  aCenterPoint.y, layerDepth );
751 
753  currentManager->Vertex( aCenterPoint.x, // v1
754  aCenterPoint.y, layerDepth );
755 
757  currentManager->Vertex( aCenterPoint.x, aCenterPoint.y, // v2
758  layerDepth );
759  }
760 }
VERTEX_MANAGER * currentManager
Currently used VERTEX_MANAGER (for storing VERTEX_ITEMs)
Definition: opengl_gal.h:302
double layerDepth
The actual layer depth.
bool Reserve(unsigned int aSize)
Function Reserve() allocates space for vertices, so it will be used with subsequent Vertex() calls.
bool Vertex(const VERTEX &aVertex)
Function Vertex() adds a vertex with the given coordinates to the currently set item.
double g
Green component.
Definition: color4d.h:375
COLOR4D fillColor
The fill color.
double b
Blue component.
Definition: color4d.h:376
double a
Alpha component.
Definition: color4d.h:377
bool isStrokeEnabled
Are the outlines stroked ?
COLOR4D strokeColor
The color of the outlines.
void Color(const COLOR4D &aColor)
Function Color() changes currently used color that will be applied to newly added vertices.
float lineWidth
The line width.
bool isFillEnabled
Is filling of graphic objects enabled ?
void Shader(GLfloat aShaderType, GLfloat aParam1=0.0f, GLfloat aParam2=0.0f, GLfloat aParam3=0.0f)
Function Shader() changes currently used shader and its parameters that will be applied to newly adde...
double r
Red component.
Definition: color4d.h:374

References KIGFX::COLOR4D::a, KIGFX::COLOR4D::b, KIGFX::VERTEX_MANAGER::Color(), currentManager, KIGFX::GAL::fillColor, KIGFX::COLOR4D::g, KIGFX::GAL::isFillEnabled, KIGFX::GAL::isStrokeEnabled, KIGFX::GAL::layerDepth, KIGFX::GAL::lineWidth, KIGFX::COLOR4D::r, KIGFX::VERTEX_MANAGER::Reserve(), KIGFX::VERTEX_MANAGER::Shader(), KIGFX::SHADER_FILLED_CIRCLE, KIGFX::SHADER_STROKED_CIRCLE, KIGFX::GAL::strokeColor, 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 1701 of file opengl_gal.cpp.

1702 {
1703  // Now we should only store the position of the mouse cursor
1704  // The real drawing routines are in blitCursor()
1705  //VECTOR2D screenCursor = worldScreenMatrix * aCursorPosition;
1706  //cursorPosition = screenWorldMatrix * VECTOR2D( screenCursor.x, screenCursor.y );
1707  cursorPosition = aCursorPosition;
1708 }
VECTOR2D cursorPosition
Current cursor position (world coordinates)

References KIGFX::GAL::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 1133 of file opengl_gal.cpp.

1136 {
1137  std::vector<VECTOR2D> output;
1138  std::vector<VECTOR2D> pointCtrl;
1139 
1140  pointCtrl.push_back( aStartPoint );
1141  pointCtrl.push_back( aControlPointA );
1142  pointCtrl.push_back( aControlPointB );
1143  pointCtrl.push_back( aEndPoint );
1144 
1145  BEZIER_POLY converter( pointCtrl );
1146  converter.GetPoly( output, aFilterValue );
1147 
1148  DrawPolyline( &output[0], output.size() );
1149 }
void DrawPolyline(const std::deque< VECTOR2D > &aPointList) override
Draw a polyline.
Definition: opengl_gal.cpp:974
Bezier curves to polygon converter.
Definition: bezier_curves.h:35

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

1774 {
1775  Save();
1776 
1777  currentManager->Reserve( 3 );
1778  currentManager->Translate( aCenterPoint.x, aCenterPoint.y, 0.0f );
1779  currentManager->Rotate( aAngle, 0.0f, 0.0f, 1.0f );
1780 
1781  /* Draw a triangle that contains the semicircle, then shade it to leave only
1782  * the semicircle. Parameters given to Shader() are indices of the triangle's vertices
1783  * (if you want to understand more, check the vertex shader source [shader.vert]).
1784  * Shader uses these coordinates to determine if fragments are inside the semicircle or not.
1785  * v2
1786  * /\
1787  * /__\
1788  * v0 //__\\ v1
1789  */
1791  currentManager->Vertex( -aRadius * 3.0f / sqrt( 3.0f ), 0.0f, layerDepth ); // v0
1792 
1794  currentManager->Vertex( aRadius * 3.0f / sqrt( 3.0f ), 0.0f, layerDepth ); // v1
1795 
1797  currentManager->Vertex( 0.0f, aRadius * 2.0f, layerDepth ); // v2
1798 
1799  Restore();
1800 }
VERTEX_MANAGER * currentManager
Currently used VERTEX_MANAGER (for storing VERTEX_ITEMs)
Definition: opengl_gal.h:302
double layerDepth
The actual layer depth.
bool Reserve(unsigned int aSize)
Function Reserve() allocates space for vertices, so it will be used with subsequent Vertex() calls.
void Restore() override
Restore the context.
bool Vertex(const VERTEX &aVertex)
Function Vertex() adds a vertex with the given coordinates to the currently set item.
void Rotate(GLfloat aAngle, GLfloat aX, GLfloat aY, GLfloat aZ)
Function Rotate() multiplies the current matrix by a rotation matrix, so the newly vertices will be r...
void Save() override
Save the context.
void Translate(GLfloat aX, GLfloat aY, GLfloat aZ)
Function Translate() multiplies the current matrix by a translation matrix, so newly vertices will be...
void Shader(GLfloat aShaderType, GLfloat aParam1=0.0f, GLfloat aParam2=0.0f, GLfloat aParam3=0.0f)
Function Shader() changes currently used shader and its parameters that will be applied to newly adde...

References currentManager, KIGFX::GAL::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

Draw the grid

Reimplemented from KIGFX::GAL.

Definition at line 1323 of file opengl_gal.cpp.

1324 {
1327 
1329 
1330  // sub-pixel lines all render the same
1331  float minorLineWidth =
1332  std::fmax( 1.0f, gridLineWidth ) * getWorldPixelSize() / GetScaleFactor();
1333  float majorLineWidth = minorLineWidth * 2.0f;
1334 
1335  // Draw the axis and grid
1336  // For the drawing the start points, end points and increments have
1337  // to be calculated in world coordinates
1338  VECTOR2D worldStartPoint = screenWorldMatrix * VECTOR2D( 0.0, 0.0 );
1339  VECTOR2D worldEndPoint = screenWorldMatrix * VECTOR2D( screenSize );
1340 
1341  // Draw axes if desired
1342  if( axesEnabled )
1343  {
1344  SetLineWidth( minorLineWidth );
1346 
1347  DrawLine( VECTOR2D( worldStartPoint.x, 0 ), VECTOR2D( worldEndPoint.x, 0 ) );
1348  DrawLine( VECTOR2D( 0, worldStartPoint.y ), VECTOR2D( 0, worldEndPoint.y ) );
1349  }
1350 
1351  // force flush
1353 
1354  if( !gridVisibility || gridSize.x == 0 || gridSize.y == 0 )
1355  return;
1356 
1357  VECTOR2D gridScreenSize( gridSize );
1358 
1359  double gridThreshold = computeMinGridSpacing() / worldScale;
1360 
1362  gridThreshold *= 2.0;
1363 
1364  // If we cannot display the grid density, scale down by a tick size and
1365  // try again. Eventually, we get some representation of the grid
1366  while( std::min( gridScreenSize.x, gridScreenSize.y ) <= gridThreshold )
1367  {
1368  gridScreenSize = gridScreenSize * static_cast<double>( gridTick );
1369  }
1370 
1371  // Compute grid starting and ending indexes to draw grid points on the
1372  // visible screen area
1373  // Note: later any point coordinate will be offsetted by gridOrigin
1374  int gridStartX = KiROUND( ( worldStartPoint.x - gridOrigin.x ) / gridScreenSize.x );
1375  int gridEndX = KiROUND( ( worldEndPoint.x - gridOrigin.x ) / gridScreenSize.x );
1376  int gridStartY = KiROUND( ( worldStartPoint.y - gridOrigin.y ) / gridScreenSize.y );
1377  int gridEndY = KiROUND( ( worldEndPoint.y - gridOrigin.y ) / gridScreenSize.y );
1378 
1379  // Ensure start coordinate > end coordinate
1380  SWAP( gridStartX, >, gridEndX );
1381  SWAP( gridStartY, >, gridEndY );
1382 
1383  // Ensure the grid fills the screen
1384  --gridStartX; ++gridEndX;
1385  --gridStartY; ++gridEndY;
1386 
1387  glDisable( GL_DEPTH_TEST );
1388  glDisable( GL_TEXTURE_2D );
1389 
1390  if( gridStyle == GRID_STYLE::DOTS )
1391  {
1392  glEnable( GL_STENCIL_TEST );
1393  glStencilFunc( GL_ALWAYS, 1, 1 );
1394  glStencilOp( GL_KEEP, GL_KEEP, GL_INCR );
1395  glColor4d( 0.0, 0.0, 0.0, 0.0 );
1396  SetStrokeColor( COLOR4D( 0.0, 0.0, 0.0, 0.0 ) );
1397  }
1398  else
1399  {
1400  glColor4d( gridColor.r, gridColor.g, gridColor.b, gridColor.a );
1402  }
1403 
1405  {
1406 
1407  // Vertical positions
1408  for( int j = gridStartY; j <= gridEndY; j++ )
1409  {
1410  bool tickY = ( j % gridTick == 0 );
1411  const double posY = j * gridScreenSize.y + gridOrigin.y;
1412 
1413  // Horizontal positions
1414  for( int i = gridStartX; i <= gridEndX; i++ )
1415  {
1416  bool tickX = ( i % gridTick == 0 );
1417  SetLineWidth( ( ( tickX && tickY ) ? majorLineWidth : minorLineWidth ) );
1418  auto lineLen = 2.0 * GetLineWidth();
1419  auto posX = i * gridScreenSize.x + gridOrigin.x;
1420 
1421  DrawLine( VECTOR2D( posX - lineLen, posY ), VECTOR2D( posX + lineLen, posY ) );
1422  DrawLine( VECTOR2D( posX, posY - lineLen ), VECTOR2D( posX, posY + lineLen ) );
1423  }
1424  }
1425 
1427  }
1428  else
1429  {
1430  // Vertical lines
1431  for( int j = gridStartY; j <= gridEndY; j++ )
1432  {
1433  const double y = j * gridScreenSize.y + gridOrigin.y;
1434 
1435  // If axes are drawn, skip the lines that would cover them
1436  if( axesEnabled && y == 0.0 )
1437  continue;
1438 
1439  SetLineWidth( ( j % gridTick == 0 ) ? majorLineWidth : minorLineWidth );
1440  VECTOR2D a ( gridStartX * gridScreenSize.x + gridOrigin.x, y );
1441  VECTOR2D b ( gridEndX * gridScreenSize.x + gridOrigin.x, y );
1442 
1443  DrawLine( a, b );
1444  }
1445 
1447 
1448  if( gridStyle == GRID_STYLE::DOTS )
1449  {
1450  glStencilFunc( GL_NOTEQUAL, 0, 1 );
1451  glColor4d( gridColor.r, gridColor.g, gridColor.b, gridColor.a );
1453  }
1454 
1455  // Horizontal lines
1456  for( int i = gridStartX; i <= gridEndX; i++ )
1457  {
1458  const double x = i * gridScreenSize.x + gridOrigin.x;
1459 
1460  // If axes are drawn, skip the lines that would cover them
1461  if( axesEnabled && x == 0.0 )
1462  continue;
1463 
1464  SetLineWidth( ( i % gridTick == 0 ) ? majorLineWidth : minorLineWidth );
1465  VECTOR2D a ( x, gridStartY * gridScreenSize.y + gridOrigin.y );
1466  VECTOR2D b ( x, gridEndY * gridScreenSize.y + gridOrigin.y );
1467  DrawLine( a, b );
1468  }
1469 
1471 
1472  if( gridStyle == GRID_STYLE::DOTS )
1473  glDisable( GL_STENCIL_TEST );
1474  }
1475 
1476  glEnable( GL_DEPTH_TEST );
1477  glEnable( GL_TEXTURE_2D );
1478 }
int gridTick
Every tick line gets the double width.
float GetLineWidth() const
Get the line width.
bool axesEnabled
Should the axes be drawn.
double computeMinGridSpacing() const
compute minimum grid spacing from the grid settings
GRID_STYLE gridStyle
Grid display style.
double GetScaleFactor() const
Get the current scale factor.
double g
Green component.
Definition: color4d.h:375
MATRIX3x3D screenWorldMatrix
Screen transformation.
virtual void SetLineWidth(float aLineWidth)
Set the line width.
VERTEX_MANAGER * nonCachedManager
Container for storing non-cached VERTEX_ITEMs.
Definition: opengl_gal.h:304
double b
Blue component.
Definition: color4d.h:376
Auxiliary rendering target (noncached)
Definition: definitions.h:49
double getWorldPixelSize() const
Definition: opengl_gal.cpp:394
double a
Alpha component.
Definition: color4d.h:377
OPENGL_COMPOSITOR * compositor
Handles multiple rendering targets.
Definition: opengl_gal.h:308
VECTOR2< double > VECTOR2D
Definition: vector2d.h:593
unsigned int mainBuffer
Main rendering target.
Definition: opengl_gal.h:309
COLOR4D axesColor
Color of the axes.
float gridLineWidth
Line width of the grid.
void DrawLine(const VECTOR2D &aStartPoint, const VECTOR2D &aEndPoint) override
Draw a line.
Definition: opengl_gal.cpp:644
VECTOR2D gridOrigin
The grid origin.
virtual void SetBuffer(unsigned int aBufferHandle) override
Function SetBuffer() sets the selected buffer as the rendering target.
Use dots for the grid.
Use small cross instead of dots for the grid.
void EndDrawing() const
Function EndDrawing() finishes drawing operations.
void SetTarget(RENDER_TARGET aTarget) override
Sets the target for rendering.
virtual void SetStrokeColor(const COLOR4D &aColor)
Set the stroke color.
COLOR4D gridColor
Color of the grid.
bool gridVisibility
Should the grid be shown.
void EnableDepthTest(bool aEnabled)
Function EnableDepthTest() Enables/disables Z buffer depth test.
double worldScale
The scale factor world->screen.
VECTOR2D gridSize
The grid size.
VECTOR2I screenSize
Screen size in screen coordinates.
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:374
COLOR4D is the color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:100

References KIGFX::COLOR4D::a, KIGFX::GAL::axesColor, KIGFX::GAL::axesEnabled, KIGFX::COLOR4D::b, compositor, 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(), KIGFX::GAL::gridColor, KIGFX::GAL::gridLineWidth, KIGFX::GAL::gridOrigin, KIGFX::GAL::gridSize, KIGFX::GAL::gridStyle, KIGFX::GAL::gridTick, KIGFX::GAL::gridVisibility, KiROUND(), mainBuffer, nonCachedManager, KIGFX::COLOR4D::r, KIGFX::GAL::screenSize, KIGFX::GAL::screenWorldMatrix, KIGFX::OPENGL_COMPOSITOR::SetBuffer(), KIGFX::GAL::SetLineWidth(), KIGFX::GAL::SetStrokeColor(), SetTarget(), KIGFX::SMALL_CROSS, SWAP, KIGFX::TARGET_NONCACHED, KIGFX::GAL::worldScale, 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 1588 of file opengl_gal.cpp.

1589 {
1590  if( groups[aGroupNumber] )
1591  cachedManager->DrawItem( *groups[aGroupNumber] );
1592 }
void DrawItem(const VERTEX_ITEM &aItem) const
Function DrawItem() draws an item to the buffer.
GROUPS_MAP groups
Stores informations about VBO objects (groups)
Definition: opengl_gal.h:300
VERTEX_MANAGER * cachedManager
Container for storing cached VERTEX_ITEMs.
Definition: opengl_gal.h:303

References cachedManager, KIGFX::VERTEX_MANAGER::DrawItem(), and 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 644 of file opengl_gal.cpp.

645 {
647 
648  drawLineQuad( aStartPoint, aEndPoint );
649 }
VERTEX_MANAGER * currentManager
Currently used VERTEX_MANAGER (for storing VERTEX_ITEMs)
Definition: opengl_gal.h:302
void drawLineQuad(const VECTOR2D &aStartPoint, const VECTOR2D &aEndPoint)
Draw a quad for the line.
double g
Green component.
Definition: color4d.h:375
double b
Blue component.
Definition: color4d.h:376
double a
Alpha component.
Definition: color4d.h:377
COLOR4D strokeColor
The color of the outlines.
void Color(const COLOR4D &aColor)
Function Color() changes currently used color that will be applied to newly added vertices.
double r
Red component.
Definition: color4d.h:374

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

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

1712 {
1713  /* Helper drawing: ____--- v3 ^
1714  * ____---- ... \ \
1715  * ____---- ... \ end \
1716  * v1 ____---- ... ____---- \ width
1717  * ---- ...___---- \ \
1718  * \ ___...-- \ v
1719  * \ ____----... ____---- v2
1720  * ---- ... ____----
1721  * start \ ... ____----
1722  * \... ____----
1723  * ----
1724  * v0
1725  * dots mark triangles' hypotenuses
1726  */
1727 
1728  auto v1 = currentManager->GetTransformation() * glm::vec4( aStartPoint.x, aStartPoint.y, 0.0, 0.0 );
1729  auto v2 = currentManager->GetTransformation() * glm::vec4( aEndPoint.x, aEndPoint.y, 0.0, 0.0 );
1730 
1731  VECTOR2D vs( v2.x - v1.x, v2.y - v1.y );
1732 
1733  currentManager->Reserve( 6 );
1734 
1735  // Line width is maintained by the vertex shader
1736  currentManager->Shader( SHADER_LINE_A, lineWidth, vs.x, vs.y );
1737  currentManager->Vertex( aStartPoint, layerDepth );
1738 
1739  currentManager->Shader( SHADER_LINE_B, lineWidth, vs.x, vs.y );
1740  currentManager->Vertex( aStartPoint, layerDepth );
1741 
1742  currentManager->Shader( SHADER_LINE_C, lineWidth, vs.x, vs.y );
1743  currentManager->Vertex( aEndPoint, layerDepth );
1744 
1745  currentManager->Shader( SHADER_LINE_D, lineWidth, vs.x, vs.y );
1746  currentManager->Vertex( aEndPoint, layerDepth );
1747 
1748  currentManager->Shader( SHADER_LINE_E, lineWidth, vs.x, vs.y );
1749  currentManager->Vertex( aEndPoint, layerDepth );
1750 
1751  currentManager->Shader( SHADER_LINE_F, lineWidth, vs.x, vs.y );
1752  currentManager->Vertex( aStartPoint, layerDepth );
1753 }
VERTEX_MANAGER * currentManager
Currently used VERTEX_MANAGER (for storing VERTEX_ITEMs)
Definition: opengl_gal.h:302
const glm::mat4 & GetTransformation() const
double layerDepth
The actual layer depth.
bool Reserve(unsigned int aSize)
Function Reserve() allocates space for vertices, so it will be used with subsequent Vertex() calls.
bool Vertex(const VERTEX &aVertex)
Function Vertex() adds a vertex with the given coordinates to the currently set item.
float lineWidth
The line width.
void Shader(GLfloat aShaderType, GLfloat aParam1=0.0f, GLfloat aParam2=0.0f, GLfloat aParam3=0.0f)
Function Shader() changes currently used shader and its parameters that will be applied to newly adde...

References currentManager, KIGFX::VERTEX_MANAGER::GetTransformation(), KIGFX::GAL::layerDepth, KIGFX::GAL::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, 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 997 of file opengl_gal.cpp.

998 {
999  wxCHECK( aPointList.size() >= 2, /* void */ );
1000  auto points = std::unique_ptr<GLdouble[]>( new GLdouble[3 * aPointList.size()] );
1001  GLdouble* ptr = points.get();
1002 
1003  for( const VECTOR2D& p : aPointList )
1004  {
1005  *ptr++ = p.x;
1006  *ptr++ = p.y;
1007  *ptr++ = layerDepth;
1008  }
1009 
1010  drawPolygon( points.get(), aPointList.size() );
1011 }
double layerDepth
The actual layer depth.
void drawPolygon(GLdouble *aPoints, int aPointCount)
Draws a filled polygon.

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

Referenced by DrawPolygon().

◆ DrawPolygon() [2/4]

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

Reimplemented from KIGFX::GAL.

Definition at line 1014 of file opengl_gal.cpp.

1015 {
1016  wxCHECK( aListSize >= 2, /* void */ );
1017  auto points = std::unique_ptr<GLdouble[]>( new GLdouble[3 * aListSize] );
1018  GLdouble* target = points.get();
1019  const VECTOR2D* src = aPointList;
1020 
1021  for( int i = 0; i < aListSize; ++i )
1022  {
1023  *target++ = src->x;
1024  *target++ = src->y;
1025  *target++ = layerDepth;
1026  ++src;
1027  }
1028 
1029  drawPolygon( points.get(), aListSize );
1030 }
double layerDepth
The actual layer depth.
void drawPolygon(GLdouble *aPoints, int aPointCount)
Draws a filled polygon.

References drawPolygon(), KIGFX::GAL::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 1096 of file opengl_gal.cpp.

1097 {
1098  if ( aPolySet.IsTriangulationUpToDate() )
1099  {
1100  drawTriangulatedPolyset( aPolySet );
1101  return;
1102  }
1103 
1104  for( int j = 0; j < aPolySet.OutlineCount(); ++j )
1105  {
1106  const SHAPE_LINE_CHAIN& outline = aPolySet.COutline( j );
1107  DrawPolygon( outline );
1108  }
1109 }
int OutlineCount() const
Returns the number of outlines in the set
void DrawPolygon(const std::deque< VECTOR2D > &aPointList) override
Draw a polygon.
Definition: opengl_gal.cpp:997
bool IsTriangulationUpToDate() const
void drawTriangulatedPolyset(const SHAPE_POLY_SET &aPoly)
Draws 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 1113 of file opengl_gal.cpp.

1114 {
1115  wxCHECK( aPolygon.PointCount() >= 2, /* void */ );
1116 
1117  const int pointCount = aPolygon.SegmentCount() + 1;
1118  std::unique_ptr<GLdouble[]> points( new GLdouble[3 * pointCount] );
1119  GLdouble* ptr = points.get();
1120 
1121  for( int i = 0; i < pointCount; ++i )
1122  {
1123  const VECTOR2I& p = aPolygon.CPoint( i );
1124  *ptr++ = p.x;
1125  *ptr++ = p.y;
1126  *ptr++ = layerDepth;
1127  }
1128 
1129  drawPolygon( points.get(), pointCount );
1130 }
double layerDepth
The actual layer depth.
void drawPolygon(GLdouble *aPoints, int aPointCount)
Draws a filled polygon.

References SHAPE_LINE_CHAIN::CPoint(), drawPolygon(), KIGFX::GAL::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

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

1838 {
1839  if( isFillEnabled )
1840  {
1843 
1844  // Any non convex polygon needs to be tesselated
1845  // for this purpose the GLU standard functions are used
1846  TessParams params = { currentManager, tessIntersects };
1847  gluTessBeginPolygon( tesselator, &params );
1848  gluTessBeginContour( tesselator );
1849 
1850  GLdouble* point = aPoints;
1851 
1852  for( int i = 0; i < aPointCount; ++i )
1853  {
1854  gluTessVertex( tesselator, point, point );
1855  point += 3; // 3 coordinates
1856  }
1857 
1858  gluTessEndContour( tesselator );
1859  gluTessEndPolygon( tesselator );
1860 
1861  // Free allocated intersecting points
1862  tessIntersects.clear();
1863  }
1864 
1865  if( isStrokeEnabled )
1866  {
1867  drawPolyline( [&](int idx) { return VECTOR2D( aPoints[idx * 3], aPoints[idx * 3 + 1] ); },
1868  aPointCount );
1869  }
1870 }
VERTEX_MANAGER * currentManager
Currently used VERTEX_MANAGER (for storing VERTEX_ITEMs)
Definition: opengl_gal.h:302
double g
Green component.
Definition: color4d.h:375
COLOR4D fillColor
The fill color.
double b
Blue component.
Definition: color4d.h:376
double a
Alpha component.
Definition: color4d.h:377
bool isStrokeEnabled
Are the outlines stroked ?
VECTOR2< double > VECTOR2D
Definition: vector2d.h:593
void Color(const COLOR4D &aColor)
Function Color() changes currently used color that will be applied to newly added vertices.
GLUtesselator * tesselator
The tessellator.
Definition: opengl_gal.h:352
bool isFillEnabled
Is filling of graphic objects enabled ?
std::deque< boost::shared_array< GLdouble > > tessIntersects
Storage for intersecting points.
Definition: opengl_gal.h:354
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)
Function Shader() changes currently used shader and its parameters that will be applied to newly adde...
double r
Red component.
Definition: color4d.h:374

References KIGFX::COLOR4D::a, KIGFX::COLOR4D::b, KIGFX::VERTEX_MANAGER::Color(), currentManager, drawPolyline(), KIGFX::GAL::fillColor, KIGFX::COLOR4D::g, KIGFX::GAL::isFillEnabled, KIGFX::GAL::isStrokeEnabled, KIGFX::COLOR4D::r, KIGFX::VERTEX_MANAGER::Shader(), KIGFX::SHADER_NONE, tesselator, and tessIntersects.

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

975 {
976  drawPolyline( [&](int idx) { return aPointList[idx]; }, aPointList.size() );
977 }
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 980 of file opengl_gal.cpp.

981 {
982  drawPolyline( [&](int idx) { return aPointList[idx]; }, aListSize );
983 }
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 986 of file opengl_gal.cpp.

987 {
988  auto numPoints = aLineChain.PointCount();
989 
990  if( aLineChain.IsClosed() )
991  numPoints += 1;
992 
993  drawPolyline( [&](int idx) { return aLineChain.CPoint(idx); }, numPoints );
994 }
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 1873 of file opengl_gal.cpp.

1874 {
1875  wxCHECK( aPointCount >= 2, /* return */ );
1876 
1878  int i;
1879 
1880  for( i = 1; i < aPointCount; ++i )
1881  {
1882  auto start = aPointGetter( i - 1 );
1883  auto end = aPointGetter( i );
1884 
1885  drawLineQuad( start, end );
1886  }
1887 }
VERTEX_MANAGER * currentManager
Currently used VERTEX_MANAGER (for storing VERTEX_ITEMs)
Definition: opengl_gal.h:302
void drawLineQuad(const VECTOR2D &aStartPoint, const VECTOR2D &aEndPoint)
Draw a quad for the line.
double g
Green component.
Definition: color4d.h:375
double b
Blue component.
Definition: color4d.h:376
double a
Alpha component.
Definition: color4d.h:377
COLOR4D strokeColor
The color of the outlines.
void Color(const COLOR4D &aColor)
Function Color() changes currently used color that will be applied to newly added vertices.
double r
Red component.
Definition: color4d.h:374

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

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

937 {
938  // Compute the diagonal points of the rectangle
939  VECTOR2D diagonalPointA( aEndPoint.x, aStartPoint.y );
940  VECTOR2D diagonalPointB( aStartPoint.x, aEndPoint.y );
941 
942  // Fill the rectangle
943  if( isFillEnabled )
944  {
945  currentManager->Reserve( 6 );
948 
949  currentManager->Vertex( aStartPoint.x, aStartPoint.y, layerDepth );
950  currentManager->Vertex( diagonalPointA.x, diagonalPointA.y, layerDepth );
951  currentManager->Vertex( aEndPoint.x, aEndPoint.y, layerDepth );
952 
953  currentManager->Vertex( aStartPoint.x, aStartPoint.y, layerDepth );
954  currentManager->Vertex( aEndPoint.x, aEndPoint.y, layerDepth );
955  currentManager->Vertex( diagonalPointB.x, diagonalPointB.y, layerDepth );
956  }
957 
958  // Stroke the outline
959  if( isStrokeEnabled )
960  {
962 
963  std::deque<VECTOR2D> pointList;
964  pointList.push_back( aStartPoint );
965  pointList.push_back( diagonalPointA );
966  pointList.push_back( aEndPoint );
967  pointList.push_back( diagonalPointB );
968  pointList.push_back( aStartPoint );
969  DrawPolyline( pointList );
970  }
971 }
VERTEX_MANAGER * currentManager
Currently used VERTEX_MANAGER (for storing VERTEX_ITEMs)
Definition: opengl_gal.h:302
double layerDepth
The actual layer depth.
bool Reserve(unsigned int aSize)
Function Reserve() allocates space for vertices, so it will be used with subsequent Vertex() calls.
bool Vertex(const VERTEX &aVertex)
Function Vertex() adds a vertex with the given coordinates to the currently set item.
double g
Green component.
Definition: color4d.h:375
COLOR4D fillColor
The fill color.
double b
Blue component.
Definition: color4d.h:376
double a
Alpha component.
Definition: color4d.h:377
bool isStrokeEnabled
Are the outlines stroked ?
COLOR4D strokeColor
The color of the outlines.
void Color(const COLOR4D &aColor)
Function Color() changes currently used color that will be applied to newly added vertices.
bool isFillEnabled
Is filling of graphic objects enabled ?
void DrawPolyline(const std::deque< VECTOR2D > &aPointList) override
Draw a polyline.
Definition: opengl_gal.cpp:974
void Shader(GLfloat aShaderType, GLfloat aParam1=0.0f, GLfloat aParam2=0.0f, GLfloat aParam3=0.0f)
Function Shader() changes currently used shader and its parameters that will be applied to newly adde...
double r
Red component.
Definition: color4d.h:374

References KIGFX::COLOR4D::a, KIGFX::COLOR4D::b, KIGFX::VERTEX_MANAGER::Color(), currentManager, DrawPolyline(), KIGFX::GAL::fillColor, KIGFX::COLOR4D::g, KIGFX::GAL::isFillEnabled, KIGFX::GAL::isStrokeEnabled, KIGFX::GAL::layerDepth, KIGFX::COLOR4D::r, KIGFX::VERTEX_MANAGER::Reserve(), KIGFX::VERTEX_MANAGER::Shader(), KIGFX::SHADER_NONE, KIGFX::GAL::strokeColor, 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 652 of file opengl_gal.cpp.

654 {
655  VECTOR2D startEndVector = aEndPoint - aStartPoint;
656  double lineLength = startEndVector.EuclideanNorm();
657 
658  float startx = aStartPoint.x;
659  float starty = aStartPoint.y;
660  float endx = aStartPoint.x + lineLength;
661  float endy = aStartPoint.y + lineLength;
662 
663  // Be careful about floating point rounding. As we draw segments in larger and larger coordinates,
664  // the shader (which uses floats) will lose precision and stop drawing small segments.
665  // In this case, we need to draw a circle for the minimal segment
666  if( startx == endx || starty == endy )
667  {
668  DrawCircle( aStartPoint, aWidth/2 );
669  return;
670  }
671 
672  if( isFillEnabled || aWidth == 1.0 )
673  {
675 
676  SetLineWidth( aWidth );
677  drawLineQuad( aStartPoint, aEndPoint );
678  }
679  else
680  {
681  auto lineAngle = startEndVector.Angle();
682  // Outlined tracks
683 
684  SetLineWidth( 1.0 );
686 
687  Save();
688 
689  currentManager->Translate( aStartPoint.x, aStartPoint.y, 0.0 );
690  currentManager->Rotate( lineAngle, 0.0f, 0.0f, 1.0f );
691 
692  drawLineQuad( VECTOR2D( 0.0, aWidth / 2.0 ),
693  VECTOR2D( lineLength, aWidth / 2.0 ) );
694 
695  drawLineQuad( VECTOR2D( 0.0, -aWidth / 2.0 ),
696  VECTOR2D( lineLength, -aWidth / 2.0 ) );
697 
698  // Draw line caps
699  drawStrokedSemiCircle( VECTOR2D( 0.0, 0.0 ), aWidth / 2, M_PI / 2 );
700  drawStrokedSemiCircle( VECTOR2D( lineLength, 0.0 ), aWidth / 2, -M_PI / 2 );
701 
702  Restore();
703  }
704 }
VERTEX_MANAGER * currentManager
Currently used VERTEX_MANAGER (for storing VERTEX_ITEMs)
Definition: opengl_gal.h:302
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)
Function Rotate() multiplies the current matrix by a rotation matrix, so the newly vertices will be r...
double g
Green component.
Definition: color4d.h:375
COLOR4D fillColor
The fill color.
virtual void SetLineWidth(float aLineWidth)
Set the line width.
double b
Blue component.
Definition: color4d.h:376
void Save() override
Save the context.
double a
Alpha component.
Definition: color4d.h:377
VECTOR2< double > VECTOR2D
Definition: vector2d.h:593
COLOR4D strokeColor
The color of the outlines.
void Translate(GLfloat aX, GLfloat aY, GLfloat aZ)
Function Translate() multiplies the current matrix by a translation matrix, so newly vertices will be...
double Angle() const
Function Angle computes the angle of the vector.
Definition: vector2d.h:313
void Color(const COLOR4D &aColor)
Function Color() 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.
bool isFillEnabled
Is filling of graphic objects enabled ?
T EuclideanNorm() const
Destructor.
Definition: vector2d.h:299
double r
Red component.
Definition: color4d.h:374
void DrawCircle(const VECTOR2D &aCenterPoint, double aRadius) override
Draw a circle using world coordinates.
Definition: opengl_gal.cpp:707

References KIGFX::COLOR4D::a, VECTOR2< T >::Angle(), KIGFX::COLOR4D::b, KIGFX::VERTEX_MANAGER::Color(), currentManager, DrawCircle(), drawLineQuad(), drawStrokedSemiCircle(), VECTOR2< T >::EuclideanNorm(), KIGFX::GAL::fillColor, KIGFX::COLOR4D::g, KIGFX::GAL::isFillEnabled, KIGFX::COLOR4D::r, Restore(), KIGFX::VERTEX_MANAGER::Rotate(), Save(), KIGFX::GAL::SetLineWidth(), KIGFX::GAL::strokeColor, and KIGFX::VERTEX_MANAGER::Translate().

◆ drawSemiCircle()

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

Draw a semicircle.

Depending on settings (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 1756 of file opengl_gal.cpp.

1757 {
1758  if( isFillEnabled )
1759  {
1761  drawFilledSemiCircle( aCenterPoint, aRadius, aAngle );
1762  }
1763 
1764  if( isStrokeEnabled )
1765  {
1767  drawStrokedSemiCircle( aCenterPoint, aRadius, aAngle );
1768  }
1769 }
VERTEX_MANAGER * currentManager
Currently used VERTEX_MANAGER (for storing VERTEX_ITEMs)
Definition: opengl_gal.h:302
double g
Green component.
Definition: color4d.h:375
COLOR4D fillColor
The fill color.
double b
Blue component.
Definition: color4d.h:376
double a
Alpha component.
Definition: color4d.h:377
bool isStrokeEnabled
Are the outlines stroked ?
COLOR4D strokeColor
The color of the outlines.
void Color(const COLOR4D &aColor)
Function Color() 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.
bool isFillEnabled
Is filling of graphic objects enabled ?
double r
Red component.
Definition: color4d.h:374
void drawFilledSemiCircle(const VECTOR2D &aCenterPoint, double aRadius, double aAngle)
Draw a filled semicircle.

References KIGFX::COLOR4D::a, KIGFX::COLOR4D::b, KIGFX::VERTEX_MANAGER::Color(), currentManager, drawFilledSemiCircle(), drawStrokedSemiCircle(), KIGFX::GAL::fillColor, KIGFX::COLOR4D::g, KIGFX::GAL::isFillEnabled, KIGFX::GAL::isStrokeEnabled, KIGFX::COLOR4D::r, and KIGFX::GAL::strokeColor.

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

1805 {
1806  double outerRadius = aRadius + ( lineWidth / 2 );
1807 
1808  Save();
1809 
1810  currentManager->Reserve( 3 );
1811  currentManager->Translate( aCenterPoint.x, aCenterPoint.y, 0.0f );
1812  currentManager->Rotate( aAngle, 0.0f, 0.0f, 1.0f );
1813 
1814  /* Draw a triangle that contains the semicircle, then shade it to leave only
1815  * the semicircle. Parameters given to Shader() are indices of the triangle's vertices
1816  * (if you want to understand more, check the vertex shader source [shader.vert]), the
1817  * radius and the line width. Shader uses these coordinates to determine if fragments are
1818  * inside the semicircle or not.
1819  * v2
1820  * /\
1821  * /__\
1822  * v0 //__\\ v1
1823  */
1825  currentManager->Vertex( -outerRadius * 3.0f / sqrt( 3.0f ), 0.0f, layerDepth ); // v0
1826 
1828  currentManager->Vertex( outerRadius * 3.0f / sqrt( 3.0f ), 0.0f, layerDepth ); // v1
1829 
1831  currentManager->Vertex( 0.0f, outerRadius * 2.0f, layerDepth ); // v2
1832 
1833  Restore();
1834 }
VERTEX_MANAGER * currentManager
Currently used VERTEX_MANAGER (for storing VERTEX_ITEMs)
Definition: opengl_gal.h:302
double layerDepth
The actual layer depth.
bool Reserve(unsigned int aSize)
Function Reserve() allocates space for vertices, so it will be used with subsequent Vertex() calls.
void Restore() override
Restore the context.
bool Vertex(const VERTEX &aVertex)
Function Vertex() adds a vertex with the given coordinates to the currently set item.
void Rotate(GLfloat aAngle, GLfloat aX, GLfloat aY, GLfloat aZ)
Function Rotate() multiplies the current matrix by a rotation matrix, so the newly vertices will be r...
void Save() override
Save the context.
void Translate(GLfloat aX, GLfloat aY, GLfloat aZ)
Function Translate() multiplies the current matrix by a translation matrix, so newly vertices will be...
float lineWidth
The line width.
void Shader(GLfloat aShaderType, GLfloat aParam1=0.0f, GLfloat aParam2=0.0f, GLfloat aParam3=0.0f)
Function Shader() changes currently used shader and its parameters that will be applied to newly adde...

References currentManager, KIGFX::GAL::layerDepth, KIGFX::GAL::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

Draws a set of polygons with a cached triangulation.

Way faster than drawPolygon.

Definition at line 1033 of file opengl_gal.cpp.

1034 {
1037 
1038  if( isFillEnabled )
1039  {
1040  for( unsigned int j = 0; j < aPolySet.TriangulatedPolyCount(); ++j )
1041  {
1042  auto triPoly = aPolySet.TriangulatedPolygon( j );
1043 
1044  for( size_t i = 0; i < triPoly->GetTriangleCount(); i++ )
1045  {
1046  VECTOR2I a, b, c;
1047  triPoly->GetTriangle( i, a, b, c );
1048  currentManager->Vertex( a.x, a.y, layerDepth );
1049  currentManager->Vertex( b.x, b.y, layerDepth );
1050  currentManager->Vertex( c.x, c.y, layerDepth );
1051  }
1052  }
1053  }
1054 
1055  if( isStrokeEnabled )
1056  {
1057  for( int j = 0; j < aPolySet.OutlineCount(); ++j )
1058  {
1059  const auto& poly = aPolySet.Polygon( j );
1060 
1061  for( const auto& lc : poly )
1062  {
1063  DrawPolyline( lc );
1064  }
1065  }
1066  }
1067 
1068  if( ADVANCED_CFG::GetCfg().m_DrawTriangulationOutlines )
1069  {
1070  auto oldStrokeColor = strokeColor;
1071  double oldLayerDepth = layerDepth;
1072 
1073  SetLayerDepth( layerDepth - 1 );
1074  SetStrokeColor( COLOR4D( 0.0, 1.0, 0.2, 1.0 ) );
1075 
1076  for( unsigned int j = 0; j < aPolySet.TriangulatedPolyCount(); ++j )
1077  {
1078  auto triPoly = aPolySet.TriangulatedPolygon( j );
1079 
1080  for( size_t i = 0; i < triPoly->GetTriangleCount(); i++ )
1081  {
1082  VECTOR2I a, b, c;
1083  triPoly->GetTriangle( i, a, b, c );
1084  DrawLine( a, b );
1085  DrawLine( b, c );
1086  DrawLine( c, a );
1087  }
1088  }
1089 
1090  SetStrokeColor( oldStrokeColor );
1091  SetLayerDepth( oldLayerDepth );
1092  }
1093 }
VERTEX_MANAGER * currentManager
Currently used VERTEX_MANAGER (for storing VERTEX_ITEMs)
Definition: opengl_gal.h:302
double layerDepth
The actual layer depth.
bool Vertex(const VERTEX &aVertex)
Function Vertex() adds a vertex with the given coordinates to the currently set item.
double g
Green component.
Definition: color4d.h:375
COLOR4D fillColor
The fill color.
virtual void SetLayerDepth(double aLayerDepth)
Set the depth of the layer (position on the z-axis)
double b
Blue component.
Definition: color4d.h:376
double a
Alpha component.
Definition: color4d.h:377
bool isStrokeEnabled
Are the outlines stroked ?
COLOR4D strokeColor
The color of the outlines.
void DrawLine(const VECTOR2D &aStartPoint, const VECTOR2D &aEndPoint) override
Draw a line.
Definition: opengl_gal.cpp:644
void Color(const COLOR4D &aColor)
Function Color() changes currently used color that will be applied to newly added vertices.
bool isFillEnabled
Is filling of graphic objects enabled ?
void DrawPolyline(const std::deque< VECTOR2D > &aPointList) override
Draw a polyline.
Definition: opengl_gal.cpp:974
virtual void SetStrokeColor(const COLOR4D &aColor)
Set the stroke color.
static const ADVANCED_CFG & GetCfg()
Get the singleton instance's config, which is shared by all consumers of advanced config.
void Shader(GLfloat aShaderType, GLfloat aParam1=0.0f, GLfloat aParam2=0.0f, GLfloat aParam3=0.0f)
Function Shader() changes currently used shader and its parameters that will be applied to newly adde...
double r
Red component.
Definition: color4d.h:374
COLOR4D is the color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:100

References KIGFX::COLOR4D::a, KIGFX::COLOR4D::b, KIGFX::VERTEX_MANAGER::Color(), currentManager, DrawLine(), DrawPolyline(), KIGFX::GAL::fillColor, KIGFX::COLOR4D::g, ADVANCED_CFG::GetCfg(), KIGFX::GAL::isFillEnabled, KIGFX::GAL::isStrokeEnabled, KIGFX::GAL::layerDepth, SHAPE_POLY_SET::OutlineCount(), SHAPE_POLY_SET::Polygon(), KIGFX::COLOR4D::r, KIGFX::GAL::SetLayerDepth(), KIGFX::GAL::SetStrokeColor(), KIGFX::VERTEX_MANAGER::Shader(), KIGFX::SHADER_NONE, KIGFX::GAL::strokeColor, 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

Parameters passed to the GLU tesselator.

Reimplemented from KIGFX::GAL.

Definition at line 2227 of file opengl_gal.cpp.

2228 {
2229  cachedManager->EnableDepthTest( aEnabled );
2230  nonCachedManager->EnableDepthTest( aEnabled );
2231  overlayManager->EnableDepthTest( aEnabled );
2232 }
VERTEX_MANAGER * overlayManager
Container for storing overlaid VERTEX_ITEMs.
Definition: opengl_gal.h:305
VERTEX_MANAGER * nonCachedManager
Container for storing non-cached VERTEX_ITEMs.
Definition: opengl_gal.h:304
VERTEX_MANAGER * cachedManager
Container for storing cached VERTEX_ITEMs.
Definition: opengl_gal.h:303
void EnableDepthTest(bool aEnabled)
Function EnableDepthTest() Enables/disables Z buffer depth test.

References cachedManager, KIGFX::VERTEX_MANAGER::EnableDepthTest(), nonCachedManager, and overlayManager.

◆ endDrawing()

void OPENGL_GAL::endDrawing ( )
overrideprivatevirtual

Update handler for OpenGL settings

Reimplemented from KIGFX::GAL.

Definition at line 556 of file opengl_gal.cpp.

557 {
558  wxASSERT_MSG( isContextLocked, "What happened to the context lock?" );
559 
560 #ifdef __WXDEBUG__
561  PROF_COUNTER totalRealTime( "OPENGL_GAL::endDrawing()", true );
562 #endif /* __WXDEBUG__ */
563 
564  // Cached & non-cached containers are rendered to the same buffer
568 
569  // Overlay container is rendered to a different buffer
570  if( overlayBuffer )
573 
574  // Be sure that the framebuffer is not colorized (happens on specific GPU&drivers combinations)
575  glColor4d( 1.0, 1.0, 1.0, 1.0 );
576 
577  // Draw the remaining contents, blit the rendering targets to the screen, swap the buffers
579 
580  if( overlayBuffer )
582 
583  compositor->Present();
584  blitCursor();
585 
586  SwapBuffers();
587 
588 #ifdef __WXDEBUG__
589  totalRealTime.Stop();
590  wxLogTrace( "GAL_PROFILE", wxT( "OPENGL_GAL::endDrawing(): %.1f ms" ), totalRealTime.msecs() );
591 #endif /* __WXDEBUG__ */
592 }
virtual void DrawBuffer(unsigned int aBufferHandle) override
Function DrawBuffer() draws the selected buffer to the output buffer.
unsigned int overlayBuffer
Auxiliary rendering target (for menus etc.)
Definition: opengl_gal.h:310
VERTEX_MANAGER * overlayManager
Container for storing overlaid VERTEX_ITEMs.
Definition: opengl_gal.h:305
bool isContextLocked
Used for assertion checking.
Definition: opengl_gal.h:323
The class PROF_COUNTER is a small class to help profiling.
Definition: profile.h:44
VERTEX_MANAGER * nonCachedManager
Container for storing non-cached VERTEX_ITEMs.
Definition: opengl_gal.h:304
OPENGL_COMPOSITOR * compositor
Handles multiple rendering targets.
Definition: opengl_gal.h:308
virtual void Present() override
Function Present() Call this to present the output buffer to the screen.
unsigned int mainBuffer
Main rendering target.
Definition: opengl_gal.h:309
virtual void SetBuffer(unsigned int aBufferHandle) override
Function SetBuffer() sets the selected buffer as the rendering target.
void blitCursor()
Blits cursor into the current screen.
VERTEX_MANAGER * cachedManager
Container for storing cached VERTEX_ITEMs.
Definition: opengl_gal.h:303
void EndDrawing() const
Function EndDrawing() finishes drawing operations.

References blitCursor(), cachedManager, compositor, KIGFX::OPENGL_COMPOSITOR::DrawBuffer(), KIGFX::VERTEX_MANAGER::EndDrawing(), isContextLocked, mainBuffer, PROF_COUNTER::msecs(), nonCachedManager, overlayBuffer, overlayManager, KIGFX::OPENGL_COMPOSITOR::Present(), KIGFX::OPENGL_COMPOSITOR::SetBuffer(), and PROF_COUNTER::Stop().

◆ EndGroup()

void OPENGL_GAL::EndGroup ( )
overridevirtual

End the group.

Reimplemented from KIGFX::GAL.

Definition at line 1581 of file opengl_gal.cpp.

1582 {
1584  isGrouping = false;
1585 }
bool isGrouping
Was a group started?
Definition: opengl_gal.h:322
void FinishItem() const
Function FinishItem() does the cleaning after adding an item.
VERTEX_MANAGER * cachedManager
Container for storing cached VERTEX_ITEMs.
Definition: opengl_gal.h:303

References cachedManager, KIGFX::VERTEX_MANAGER::FinishItem(), and isGrouping.

◆ endUpdate()

void OPENGL_GAL::endUpdate ( )
overrideprivatevirtual

Reimplemented from KIGFX::GAL.

Definition at line 635 of file opengl_gal.cpp.

636 {
637  if( !isInitialized )
638  return;
639 
640  cachedManager->Unmap();
641 }
void Unmap()
Function Unmap() unmaps vertex buffer.
VERTEX_MANAGER * cachedManager
Container for storing cached VERTEX_ITEMs.
Definition: opengl_gal.h:303
bool isInitialized
Basic initialization flag, has to be done when the window is visible.
Definition: opengl_gal.h:320

References cachedManager, 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 1505 of file opengl_gal.cpp.

1506 {
1507  glFlush();
1508 }

◆ GetClearColor()

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

Definition at line 219 of file graphics_abstraction_layer.h.

220  {
221  return m_clearColor;
222  }

References KIGFX::GAL::m_clearColor.

◆ getCursorColor()

COLOR4D GAL::getCursorColor ( ) const
protectedinherited

Gets the actual cursor color to draw.

Definition at line 242 of file graphics_abstraction_layer.cpp.

243 {
244  auto color = cursorColor;
245 
246  // dim the cursor if it's only on because it was forced
247  // (this helps to provide a hint for active tools)
248  if( !isCursorEnabled )
249  {
250  color.a = color.a * 0.5;
251  }
252 
253  return color;
254 }
bool isCursorEnabled
Is the cursor enabled?
int color
Definition: DXF_plotter.cpp:60
COLOR4D cursorColor
Cursor color.

References color, KIGFX::GAL::cursorColor, and KIGFX::GAL::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 269 of file graphics_abstraction_layer.h.

270  {
271  return fillColor;
272  }
COLOR4D fillColor
The fill color.

References KIGFX::GAL::fillColor.

◆ GetGlyphSize()

◆ GetGridLineWidth()

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

Get the grid line width.

Returns
the grid line width

Definition at line 913 of file graphics_abstraction_layer.h.

914  {
915  return gridLineWidth;
916  }
float gridLineWidth
Line width of the grid.

References KIGFX::GAL::gridLineWidth.

◆ GetGridOrigin()

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

Definition at line 838 of file graphics_abstraction_layer.h.

839  {
840  return gridOrigin;
841  }
VECTOR2D gridOrigin
The grid origin.

References KIGFX::GAL::gridOrigin.

Referenced by EE_GRID_HELPER::GetOrigin(), and GRID_HELPER::GetOrigin().

◆ GetGridPoint()

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

Function GetGridPoint() 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 220 of file graphics_abstraction_layer.cpp.

221 {
222 #if 0
223  // This old code expects a non zero grid size, which can be wrong here.
224  return VECTOR2D( KiROUND( ( aPoint.x - gridOffset.x ) / gridSize.x ) * gridSize.x + gridOffset.x,
225  KiROUND( ( aPoint.y - gridOffset.y ) / gridSize.y ) * gridSize.y + gridOffset.y );
226 #else
227  // if grid size == 0.0 there is no grid, so use aPoint as grid reference position
228  double cx = gridSize.x > 0.0 ? KiROUND( ( aPoint.x - gridOffset.x ) / gridSize.x ) * gridSize.x + gridOffset.x
229  : aPoint.x;
230  double cy = gridSize.y > 0.0 ? KiROUND( ( aPoint.y - gridOffset.y ) / gridSize.y ) * gridSize.y + gridOffset.y
231  : aPoint.y;
232 
233  return VECTOR2D( cx, cy );
234 #endif
235 }
VECTOR2D gridOffset
The grid offset to compensate cursor position.
VECTOR2< double > VECTOR2D
Definition: vector2d.h:593
VECTOR2D gridSize
The grid size.
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 KIGFX::GAL::gridOffset, KIGFX::GAL::gridSize, KiROUND(), VECTOR2< T >::x, and VECTOR2< T >::y.

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

◆ GetGridSize()

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

Returns the grid size.

Returns
A vector containing the grid size in x and y direction.

Definition at line 865 of file graphics_abstraction_layer.h.

866  {
867  return gridSize;
868  }
VECTOR2D gridSize
The grid size.

References KIGFX::GAL::gridSize.

Referenced by COMMON_TOOLS::CursorControl(), DIALOG_BOARD_REANNOTATE::DIALOG_BOARD_REANNOTATE(), GRID_HELPER::GetGrid(), EE_GRID_HELPER::GetGrid(), EDA_DRAW_FRAME::GetNearestGridPosition(), COMMON_TOOLS::PanControl(), and EDA_DRAW_PANEL_GAL::SwitchBackend().

◆ GetGridSnapping()

◆ GetGridVisibility()

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

Definition at line 815 of file graphics_abstraction_layer.h.

815 { return gridVisibility; }
bool gridVisibility
Should the grid be shown.

References KIGFX::GAL::gridVisibility.

Referenced by EDA_DRAW_PANEL_GAL::SwitchBackend().

◆ GetHorizontalJustify()

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

Returns current text horizontal justification setting.

Definition at line 444 of file graphics_abstraction_layer.h.

445  {
447  }
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 644 of file graphics_abstraction_layer.h.

645  {
646  return lookAtPoint;
647  }
VECTOR2D lookAtPoint
Point to be looked at in world space.

References KIGFX::GAL::lookAtPoint.

◆ GetMaxDepth()

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

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

Definition at line 713 of file graphics_abstraction_layer.h.

714  {
715  return depthRange.y;
716  }
VECTOR2D depthRange
Range of the depth.

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

◆ GetMinDepth()

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

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

Definition at line 705 of file graphics_abstraction_layer.h.

706  {
707  return depthRange.x;
708  }
VECTOR2D depthRange
Range of the depth.

References KIGFX::GAL::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

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

2078 {
2079  wxASSERT_MSG( groups.size() < std::numeric_limits<unsigned int>::max(),
2080  wxT( "There are no free slots to store a group" ) );
2081 
2082  while( groups.find( groupCounter ) != groups.end() )
2083  {
2084  groupCounter++;
2085  }
2086 
2087  return groupCounter++;
2088 }
GROUPS_MAP groups
Stores informations about VBO objects (groups)
Definition: opengl_gal.h:300
unsigned int groupCounter
Counter used for generating keys for groups.
Definition: opengl_gal.h:301

References groupCounter, and groups.

Referenced by BeginGroup().

◆ GetRotation()

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

Get the rotation angle.

Returns
The rotation angle (radians).

Definition at line 684 of file graphics_abstraction_layer.h.

685  {
686  return rotation;
687  }
double rotation
Rotation transformation (radians)

References KIGFX::GAL::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 401 of file opengl_gal.cpp.

402 {
403  auto sf = GetScaleFactor();
404  return VECTOR2D( 2.0 / (double) ( screenSize.x * sf ), 2.0 / (double) ( screenSize.y * sf ) );
405 }
double GetScaleFactor() const
Get the current scale factor.
VECTOR2< double > VECTOR2D
Definition: vector2d.h:593
VECTOR2I screenSize
Screen size in screen coordinates.

References HIDPI_GL_CANVAS::GetScaleFactor(), KIGFX::GAL::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 580 of file graphics_abstraction_layer.h.

581  {
582  return screenWorldMatrix;
583  }
MATRIX3x3D screenWorldMatrix
Screen transformation.

References KIGFX::GAL::screenWorldMatrix.

Referenced by KIGFX::PCB_PAINTER::draw(), KIGFX::SCH_PAINTER::getShadowWidth(), 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 289 of file graphics_abstraction_layer.h.

290  {
291  return strokeColor;
292  }
COLOR4D strokeColor
The color of the outlines.

References KIGFX::GAL::strokeColor.

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

◆ GetStrokeFont()

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

Definition at line 331 of file graphics_abstraction_layer.h.

332  {
333  return strokeFont;
334  }
STROKE_FONT strokeFont
Instance of object that stores information about how to draw texts.

References KIGFX::GAL::strokeFont.

Referenced by EDA_TEXT::GetTextBox().

◆ GetTarget()

RENDER_TARGET OPENGL_GAL::GetTarget ( ) const
overridevirtual

Gets the currently used target for rendering.

Returns
The current rendering target.

Reimplemented from KIGFX::GAL.

Definition at line 1649 of file opengl_gal.cpp.

1650 {
1651  return currentTarget;
1652 }
RENDER_TARGET currentTarget
Current rendering target.
Definition: opengl_gal.h:311

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

175 {
176  // Compute the X and Y size of a given text.
177  // Because computeTextLineSize expects a one line text,
178  // aText is expected to be only one line text.
179  return strokeFont.computeTextLineSize( aText );
180 }
STROKE_FONT 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::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 462 of file graphics_abstraction_layer.h.

463  {
465  }
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().

◆ getWorldPixelSize()

double OPENGL_GAL::getWorldPixelSize ( ) const
private

Definition at line 394 of file opengl_gal.cpp.

395 {
396  auto matrix = GetScreenWorldMatrix();
397  return std::min( std::abs( matrix.GetScale().x ), std::abs( matrix.GetScale().y ) );
398 }
const MATRIX3x3D & GetScreenWorldMatrix() const
Get the screen <-> world transformation matrix.

References KIGFX::GAL::GetScreenWorldMatrix().

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

571  {
572  return worldScreenMatrix;
573  }
MATRIX3x3D worldScreenMatrix
World transformation.

References KIGFX::GAL::worldScreenMatrix.

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

◆ GetZoomFactor()

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

Get the zoom factor.

Returns
the zoom factor.

Definition at line 664 of file graphics_abstraction_layer.h.

665  {
666  return zoomFactor;
667  }
double zoomFactor
The zoom factor.

References KIGFX::GAL::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

Returns true if the target exists.

Parameters
aTargetis the target to be checked.

Reimplemented from KIGFX::GAL.

Definition at line 1686 of file opengl_gal.cpp.

1687 {
1688  switch( aTarget )
1689  {
1690  default:
1691  case TARGET_CACHED:
1692  case TARGET_NONCACHED:
1693  return true;
1694 
1695  case TARGET_OVERLAY:
1696  return ( overlayBuffer != 0 );
1697  }
1698 }
unsigned int overlayBuffer
Auxiliary rendering target (for menus etc.)
Definition: opengl_gal.h:310
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 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 2091 of file opengl_gal.cpp.

2092 {
2093 
2094  wxASSERT( IsShownOnScreen() );
2095 
2096  wxASSERT_MSG( isContextLocked, "This should only be called from within a locked context." );
2097 
2098 // IsDisplayAttr() handles WX_GL_{MAJOR,MINOR}_VERSION correctly only in 3.0.4
2099 // starting with 3.1.0 one should use wxGLContext::IsOk() (done by GL_CONTEXT_MANAGER)
2100 #if wxCHECK_VERSION( 3, 0, 3 ) and !wxCHECK_VERSION( 3, 1, 0 )
2101  const int attr[] = { WX_GL_MAJOR_VERSION, 2, WX_GL_MINOR_VERSION, 1, 0 };
2102 
2103  if( !IsDisplaySupported( attr ) )
2104  throw std::runtime_error( "OpenGL 2.1 or higher is required!" );
2105 #endif /* wxCHECK_VERSION( 3, 0, 3 ) */
2106 
2107  // Check correct initialization from the constructor
2108  if( !glMainContext )
2109  throw std::runtime_error( "Could not create the main OpenGL context" );
2110 
2111  if( !glPrivContext )
2112  throw std::runtime_error( "Could not create a private OpenGL context" );
2113 
2114  if( tesselator == NULL )
2115  throw std::runtime_error( "Could not create the tesselator" );
2116  // End initialzation checks
2117 
2118  GLenum err = glewInit();
2119 
2120  if( GLEW_OK != err )
2121  throw std::runtime_error( (const char*) glewGetErrorString( err ) );
2122 
2123  // Check the OpenGL version (minimum 2.1 is required)
2124  if( !GLEW_VERSION_2_1 )
2125  throw std::runtime_error( "OpenGL 2.1 or higher is required!" );
2126 
2127 #if defined (__LINUX__) // calling enableGlDebug crashes opengl on some OS (OSX and some Windows)
2128 #ifdef DEBUG
2129  if( GLEW_ARB_debug_output )
2130  enableGlDebug( true );
2131 #endif
2132 #endif
2133 
2134  // Framebuffers have to be supported
2135  if( !GLEW_EXT_framebuffer_object )
2136  throw std::runtime_error( "Framebuffer objects are not supported!" );
2137 
2138  // Vertex buffer has to be supported
2139  if( !GLEW_ARB_vertex_buffer_object )
2140  throw std::runtime_error( "Vertex buffer objects are not supported!" );
2141 
2142  // Prepare shaders
2144  throw std::runtime_error( "Cannot compile vertex shader!" );
2145 
2147  throw std::runtime_error( "Cannot compile fragment shader!" );
2148 
2149  if( !shader->IsLinked() && !shader->Link() )
2150  throw std::runtime_error( "Cannot link the shaders!" );
2151 
2152  // Check if video card supports textures big enough to fit the font atlas
2153  int maxTextureSize;
2154  glGetIntegerv( GL_MAX_TEXTURE_SIZE, &maxTextureSize );
2155 
2156  if( maxTextureSize < (int) font_image.width || maxTextureSize < (int) font_image.height )
2157  {
2158  // TODO implement software texture scaling
2159  // for bitmap fonts and use a higher resolution texture?
2160  throw std::runtime_error( "Requested texture size is not supported" );
2161  }
2162 
2164 
2165  cachedManager = new VERTEX_MANAGER( true );
2166  nonCachedManager = new VERTEX_MANAGER( false );
2167  overlayManager = new VERTEX_MANAGER( false );
2168 
2169  // Make VBOs use shaders
2173 
2174  isInitialized = true;
2175 }
bool IsLinked() const
Returns true if shaders are linked correctly.
Definition: shader.h:124
bool LoadShaderFromStrings(SHADER_TYPE aShaderType, Args &&... aArgs)
Add a shader and compile the shader sources.
Definition: shader.h:99
static wxGLContext * glMainContext
Parent OpenGL context.
Definition: opengl_gal.h:290
VERTEX_MANAGER * overlayManager
Container for storing overlaid VERTEX_ITEMs.
Definition: opengl_gal.h:305
bool isContextLocked
Used for assertion checking.
Definition: opengl_gal.h:323
Fragment shader.
Definition: shader.h:47
bool Link()
Link the shaders.
Definition: shader.cpp:97
SHADER * shader
There is only one shader used for different objects.
Definition: opengl_gal.h:314
void enableGlDebug(bool aEnable)
Enables/disables OpenGL driver messages output.
Definition: utils.cpp:142
VERTEX_MANAGER * nonCachedManager
Container for storing non-cached VERTEX_ITEMs.
Definition: opengl_gal.h:304
#define NULL
void SetShader(SHADER &aShader) const
Function SetShader() sets a shader program that is going to be used during rendering.
FONT_IMAGE_TYPE font_image
Definition: gl_resources.cpp:4
Vertex shader.
Definition: shader.h:46
GLUtesselator * tesselator
The tessellator.
Definition: opengl_gal.h:352
VERTEX_MANAGER * cachedManager
Container for storing cached VERTEX_ITEMs.
Definition: opengl_gal.h:303
bool isInitialized
Basic initialization flag, has to be done when the window is visible.
Definition: opengl_gal.h:320
wxGLContext * glPrivContext
Canvas-specific OpenGL context.
Definition: opengl_gal.h:291
static int SetSwapInterval(int aVal)
Attempts to set the OpenGL swap interval.
Definition: gl_utils.h:41

References cachedManager, enableGlDebug(), KIGFX::BUILTIN_FONT::font_image, glMainContext, glPrivContext, KIGFX::BUILTIN_FONT::FONT_IMAGE_TYPE::height, isContextLocked, isInitialized, KIGFX::SHADER::IsLinked(), KIGFX::BUILTIN_SHADERS::kicad_fragment_shader, KIGFX::BUILTIN_SHADERS::kicad_vertex_shader, KIGFX::SHADER::Link(), KIGFX::SHADER::LoadShaderFromStrings(), nonCachedManager, NULL, overlayManager, KIGFX::VERTEX_MANAGER::SetShader(), GL_UTILS::SetSwapInterval(), shader, KIGFX::SHADER_TYPE_FRAGMENT, KIGFX::SHADER_TYPE_VERTEX, tesselator, and KIGFX::BUILTIN_FONT::FONT_IMAGE_TYPE::width.

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

◆ IsCairoEngine()

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

Returns true if the GAL engine is a cairo based type.

Reimplemented in KIGFX::CAIRO_GAL_BASE.

Definition at line 79 of file graphics_abstraction_layer.h.

79 { return false; }

Referenced by getShadowLayer().

◆ IsCursorEnabled()

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

Returns information about cursor visibility.

Returns
True if cursor is visible.

Definition at line 966 of file graphics_abstraction_layer.h.

967  {
969  }
bool isCursorEnabled
Is the cursor enabled?
bool forceDisplayCursor
Always show cursor.

References KIGFX::GAL::forceDisplayCursor, and KIGFX::GAL::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 751 of file graphics_abstraction_layer.h.

752  {
753  return globalFlipY;
754  }
bool globalFlipY
Flag for Y axis flipping.

References KIGFX::GAL::globalFlipY.

◆ IsFontBold()

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

Definition at line 410 of file graphics_abstraction_layer.h.

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

Returns the initalization status for the canvas.

Reimplemented from KIGFX::GAL.

Definition at line 99 of file opengl_gal.h.

100  {
101  // is*Initialized flags, but it is enough for OpenGL to show up
102  return IsShownOnScreen() && !GetClientRect().IsEmpty();
103  }

◆ IsOpenGlEngine()

bool KIGFX::OPENGL_GAL::IsOpenGlEngine ( )
inlineoverridevirtual

Returns 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

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

◆ lockContext()

void OPENGL_GAL::lockContext ( int  aClientCookie)
overrideprivatevirtual

Private: use GAL_CONTEXT_LOCKER RAII object.

Reimplemented from KIGFX::GAL.

Definition at line 595 of file opengl_gal.cpp.

596 {
597  wxASSERT_MSG( !isContextLocked, "Context already locked." );
598  isContextLocked = true;
599  lockClientCookie = aClientCookie;
600 
602 }
bool isContextLocked
Used for assertion checking.
Definition: opengl_gal.h:323
static GL_CONTEXT_MANAGER & Get()
Function Get returns the GL_CONTEXT_MANAGER instance (singleton).
void LockCtx(wxGLContext *aContext, wxGLCanvas *aCanvas)
Function LockCtx sets a context as current and prevents other canvases from switching it.
wxGLContext * glPrivContext
Canvas-specific OpenGL context.
Definition: opengl_gal.h:291

References GL_CONTEXT_MANAGER::Get(), glPrivContext, isContextLocked, lockClientCookie, and GL_CONTEXT_MANAGER::LockCtx().

◆ OnGalDisplayOptionsChanged()

void GAL::OnGalDisplayOptionsChanged ( const GAL_DISPLAY_OPTIONS aOptions)
overrideprotectedvirtualinherited

Handler for observer settings changes.

Implements KIGFX::GAL_DISPLAY_OPTIONS_OBSERVER.

Definition at line 92 of file graphics_abstraction_layer.cpp.

93 {
94  // defer to the child class first
95  updatedGalDisplayOptions( aOptions );
96 
97  // there is no refresh to do at this level
98 }
virtual bool updatedGalDisplayOptions(const GAL_DISPLAY_OPTIONS &aOptions)
Function updatedGalDisplayOptions.

References KIGFX::GAL::updatedGalDisplayOptions().

◆ onPaint()

void OPENGL_GAL::onPaint ( wxPaintEvent &  aEvent)
private

This is the OnPaint event handler.

Parameters
aEventis the OnPaint event.

Definition at line 2031 of file opengl_gal.cpp.

2032 {
2033  PostPaint( aEvent );
2034 }
void PostPaint(wxPaintEvent &aEvent)
Function PostPaint posts an event to m_paint_listener.
Definition: opengl_gal.cpp:357

References PostPaint().

Referenced by OPENGL_GAL().

◆ PopDepth()

void KIGFX::GAL::PopDepth ( )
inlineinherited

Restores previously stored drawing depth for the depth stack.

Definition at line 1008 of file graphics_abstraction_layer.h.

1009  {
1010  layerDepth = depthStack.top();
1011  depthStack.pop();
1012  }
double layerDepth
The actual layer depth.
std::stack< double > depthStack
Stored depth values.

References KIGFX::GAL::depthStack, and KIGFX::GAL::layerDepth.

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

◆ PostPaint()

void OPENGL_GAL::PostPaint ( wxPaintEvent &  aEvent)

Function PostPaint posts an event to m_paint_listener.

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

Definition at line 357 of file opengl_gal.cpp.

358 {
359  // posts an event to m_paint_listener to ask for redraw the canvas.
360  if( paintListener )
361  {
362  wxPostEvent( paintListener, aEvent );
363  }
364 }
wxEvtHandler * paintListener
Definition: opengl_gal.h:294

References paintListener.

Referenced by onPaint().

◆ PushDepth()

void KIGFX::GAL::PushDepth ( )
inlineinherited

Stores current drawing depth on the depth stack.

Definition at line 1000 of file graphics_abstraction_layer.h.

1001  {
1002  depthStack.push( layerDepth );
1003  }
double layerDepth
The actual layer depth.
std::stack< double > depthStack
Stored depth values.

References KIGFX::GAL::depthStack, and KIGFX::GAL::layerDepth.

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

◆ ResetTextAttributes()

void GAL::ResetTextAttributes ( )
inherited

Reset text attributes to default styling.

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

Definition at line 158 of file graphics_abstraction_layer.cpp.

159 {
160  // Tiny but non-zero - this will always need setting
161  // there is no built-in default
162  SetGlyphSize( { 1.0, 1.0 } );
163 
166 
167  SetFontBold( false );
168  SetFontItalic( false );
169  SetFontUnderlined( false );
170  SetTextMirrored( false );
171 }
void SetFontBold(const bool aBold)
Set bold property of current font.
void SetTextMirrored(const bool aMirrored)
Set a mirrored property of text.
void SetVerticalJustify(const EDA_TEXT_VJUSTIFY_T aVerticalJustify)
Set the vertical justify for text drawing.
void SetFontItalic(bool aItalic)
Set italic property of current font.
void SetGlyphSize(const VECTOR2D aSize)
Set the font glyph size.
void SetFontUnderlined(bool aUnderlined)
void SetHorizontalJustify(const EDA_TEXT_HJUSTIFY_T aHorizontalJustify)
Set the horizontal justify for text drawing.

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

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

◆ ResizeScreen()

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

Resizes the canvas.

Reimplemented from KIGFX::GAL.

Definition at line 1481 of file opengl_gal.cpp.

1482 {
1483  screenSize = VECTOR2I( aWidth, aHeight );
1484 
1485  // Resize framebuffers
1486  const float scaleFactor = GetScaleFactor();
1487  compositor->Resize( aWidth * scaleFactor, aHeight * scaleFactor );
1488  isFramebufferInitialized = false;
1489 
1490  wxGLCanvas::SetSize( aWidth, aHeight );
1491 }
double GetScaleFactor() const
Get the current scale factor.
VECTOR2< int > VECTOR2I
Definition: vector2d.h:594
OPENGL_COMPOSITOR * compositor
Handles multiple rendering targets.
Definition: opengl_gal.h:308