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

More...
 
virtual void DrawLine (const VECTOR2D &aStartPoint, const VECTOR2D &aEndPoint) override
 Draw a line. More...
 
virtual void DrawSegment (const VECTOR2D &aStartPoint, const VECTOR2D &aEndPoint, double aWidth) override
 Draw a rounded segment. More...
 
virtual void DrawCircle (const VECTOR2D &aCenterPoint, double aRadius) override
 Draw a circle using world coordinates. More...
 
virtual void DrawArc (const VECTOR2D &aCenterPoint, double aRadius, double aStartAngle, double aEndAngle) override
 Draw an arc. More...
 
virtual void DrawArcSegment (const VECTOR2D &aCenterPoint, double aRadius, double aStartAngle, double aEndAngle, double aWidth) override
 Draw an arc segment. More...
 
virtual void DrawRectangle (const VECTOR2D &aStartPoint, const VECTOR2D &aEndPoint) override
 Draw a rectangle. More...
 
virtual void DrawPolyline (const std::deque< VECTOR2D > &aPointList) override
 Draw a polyline. More...
 
virtual void DrawPolyline (const VECTOR2D aPointList[], int aListSize) override
 
virtual void DrawPolyline (const SHAPE_LINE_CHAIN &aLineChain) override
 
virtual void DrawPolygon (const std::deque< VECTOR2D > &aPointList) override
 Draw a polygon. More...
 
virtual void DrawPolygon (const VECTOR2D aPointList[], int aListSize) override
 
virtual void DrawPolygon (const SHAPE_POLY_SET &aPolySet) override
 
virtual void DrawPolygon (const SHAPE_LINE_CHAIN &aPolySet) override
 
virtual void DrawCurve (const VECTOR2D &startPoint, const VECTOR2D &controlPointA, const VECTOR2D &controlPointB, const VECTOR2D &endPoint) override
 Draw a cubic bezier spline. More...
 
virtual void DrawBitmap (const BITMAP_BASE &aBitmap) override
 Draw a bitmap image. More...
 
virtual void BitmapText (const wxString &aText, const VECTOR2D &aPosition, double aRotationAngle) override
 Draws a text using a bitmap font. More...
 
virtual void DrawGrid () override
 

More...
 
virtual void ResizeScreen (int aWidth, int aHeight) override
 Resizes the canvas. More...
 
virtual bool Show (bool aShow) override
 Shows/hides the GAL canvas. More...
 
virtual void Flush () override
 Force all remaining objects to be drawn. More...
 
virtual void ClearScreen () override
 Clear the screen. More...
 
virtual void Transform (const MATRIX3x3D &aTransformation) override
 Transform the context. More...
 
virtual void Rotate (double aAngle) override
 Rotate the context. More...
 
virtual void Translate (const VECTOR2D &aTranslation) override
 Translate the context. More...
 
virtual void Scale (const VECTOR2D &aScale) override
 Scale the context. More...
 
virtual void Save () override
 Save the context. More...
 
virtual void Restore () override
 Restore the context. More...
 
virtual int BeginGroup () override
 Begin a group. More...
 
virtual void EndGroup () override
 End the group. More...
 
virtual void DrawGroup (int aGroupNumber) override
 Draw the stored group. More...
 
virtual void ChangeGroupColor (int aGroupNumber, const COLOR4D &aNewColor) override
 Changes the color used to draw the group. More...
 
virtual void ChangeGroupDepth (int aGroupNumber, int aDepth) override
 Changes the depth (Z-axis position) of the group. More...
 
virtual void DeleteGroup (int aGroupNumber) override
 Delete the group from the memory. More...
 
virtual void ClearCache () override
 Delete all data created during caching of graphic items. More...
 
virtual void SaveScreen () override
 Save the screen contents. More...
 
virtual void RestoreScreen () override
 Restore the screen contents. More...
 
virtual void SetTarget (RENDER_TARGET aTarget) override
 Sets the target for rendering. More...
 
virtual RENDER_TARGET GetTarget () const override
 Gets the currently used target for rendering. More...
 
virtual void ClearTarget (RENDER_TARGET aTarget) override
 Clears the target for rendering. More...
 
virtual void SetNegativeDrawMode (bool aSetting) override
 Sets negative draw mode in the renderer. More...
 
virtual void ComputeWorldScreenMatrix () override
 Compute the world <-> screen transformation matrix. More...
 
virtual void DrawCursor (const VECTOR2D &aCursorPosition) override
 Draw the cursor. More...
 
void PostPaint ()
 Function PostPaint posts an event to m_paint_listener. More...
 
void SetMouseListener (wxEvtHandler *aMouseListener)
 
void SetPaintListener (wxEvtHandler *aPaintListener)
 
virtual 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...
 
double GetOverbarVerticalPosition () const
 Compute the vertical position of an overbar, sometimes used in texts. 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 aGlyphSize)
 Set the font glyph size. More...
 
const VECTOR2DGetGlyphSize () const
 
void SetFontBold (const bool aBold)
 Set bold property of current font. More...
 
bool IsFontBold () const
 Returns true if current font has 'bold' attribute enabled. More...
 
void SetFontItalic (const bool aItalic)
 Set italic property of current font. More...
 
bool IsFontItalic () const
 Returns true if current font has 'italic' attribute enabled. More...
 
void SetTextMirrored (const bool aMirrored)
 Set a mirrored property of text. More...
 
bool IsTextMirrored () const
 Returns true if text should displayed mirrored. More...
 
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...
 
void SetGridOrigin (const VECTOR2D &aGridOrigin)
 Set the origin point for the grid. More...
 
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
 
virtual float GetBackingScaleFactor () 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...
 

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
 
virtual void beginUpdate () override
 
virtual void endUpdate () override
 
virtual void beginDrawing () override
 
virtual 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. 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 300 of file opengl_gal.h.

◆ super

typedef GAL KIGFX::OPENGL_GAL::super
private

Super class definition.

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

185  :
186  GAL( aDisplayOptions ),
187  HIDPI_GL_CANVAS( aParent, wxID_ANY, (int*) glAttributes, wxDefaultPosition, wxDefaultSize,
188  wxEXPAND, aName ),
189  mouseListener( aMouseListener ),
190  paintListener( aPaintListener ),
191  currentManager( nullptr ),
192  cachedManager( nullptr ),
193  nonCachedManager( nullptr ),
194  overlayManager( nullptr ),
195  mainBuffer( 0 ),
196  overlayBuffer( 0 ),
197  isContextLocked( false ),
198  lockClientCookie( 0 )
199 {
200 // IsDisplayAttr() handles WX_GL_{MAJOR,MINOR}_VERSION correctly only in 3.0.4
201 // starting with 3.1.0 one should use wxGLContext::IsOk() (done by GL_CONTEXT_MANAGER)
202 #if wxCHECK_VERSION( 3, 0, 3 ) and !wxCHECK_VERSION( 3, 1, 0 )
203  const int attr[] = { WX_GL_MAJOR_VERSION, 2, WX_GL_MINOR_VERSION, 1, 0 };
204 
205  if( !IsDisplaySupported( attr ) )
206  throw std::runtime_error( "OpenGL 2.1 or higher is required!" );
207 #endif /* wxCHECK_VERSION( 3, 0, 3 ) */
208 
209  if( glMainContext == NULL )
210  {
212 
213  if( !glMainContext )
214  throw std::runtime_error( "Could not create the main OpenGL context" );
215 
217  }
218  else
219  {
221 
222  if( !glPrivContext )
223  throw std::runtime_error( "Could not create a private OpenGL context" );
224  }
225 
226  shader = new SHADER();
227  ++instanceCounter;
228 
229  bitmapCache.reset( new GL_BITMAP_CACHE );
230 
233 
234  // Initialize the flags
235  isFramebufferInitialized = false;
236  isBitmapFontInitialized = false;
237  isInitialized = false;
238  isGrouping = false;
239  groupCounter = 0;
240 
241  // Connecting the event handlers
242  Connect( wxEVT_PAINT, wxPaintEventHandler( OPENGL_GAL::onPaint ) );
243 
244  // Mouse events are skipped to the parent
245  Connect( wxEVT_MOTION, wxMouseEventHandler( OPENGL_GAL::skipMouseEvent ) );
246  Connect( wxEVT_LEFT_DOWN, wxMouseEventHandler( OPENGL_GAL::skipMouseEvent ) );
247  Connect( wxEVT_LEFT_UP, wxMouseEventHandler( OPENGL_GAL::skipMouseEvent ) );
248  Connect( wxEVT_LEFT_DCLICK, wxMouseEventHandler( OPENGL_GAL::skipMouseEvent ) );
249  Connect( wxEVT_MIDDLE_DOWN, wxMouseEventHandler( OPENGL_GAL::skipMouseEvent ) );
250  Connect( wxEVT_MIDDLE_UP, wxMouseEventHandler( OPENGL_GAL::skipMouseEvent ) );
251  Connect( wxEVT_MIDDLE_DCLICK, wxMouseEventHandler( OPENGL_GAL::skipMouseEvent ) );
252  Connect( wxEVT_RIGHT_DOWN, wxMouseEventHandler( OPENGL_GAL::skipMouseEvent ) );
253  Connect( wxEVT_RIGHT_UP, wxMouseEventHandler( OPENGL_GAL::skipMouseEvent ) );
254  Connect( wxEVT_RIGHT_DCLICK, wxMouseEventHandler( OPENGL_GAL::skipMouseEvent ) );
255  Connect( wxEVT_MOUSEWHEEL, wxMouseEventHandler( OPENGL_GAL::skipMouseEvent ) );
256 #if wxCHECK_VERSION( 3, 1, 0 ) || defined( USE_OSX_MAGNIFY_EVENT )
257  Connect( wxEVT_MAGNIFY, wxMouseEventHandler( OPENGL_GAL::skipMouseEvent ) );
258 #endif
259 #if defined _WIN32 || defined _WIN64
260  Connect( wxEVT_ENTER_WINDOW, wxMouseEventHandler( OPENGL_GAL::skipMouseEvent ) );
261 #endif
262 
263  SetSize( aParent->GetClientSize() );
265 
266  // Grid color settings are different in Cairo and OpenGL
267  SetGridColor( COLOR4D( 0.8, 0.8, 0.8, 0.1 ) );
268  SetAxesColor( COLOR4D( BLUE ) );
269 
270  // Tesselator initialization
271  tesselator = gluNewTess();
273 
274  if( tesselator == NULL )
275  throw std::runtime_error( "Could not create the tesselator" );
276 
277  gluTessProperty( tesselator, GLU_TESS_WINDING_RULE, GLU_TESS_WINDING_POSITIVE );
278 
280 }
Definition: colors.h:57
virtual wxSize GetNativePixelSize() const
VERTEX_MANAGER * currentManager
Currently used VERTEX_MANAGER (for storing VERTEX_ITEMs)
Definition: opengl_gal.h:303
static wxGLContext * glMainContext
Parent OpenGL context.
Definition: opengl_gal.h:291
unsigned int overlayBuffer
Auxiliary rendering target (for menus etc.)
Definition: opengl_gal.h:311
bool isBitmapFontInitialized
Is the shader set to use bitmap fonts?
Definition: opengl_gal.h:320
VERTEX_MANAGER * overlayManager
Container for storing overlaid VERTEX_ITEMs.
Definition: opengl_gal.h:306
GAL_DISPLAY_OPTIONS & options
std::unique_ptr< GL_BITMAP_CACHE > bitmapCache
Definition: opengl_gal.h:330
static void InitTesselatorCallbacks(GLUtesselator *aTesselator)
bool isContextLocked
Used for assertion checking.
Definition: opengl_gal.h:324
SHADER * shader
There is only one shader used for different objects.
Definition: opengl_gal.h:315
VECTOR2< int > VECTOR2I
Definition: vector2d.h:587
bool isGrouping
Was a group started?
Definition: opengl_gal.h:323
OPENGL_ANTIALIASING_MODE gl_antialiasing_mode
VERTEX_MANAGER * nonCachedManager
Container for storing non-cached VERTEX_ITEMs.
Definition: opengl_gal.h:305
Auxiliary rendering target (noncached)
Definition: definitions.h:49
static int instanceCounter
GL GAL instance counter.
Definition: opengl_gal.h:293
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:309
unsigned int mainBuffer
Main rendering target.
Definition: opengl_gal.h:310
wxEvtHandler * mouseListener
Definition: opengl_gal.h:294
void SetAxesColor(const COLOR4D &aAxesColor)
Set the axes color.
static const int glAttributes[]
Definition: opengl_gal.cpp:66
void onPaint(wxPaintEvent &aEvent)
This is the OnPaint event handler.
bool isFramebufferInitialized
Are the framebuffers initialized?
Definition: opengl_gal.h:318
Class SHADER provides the access to the OpenGL shaders.
Definition: shader.h:76
GLUtesselator * tesselator
The tessellator.
Definition: opengl_gal.h:353
VERTEX_MANAGER * cachedManager
Container for storing cached VERTEX_ITEMs.
Definition: opengl_gal.h:304
wxEvtHandler * paintListener
Definition: opengl_gal.h:295
virtual void SetTarget(RENDER_TARGET aTarget) override
Sets the target for rendering.
bool isInitialized
Basic initialization flag, has to be done when the window is visible.
Definition: opengl_gal.h:321
unsigned int groupCounter
Counter used for generating keys for groups.
Definition: opengl_gal.h:302
VECTOR2I screenSize
Screen size in screen coordinates.
wxGLContext * glPrivContext
Canvas-specific OpenGL context.
Definition: opengl_gal.h:292
wxGLContext * CreateCtx(wxGLCanvas *aCanvas, const wxGLContext *aOther=NULL)
Function CreateCtx creates a managed OpenGL context.
void skipMouseEvent(wxMouseEvent &aEvent)
Skip the mouse event to the parent.
Class COLOR4D is the color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:39

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, onPaint(), KIGFX::GAL::options, KIGFX::GAL::screenSize, KIGFX::OPENGL_COMPOSITOR::SetAntialiasingMode(), KIGFX::GAL::SetAxesColor(), KIGFX::GAL::SetGridColor(), SetTarget(), shader, skipMouseEvent(), KIGFX::TARGET_NONCACHED, and tesselator.

◆ ~OPENGL_GAL()

OPENGL_GAL::~OPENGL_GAL ( )
virtual

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 
323  glMainContext = NULL;
324  }
325 }
static wxGLContext * glMainContext
Parent OpenGL context.
Definition: opengl_gal.h:291
static GLuint fontTexture
Bitmap font texture handle (shared)
Definition: opengl_gal.h:297
VERTEX_MANAGER * overlayManager
Container for storing overlaid VERTEX_ITEMs.
Definition: opengl_gal.h:306
SHADER * shader
There is only one shader used for different objects.
Definition: opengl_gal.h:315
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:305
static int instanceCounter
GL GAL instance counter.
Definition: opengl_gal.h:293
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:309
virtual void ClearCache() override
Delete all data created during caching of graphic items.
GLUtesselator * tesselator
The tessellator.
Definition: opengl_gal.h:353
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:304
bool isInitialized
Basic initialization flag, has to be done when the window is visible.
Definition: opengl_gal.h:321
wxGLContext * glPrivContext
Canvas-specific OpenGL context.
Definition: opengl_gal.h:292
void DestroyCtx(wxGLContext *aContext)
Function DestroyCtx destroys a managed OpenGL context.
static bool isBitmapFontLoaded
Is the bitmap font texture loaded?
Definition: opengl_gal.h:319

References cachedManager, ClearCache(), compositor, GL_CONTEXT_MANAGER::DestroyCtx(), fontTexture, GL_CONTEXT_MANAGER::Get(), glMainContext, glPrivContext, instanceCounter, isBitmapFontLoaded, isInitialized, GL_CONTEXT_MANAGER::LockCtx(), nonCachedManager, 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 1022 of file graphics_abstraction_layer.h.

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

370 {
371 #ifdef __WXDEBUG__
372  PROF_COUNTER totalRealTime( "OPENGL_GAL::beginDrawing()", true );
373 #endif /* __WXDEBUG__ */
374 
375  wxASSERT_MSG( isContextLocked, "GAL_DRAWING_CONTEXT RAII object should have locked context. "
376  "Calling GAL::beginDrawing() directly is not allowed." );
377 
378  wxASSERT_MSG( IsVisible(), "GAL::beginDrawing() must not be entered when GAL is not visible. "
379  "Other drawing routines will expect everything to be initialized "
380  "which will not be the case." );
381 
382  if( !isInitialized )
383  init();
384 
385  // Set up the view port
386  glMatrixMode( GL_PROJECTION );
387  glLoadIdentity();
388 
389  // Create the screen transformation (Do the RH-LH conversion here)
390  glOrtho( 0, (GLint) screenSize.x, (GLsizei) screenSize.y, 0, -depthRange.x, -depthRange.y );
391 
393  {
394  // Prepare rendering target buffers
398 
400  }
401 
402  compositor->Begin();
403 
404  // Disable 2D Textures
405  glDisable( GL_TEXTURE_2D );
406 
407  glShadeModel( GL_FLAT );
408 
409  // Enable the depth buffer
410  glEnable( GL_DEPTH_TEST );
411  glDepthFunc( GL_LESS );
412 
413  // Setup blending, required for transparent objects
414  glEnable( GL_BLEND );
415  glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );
416 
417  glMatrixMode( GL_MODELVIEW );
418 
419  // Set up the world <-> screen transformation
421  GLdouble matrixData[16] = { 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1 };
422  matrixData[0] = worldScreenMatrix.m_data[0][0];
423  matrixData[1] = worldScreenMatrix.m_data[1][0];
424  matrixData[2] = worldScreenMatrix.m_data[2][0];
425  matrixData[4] = worldScreenMatrix.m_data[0][1];
426  matrixData[5] = worldScreenMatrix.m_data[1][1];
427  matrixData[6] = worldScreenMatrix.m_data[2][1];
428  matrixData[12] = worldScreenMatrix.m_data[0][2];
429  matrixData[13] = worldScreenMatrix.m_data[1][2];
430  matrixData[14] = worldScreenMatrix.m_data[2][2];
431  glLoadMatrixd( matrixData );
432 
433  // Set defaults
436 
437  // Remove all previously stored items
440 
444 
446  {
447  // Keep bitmap font texture always bound to the second texturing unit
448  const GLint FONT_TEXTURE_UNIT = 2;
449 
450  // Either load the font atlas to video memory, or simply bind it to a texture unit
451  if( !isBitmapFontLoaded )
452  {
453  glActiveTexture( GL_TEXTURE0 + FONT_TEXTURE_UNIT );
454  glGenTextures( 1, &fontTexture );
455  glBindTexture( GL_TEXTURE_2D, fontTexture );
456  glTexImage2D( GL_TEXTURE_2D, 0, GL_RGB8, font_image.width, font_image.height,
457  0, GL_RGB, GL_UNSIGNED_BYTE, font_image.pixels );
458  glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
459  glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
460  checkGlError( "loading bitmap font" );
461 
462  glActiveTexture( GL_TEXTURE0 );
463 
464  isBitmapFontLoaded = true;
465  }
466  else
467  {
468  glActiveTexture( GL_TEXTURE0 + FONT_TEXTURE_UNIT );
469  glBindTexture( GL_TEXTURE_2D, fontTexture );
470  glActiveTexture( GL_TEXTURE0 );
471  }
472 
473  // Set shader parameter
474  GLint ufm_fontTexture = shader->AddParameter( "fontTexture" );
475  GLint ufm_fontTextureWidth = shader->AddParameter( "fontTextureWidth" );
476  ufm_worldPixelSize = shader->AddParameter( "worldPixelSize" );
477  ufm_screenPixelSize = shader->AddParameter( "screenPixelSize" );
478  ufm_pixelSizeMultiplier = shader->AddParameter( "pixelSizeMultiplier" );
479 
480  shader->Use();
481  shader->SetParameter( ufm_fontTexture, (int) FONT_TEXTURE_UNIT );
482  shader->SetParameter( ufm_fontTextureWidth, (int) font_image.width );
483  shader->Deactivate();
484  checkGlError( "setting bitmap font sampler as shader parameter" );
485 
487  }
488 
489  shader->Use();
492  double pixelSizeMultiplier = compositor->GetAntialiasSupersamplingFactor();
493  shader->SetParameter( ufm_pixelSizeMultiplier, (float) pixelSizeMultiplier );
494  shader->Deactivate();
495 
496  // Something betreen BeginDrawing and EndDrawing seems to depend on
497  // this texture unit being active, but it does not assure it itself.
498  glActiveTexture( GL_TEXTURE0 );
499 
500  // Unbind buffers - set compositor for direct drawing
502 
503 #ifdef __WXDEBUG__
504  totalRealTime.Stop();
505  wxLogTrace( "GAL_PROFILE", wxT( "OPENGL_GAL::beginDrawing(): %.1f ms" ), totalRealTime.msecs() );
506 #endif /* __WXDEBUG__ */
507 }
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:311
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:320
void Use()
Use the shader.
Definition: shader.h:132
static GLuint fontTexture
Bitmap font texture handle (shared)
Definition: opengl_gal.h:297
VERTEX_MANAGER * overlayManager
Container for storing overlaid VERTEX_ITEMs.
Definition: opengl_gal.h:306
VECTOR2D getScreenPixelSize() const
Definition: opengl_gal.cpp:362
virtual 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:138
bool isContextLocked
Used for assertion checking.
Definition: opengl_gal.h:324
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:30
SHADER * shader
There is only one shader used for different objects.
Definition: opengl_gal.h:315
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:305
T m_data[3][3]
Definition: matrix3x3.h:64
double getWorldPixelSize() const
Definition: opengl_gal.cpp:355
void init()
Basic OpenGL initialization.
OPENGL_COMPOSITOR * compositor
Handles multiple rendering targets.
Definition: opengl_gal.h:309
unsigned int mainBuffer
Main rendering target.
Definition: opengl_gal.h:310
COLOR4D strokeColor
The color of the outlines.
int AddParameter(const std::string &aParameterName)
Add a parameter to the parameter queue.
Definition: shader.cpp:125
GLint ufm_screenPixelSize
Definition: opengl_gal.h:327
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:318
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:304
virtual void Initialize() override
Function Reset() performs primary initialiation, necessary to use the object.
GLint ufm_worldPixelSize
Definition: opengl_gal.h:326
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:321
virtual float GetBackingScaleFactor() const
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:99
GLint ufm_pixelSizeMultiplier
Definition: opengl_gal.h:328
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:319

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::GetBackingScaleFactor(), 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 1471 of file opengl_gal.cpp.

1472 {
1473  isGrouping = true;
1474 
1475  std::shared_ptr<VERTEX_ITEM> newItem = std::make_shared<VERTEX_ITEM>( *cachedManager );
1476  int groupNumber = getNewGroupNumber();
1477  groups.insert( std::make_pair( groupNumber, newItem ) );
1478 
1479  return groupNumber;
1480 }
bool isGrouping
Was a group started?
Definition: opengl_gal.h:323
GROUPS_MAP groups
Stores informations about VBO objects (groups)
Definition: opengl_gal.h:301
VERTEX_MANAGER * cachedManager
Container for storing cached VERTEX_ITEMs.
Definition: opengl_gal.h:304
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 569 of file opengl_gal.cpp.

570 {
571  wxASSERT_MSG( isContextLocked, "GAL_UPDATE_CONTEXT RAII object should have locked context. "
572  "Calling this from anywhere else is not allowed." );
573 
574  wxASSERT_MSG( IsVisible(), "GAL::beginUpdate() must not be entered when GAL is not visible. "
575  "Other update routines will expect everything to be initialized "
576  "which will not be the case." );
577 
578  if( !isInitialized )
579  init();
580 
581  cachedManager->Map();
582 }
bool isContextLocked
Used for assertion checking.
Definition: opengl_gal.h:324
void init()
Basic OpenGL initialization.
void Map()
Function Map() maps vertex buffer.
VERTEX_MANAGER * cachedManager
Container for storing cached VERTEX_ITEMs.
Definition: opengl_gal.h:304
bool isInitialized
Basic initialization flag, has to be done when the window is visible.
Definition: opengl_gal.h:321
bool IsVisible() const override
Definition: opengl_gal.h:99

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

1125 {
1126  wxASSERT_MSG( !IsTextMirrored(), "No support for mirrored text using bitmap fonts." );
1127 
1128  auto processedText = ProcessOverbars( aText );
1129  const auto& text = processedText.first;
1130  const auto& overbars = processedText.second;
1131 
1132  // Compute text size, so it can be properly justified
1133  VECTOR2D textSize;
1134  float commonOffset;
1135  std::tie( textSize, commonOffset ) = computeBitmapTextSize( text );
1136 
1137  const double SCALE = 1.4 * GetGlyphSize().y / textSize.y;
1138  bool overbar = false;
1139 
1140  int overbarLength = 0;
1141  double overbarHeight = textSize.y;
1142 
1143  Save();
1144 
1146  currentManager->Translate( aPosition.x, aPosition.y, layerDepth );
1147  currentManager->Rotate( aRotationAngle, 0.0f, 0.0f, -1.0f );
1148 
1149  double sx = SCALE * ( globalFlipX ? -1.0 : 1.0 );
1150  double sy = SCALE * ( globalFlipY ? -1.0 : 1.0 );
1151 
1152  currentManager->Scale( sx, sy, 0 );
1153  currentManager->Translate( 0, -commonOffset, 0 );
1154 
1155  switch( GetHorizontalJustify() )
1156  {
1158  Translate( VECTOR2D( -textSize.x / 2.0, 0 ) );
1159  break;
1160 
1162  //if( !IsTextMirrored() )
1163  Translate( VECTOR2D( -textSize.x, 0 ) );
1164  break;
1165 
1166  case GR_TEXT_HJUSTIFY_LEFT:
1167  //if( IsTextMirrored() )
1168  //Translate( VECTOR2D( -textSize.x, 0 ) );
1169  break;
1170  }
1171 
1172  switch( GetVerticalJustify() )
1173  {
1174  case GR_TEXT_VJUSTIFY_TOP:
1175  Translate( VECTOR2D( 0, -textSize.y ) );
1176  overbarHeight = -textSize.y / 2.0;
1177  break;
1178 
1180  Translate( VECTOR2D( 0, -textSize.y / 2.0 ) );
1181  overbarHeight = 0;
1182  break;
1183 
1185  break;
1186  }
1187 
1188  int i = 0;
1189 
1190  for( UTF8::uni_iter chIt = text.ubegin(), end = text.uend(); chIt < end; ++chIt )
1191  {
1192  unsigned int c = *chIt;
1193  wxASSERT_MSG( c != '\n' && c != '\r', wxT( "No support for multiline bitmap text yet" ) );
1194 
1195  // Handle overbar
1196  if( overbars[i] && !overbar )
1197  {
1198  overbar = true; // beginning of an overbar
1199  }
1200  else if( overbar && !overbars[i] )
1201  {
1202  overbar = false; // end of an overbar
1203  drawBitmapOverbar( overbarLength, overbarHeight );
1204  overbarLength = 0;
1205  }
1206 
1207  if( overbar )
1208  overbarLength += drawBitmapChar( c );
1209  else
1210  drawBitmapChar( c );
1211 
1212  ++i;
1213  }
1214 
1215  // Handle the case when overbar is active till the end of the drawn text
1216  currentManager->Translate( 0, commonOffset, 0 );
1217 
1218  if( overbar && overbarLength > 0 )
1219  drawBitmapOverbar( overbarLength, overbarHeight );
1220 
1221  Restore();
1222 }
VERTEX_MANAGER * currentManager
Currently used VERTEX_MANAGER (for storing VERTEX_ITEMs)
Definition: opengl_gal.h:303
std::pair< UTF8, std::vector< bool > > ProcessOverbars(const UTF8 &aText)
Processes a text to extract the raw text and overbar flags.
Definition: text_utils.cpp:27
double layerDepth
The actual layer depth.
bool IsTextMirrored() const
Returns true if text should displayed mirrored.
virtual void Translate(const VECTOR2D &aTranslation) override
Translate the context.
virtual 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:302
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:303
const VECTOR2D & GetGlyphSize() const
virtual void Save() override
Save the context.
double a
Alpha component.
Definition: color4d.h:304
VECTOR2< double > VECTOR2D
Definition: vector2d.h:586
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.
class uni_iter is a non-mutating iterator that walks through unicode code points in the UTF8 encoded ...
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.
size_t i
Definition: json11.cpp:597
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:301
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, i, KIGFX::GAL::IsTextMirrored(), KIGFX::GAL::layerDepth, ProcessOverbars(), KIGFX::COLOR4D::r, Restore(), KIGFX::VERTEX_MANAGER::Rotate(), Save(), KIGFX::VERTEX_MANAGER::Scale(), KIGFX::GAL::strokeColor, Translate(), KIGFX::VERTEX_MANAGER::Translate(), VECTOR2< T >::x, and VECTOR2< T >::y.

◆ blitCursor()

void OPENGL_GAL::blitCursor ( )
private

Blits cursor into the current screen.

Definition at line 1940 of file opengl_gal.cpp.

1941 {
1942  if( !IsCursorEnabled() )
1943  return;
1944 
1946 
1947  const int cursorSize = fullscreenCursor ? 8000 : 80;
1948 
1949  VECTOR2D cursorBegin = cursorPosition - cursorSize / ( 2 * worldScale );
1950  VECTOR2D cursorEnd = cursorPosition + cursorSize / ( 2 * worldScale );
1951  VECTOR2D cursorCenter = ( cursorBegin + cursorEnd ) / 2;
1952 
1953  const COLOR4D cColor = getCursorColor();
1954  const COLOR4D color( cColor.r * cColor.a, cColor.g * cColor.a,
1955  cColor.b * cColor.a, 1.0 );
1956 
1957  glActiveTexture( GL_TEXTURE0 );
1958  glDisable( GL_TEXTURE_2D );
1959  glLineWidth( 1.0 );
1960  glColor4d( color.r, color.g, color.b, color.a );
1961 
1962  glBegin( GL_LINES );
1963  glVertex2d( cursorCenter.x, cursorBegin.y );
1964  glVertex2d( cursorCenter.x, cursorEnd.y );
1965 
1966  glVertex2d( cursorBegin.x, cursorCenter.y );
1967  glVertex2d( cursorEnd.x, cursorCenter.y );
1968  glEnd();
1969 }
VECTOR2D cursorPosition
Current cursor position (world coordinates)
int color
Definition: DXF_plotter.cpp:62
double g
Green component.
Definition: color4d.h:302
static const unsigned int DIRECT_RENDERING
double b
Blue component.
Definition: color4d.h:303
double a
Alpha component.
Definition: color4d.h:304
OPENGL_COMPOSITOR * compositor
Handles multiple rendering targets.
Definition: opengl_gal.h:309
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:301
bool IsCursorEnabled() const
Returns information about cursor visibility.
Class COLOR4D is the color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:39

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

477  {
478  // Bigger arcs need smaller alpha increment to make them look smooth
479  return std::min( 1e6 / aRadius, 2.0 * M_PI / CIRCLE_POINTS );
480  }
CIRCLE_POINTS
#define min(a, b)
Definition: auxiliary.h:85

References min.

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

1498 {
1499  if( groups[aGroupNumber] )
1500  cachedManager->ChangeItemColor( *groups[aGroupNumber], aNewColor );
1501 }
GROUPS_MAP groups
Stores informations about VBO objects (groups)
Definition: opengl_gal.h:301
VERTEX_MANAGER * cachedManager
Container for storing cached VERTEX_ITEMs.
Definition: opengl_gal.h:304
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 1504 of file opengl_gal.cpp.

1505 {
1506  if( groups[aGroupNumber] )
1507  cachedManager->ChangeItemDepth( *groups[aGroupNumber], aDepth );
1508 }
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:301
VERTEX_MANAGER * cachedManager
Container for storing cached VERTEX_ITEMs.
Definition: opengl_gal.h:304

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

◆ ClearCache()

void OPENGL_GAL::ClearCache ( )
overridevirtual

Delete all data created during caching of graphic items.

Reimplemented from KIGFX::GAL.

Definition at line 1518 of file opengl_gal.cpp.

1519 {
1520  bitmapCache.reset( new GL_BITMAP_CACHE );
1521 
1522  groups.clear();
1523 
1524  if( isInitialized )
1525  cachedManager->Clear();
1526 }
std::unique_ptr< GL_BITMAP_CACHE > bitmapCache
Definition: opengl_gal.h:330
GROUPS_MAP groups
Stores informations about VBO objects (groups)
Definition: opengl_gal.h:301
VERTEX_MANAGER * cachedManager
Container for storing cached VERTEX_ITEMs.
Definition: opengl_gal.h:304
bool isInitialized
Basic initialization flag, has to be done when the window is visible.
Definition: opengl_gal.h:321
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 1413 of file opengl_gal.cpp.

1414 {
1415  // Clear screen
1417  // NOTE: Black used here instead of m_clearColor; it will be composited later
1418  glClearColor( 0, 0, 0, 1 );
1419  glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT );
1420 }
static const unsigned int DIRECT_RENDERING
OPENGL_COMPOSITOR * compositor
Handles multiple rendering targets.
Definition: opengl_gal.h:309
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 1569 of file opengl_gal.cpp.

1570 {
1571  // Save the current state
1572  unsigned int oldTarget = compositor->GetBuffer();
1573 
1574  switch( aTarget )
1575  {
1576  // Cached and noncached items are rendered to the same buffer
1577  default:
1578  case TARGET_CACHED:
1579  case TARGET_NONCACHED:
1581  break;
1582 
1583  case TARGET_OVERLAY:
1585  break;
1586  }
1587 
1588 
1589  if( aTarget != TARGET_OVERLAY )
1591  else
1593 
1594  // Restore the previous state
1595  compositor->SetBuffer( oldTarget );
1596 }
unsigned int overlayBuffer
Auxiliary rendering target (for menus etc.)
Definition: opengl_gal.h:311
Auxiliary rendering target (noncached)
Definition: definitions.h:49
static const COLOR4D BLACK
Definition: color4d.h:311
OPENGL_COMPOSITOR * compositor
Handles multiple rendering targets.
Definition: opengl_gal.h:309
unsigned int mainBuffer
Main rendering target.
Definition: opengl_gal.h:310
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 1890 of file opengl_gal.cpp.

1891 {
1892  VECTOR2D textSize( 0, 0 );
1893  float commonOffset = std::numeric_limits<float>::max();
1894  static const auto defaultGlyph = LookupGlyph( '(' ); // for strange chars
1895 
1896  for( UTF8::uni_iter chIt = aText.ubegin(), end = aText.uend(); chIt < end; ++chIt )
1897  {
1898  unsigned int c = *chIt;
1899 
1900  const FONT_GLYPH_TYPE* glyph = LookupGlyph( c );
1901  // Debug: show not coded char in the atlas
1902  // Be carefull before allowing the assert: it usually crash kicad
1903  // when the assert is made during a paint event.
1904  // wxASSERT_MSG( glyph, wxString::Format( "missing char in font: code 0x%x <%c>", c, c ) );
1905 
1906  if( !glyph || // Not coded in font
1907  c == '-' || c == '_' ) // Strange size of these 2 chars
1908  {
1909  glyph = defaultGlyph;
1910  }
1911 
1912  if( glyph )
1913  {
1914  textSize.x += glyph->advance;
1915  }
1916  }
1917 
1918  textSize.y = std::max<float>( textSize.y, font_information.max_y - defaultGlyph->miny );
1919  commonOffset = std::min<float>( font_information.max_y - defaultGlyph->maxy, commonOffset );
1920  textSize.y -= commonOffset;
1921 
1922  return std::make_pair( textSize, commonOffset );
1923 }
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
class uni_iter is a non-mutating iterator that walks through unicode code points in the UTF8 encoded ...
Definition: utf8.h:207
#define max(a, b)
Definition: auxiliary.h:86

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

209 {
210  // just return the current value. This could be cleverer and take
211  // into account other settings in future
212  return gridMinSpacing;
213 }
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 1124 of file graphics_abstraction_layer.h.

1125  {
1127  }
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 2113 of file opengl_gal.cpp.

2114 {
2115  auto pixelSize = worldScale;
2116 
2117  lookAtPoint.x = roundr( lookAtPoint.x, pixelSize );
2118  lookAtPoint.y = roundr( lookAtPoint.y, pixelSize );
2119 
2121 }
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 1511 of file opengl_gal.cpp.

1512 {
1513  // Frees memory in the container as well
1514  groups.erase( aGroupNumber );
1515 }
GROUPS_MAP groups
Stores informations about VBO objects (groups)
Definition: opengl_gal.h:301

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

706 {
707  if( aRadius <= 0 )
708  return;
709 
710  // Swap the angles, if start angle is greater than end angle
711  SWAP( aStartAngle, >, aEndAngle );
712 
713  const double alphaIncrement = calcAngleStep( aRadius );
714 
715  Save();
716  currentManager->Translate( aCenterPoint.x, aCenterPoint.y, 0.0 );
717 
718  if( isFillEnabled )
719  {
720  double alpha;
723 
724  // Triangle fan
725  for( alpha = aStartAngle; ( alpha + alphaIncrement ) < aEndAngle; )
726  {
727  currentManager->Reserve( 3 );
728  currentManager->Vertex( 0.0, 0.0, layerDepth );
729  currentManager->Vertex( cos( alpha ) * aRadius, sin( alpha ) * aRadius, layerDepth );
730  alpha += alphaIncrement;
731  currentManager->Vertex( cos( alpha ) * aRadius, sin( alpha ) * aRadius, layerDepth );
732  }
733 
734  // The last missing triangle
735  const VECTOR2D endPoint( cos( aEndAngle ) * aRadius, sin( aEndAngle ) * aRadius );
736 
737  currentManager->Reserve( 3 );
738  currentManager->Vertex( 0.0, 0.0, layerDepth );
739  currentManager->Vertex( cos( alpha ) * aRadius, sin( alpha ) * aRadius, layerDepth );
740  currentManager->Vertex( endPoint.x, endPoint.y, layerDepth );
741  }
742 
743  if( isStrokeEnabled )
744  {
746 
747  VECTOR2D p( cos( aStartAngle ) * aRadius, sin( aStartAngle ) * aRadius );
748  double alpha;
749 
750  for( alpha = aStartAngle + alphaIncrement; alpha <= aEndAngle; alpha += alphaIncrement )
751  {
752  VECTOR2D p_next( cos( alpha ) * aRadius, sin( alpha ) * aRadius );
753  DrawLine( p, p_next );
754 
755  p = p_next;
756  }
757 
758  // Draw the last missing part
759  if( alpha != aEndAngle )
760  {
761  VECTOR2D p_last( cos( aEndAngle ) * aRadius, sin( aEndAngle ) * aRadius );
762  DrawLine( p, p_last );
763  }
764  }
765 
766  Restore();
767 }
VERTEX_MANAGER * currentManager
Currently used VERTEX_MANAGER (for storing VERTEX_ITEMs)
Definition: opengl_gal.h:303
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.
virtual 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:302
COLOR4D fillColor
The fill color.
double b
Blue component.
Definition: color4d.h:303
virtual void Save() override
Save the context.
double a
Alpha component.
Definition: color4d.h:304
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:476
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...
virtual void DrawLine(const VECTOR2D &aStartPoint, const VECTOR2D &aEndPoint) override
Draw a line.
Definition: opengl_gal.cpp:594
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:301

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

772 {
773  if( aRadius <= 0 )
774  {
775  // Arcs of zero radius are a circle of aWidth diameter
776  if( aWidth > 0 )
777  DrawCircle( aCenterPoint, aWidth / 2.0 );
778 
779  return;
780  }
781 
782  // Swap the angles, if start angle is greater than end angle
783  SWAP( aStartAngle, >, aEndAngle );
784 
785  const double alphaIncrement = calcAngleStep( aRadius );
786 
787  Save();
788  currentManager->Translate( aCenterPoint.x, aCenterPoint.y, 0.0 );
789 
790  if( isStrokeEnabled )
791  {
793 
794  double width = aWidth / 2.0;
795  VECTOR2D startPoint( cos( aStartAngle ) * aRadius,
796  sin( aStartAngle ) * aRadius );
797  VECTOR2D endPoint( cos( aEndAngle ) * aRadius,
798  sin( aEndAngle ) * aRadius );
799 
800  drawStrokedSemiCircle( startPoint, width, aStartAngle + M_PI );
801  drawStrokedSemiCircle( endPoint, width, aEndAngle );
802 
803  VECTOR2D pOuter( cos( aStartAngle ) * ( aRadius + width ),
804  sin( aStartAngle ) * ( aRadius + width ) );
805 
806  VECTOR2D pInner( cos( aStartAngle ) * ( aRadius - width ),
807  sin( aStartAngle ) * ( aRadius - width ) );
808 
809  double alpha;
810 
811  for( alpha = aStartAngle + alphaIncrement; alpha <= aEndAngle; alpha += alphaIncrement )
812  {
813  VECTOR2D pNextOuter( cos( alpha ) * ( aRadius + width ),
814  sin( alpha ) * ( aRadius + width ) );
815  VECTOR2D pNextInner( cos( alpha ) * ( aRadius - width ),
816  sin( alpha ) * ( aRadius - width ) );
817 
818  DrawLine( pOuter, pNextOuter );
819  DrawLine( pInner, pNextInner );
820 
821  pOuter = pNextOuter;
822  pInner = pNextInner;
823  }
824 
825  // Draw the last missing part
826  if( alpha != aEndAngle )
827  {
828  VECTOR2D pLastOuter( cos( aEndAngle ) * ( aRadius + width ),
829  sin( aEndAngle ) * ( aRadius + width ) );
830  VECTOR2D pLastInner( cos( aEndAngle ) * ( aRadius - width ),
831  sin( aEndAngle ) * ( aRadius - width ) );
832 
833  DrawLine( pOuter, pLastOuter );
834  DrawLine( pInner, pLastInner );
835  }
836  }
837 
838  if( isFillEnabled )
839  {
841  SetLineWidth( aWidth );
842 
843  VECTOR2D p( cos( aStartAngle ) * aRadius, sin( aStartAngle ) * aRadius );
844  double alpha;
845 
846  for( alpha = aStartAngle + alphaIncrement; alpha <= aEndAngle; alpha += alphaIncrement )
847  {
848  VECTOR2D p_next( cos( alpha ) * aRadius, sin( alpha ) * aRadius );
849  DrawLine( p, p_next );
850 
851  p = p_next;
852  }
853 
854  // Draw the last missing part
855  if( alpha != aEndAngle )
856  {
857  VECTOR2D p_last( cos( aEndAngle ) * aRadius, sin( aEndAngle ) * aRadius );
858  DrawLine( p, p_last );
859  }
860  }
861 
862  Restore();
863 }
VERTEX_MANAGER * currentManager
Currently used VERTEX_MANAGER (for storing VERTEX_ITEMs)
Definition: opengl_gal.h:303
virtual void Restore() override
Restore the context.
double g
Green component.
Definition: color4d.h:302
COLOR4D fillColor
The fill color.
virtual void SetLineWidth(float aLineWidth)
Set the line width.
double b
Blue component.
Definition: color4d.h:303
virtual void Save() override
Save the context.
double a
Alpha component.
Definition: color4d.h:304
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:476
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...
virtual void DrawLine(const VECTOR2D &aStartPoint, const VECTOR2D &aEndPoint) override
Draw a line.
Definition: opengl_gal.cpp:594
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 ?
#define SWAP(varA, condition, varB)
Swap the variables if a condition is met.
Definition: definitions.h:31
double r
Red component.
Definition: color4d.h:301
virtual void DrawCircle(const VECTOR2D &aCenterPoint, double aRadius) override
Draw a circle using world coordinates.
Definition: opengl_gal.cpp:648

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

1069 {
1070  // We have to calculate the pixel size in users units to draw the image.
1071  // worldUnitLength is a factor used for converting IU to inches
1072  double scale = 1.0 / ( aBitmap.GetPPI() * worldUnitLength );
1073  double w = (double) aBitmap.GetSizePixels().x * scale;
1074  double h = (double) aBitmap.GetSizePixels().y * scale;
1075 
1076  auto xform = currentManager->GetTransformation();
1077 
1078  glm::vec4 v0 = xform * glm::vec4( -w/2, -h/2, 0.0, 0.0 );
1079  glm::vec4 v1 = xform * glm::vec4( w/2, h/2, 0.0, 0.0 );
1080  glm::vec4 trans = xform[3];
1081 
1082  auto texture_id = bitmapCache->RequestBitmap( &aBitmap );
1083 
1084  if( !glIsTexture( texture_id ) ) // ensure the bitmap texture is still valid
1085  return;
1086 
1087  auto oldTarget = GetTarget();
1088 
1089  glPushMatrix();
1090  glTranslated( trans.x, trans.y, trans.z );
1091 
1093  glEnable(GL_TEXTURE_2D);
1094  glActiveTexture( GL_TEXTURE0 );
1095  glBindTexture( GL_TEXTURE_2D, texture_id );
1096 
1097  glBegin( GL_QUADS );
1098  glColor4f( 1.0, 1.0, 1.0, 1.0 );
1099  glTexCoord2f( 0.0, 0.0 );
1100  glVertex3f( v0.x, v0.y, layerDepth );
1101  glColor4f( 1.0, 1.0, 1.0, 1.0 );
1102  glTexCoord2f( 1.0, 0.0 );
1103  glVertex3f( v1.x, v0.y, layerDepth );
1104  glColor4f( 1.0, 1.0, 1.0, 1.0 );
1105  glTexCoord2f( 1.0, 1.0 );
1106  glVertex3f( v1.x, v1.y, layerDepth );
1107  glColor4f( 1.0, 1.0, 1.0, 1.0 );
1108  glTexCoord2f( 0.0, 1.0 );
1109  glVertex3f( v0.x, v1.y, layerDepth );
1110  glEnd();
1111 
1112  SetTarget( oldTarget );
1113  glBindTexture( GL_TEXTURE_2D, 0 );
1114 
1115 #ifdef DISABLE_BITMAP_CACHE
1116  glDeleteTextures( 1, &texture_id );
1117 #endif
1118 
1119  glPopMatrix();
1120 }
VERTEX_MANAGER * currentManager
Currently used VERTEX_MANAGER (for storing VERTEX_ITEMs)
Definition: opengl_gal.h:303
const glm::mat4 & GetTransformation() const
double layerDepth
The actual layer depth.
std::unique_ptr< GL_BITMAP_CACHE > bitmapCache
Definition: opengl_gal.h:330
Auxiliary rendering target (noncached)
Definition: definitions.h:49
virtual RENDER_TARGET GetTarget() const override
Gets the currently used target for rendering.
double worldUnitLength
The unit length of the world coordinates [inch].
virtual 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 1789 of file opengl_gal.cpp.

1790 {
1791  const float TEX_X = font_image.width;
1792  const float TEX_Y = font_image.height;
1793 
1794  // handle space
1795  if( aChar == ' ' )
1796  {
1797  const FONT_GLYPH_TYPE* g = LookupGlyph( 'x' );
1798  wxASSERT( g );
1799  Translate( VECTOR2D( g->advance, 0 ) );
1800  return g->advance;
1801  }
1802 
1803  const FONT_GLYPH_TYPE* glyph = LookupGlyph( aChar );
1804 
1805  // If the glyph is not found (happens for many esotheric unicode chars)
1806  // shows a '?' instead.
1807  if( !glyph )
1808  glyph = LookupGlyph( '?' );
1809 
1810  if( !glyph ) // Should not happen.
1811  return 0;
1812 
1813  const float X = glyph->atlas_x + font_information.smooth_pixels;
1814  const float Y = glyph->atlas_y + font_information.smooth_pixels;
1815  const float XOFF = glyph->minx;
1816 
1817  // adjust for height rounding
1818  const float round_adjust = ( glyph->maxy - glyph->miny )
1819  - float( glyph->atlas_h - font_information.smooth_pixels * 2 );
1820  const float top_adjust = font_information.max_y - glyph->maxy;
1821  const float YOFF = round_adjust + top_adjust;
1822  const float W = glyph->atlas_w - font_information.smooth_pixels *2;
1823  const float H = glyph->atlas_h - font_information.smooth_pixels *2;
1824  const float B = 0;
1825 
1826  currentManager->Reserve( 6 );
1827  Translate( VECTOR2D( XOFF, YOFF ) );
1828  /* Glyph:
1829  * v0 v1
1830  * +--+
1831  * | /|
1832  * |/ |
1833  * +--+
1834  * v2 v3
1835  */
1836  currentManager->Shader( SHADER_FONT, X / TEX_X, ( Y + H ) / TEX_Y );
1837  currentManager->Vertex( -B, -B, 0 ); // v0
1838 
1839  currentManager->Shader( SHADER_FONT, ( X + W ) / TEX_X, ( Y + H ) / TEX_Y );
1840  currentManager->Vertex( W + B, -B, 0 ); // v1
1841 
1842  currentManager->Shader( SHADER_FONT, X / TEX_X, Y / TEX_Y );
1843  currentManager->Vertex( -B, H + B, 0 ); // v2
1844 
1845 
1846  currentManager->Shader( SHADER_FONT, ( X + W ) / TEX_X, ( Y + H ) / TEX_Y );
1847  currentManager->Vertex( W + B, -B, 0 ); // v1
1848 
1849  currentManager->Shader( SHADER_FONT, X / TEX_X, Y / TEX_Y );
1850  currentManager->Vertex( -B, H + B, 0 ); // v2
1851 
1852  currentManager->Shader( SHADER_FONT, ( X + W ) / TEX_X, Y / TEX_Y );
1853  currentManager->Vertex( W + B, H + B, 0 ); // v3
1854 
1855  Translate( VECTOR2D( -XOFF + glyph->advance, -YOFF ) );
1856 
1857  return glyph->advance;
1858 }
VERTEX_MANAGER * currentManager
Currently used VERTEX_MANAGER (for storing VERTEX_ITEMs)
Definition: opengl_gal.h:303
virtual 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:586
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 1861 of file opengl_gal.cpp.

1862 {
1863  // To draw an overbar, simply draw an overbar
1864  const FONT_GLYPH_TYPE* glyph = LookupGlyph( '_' );
1865  wxCHECK( glyph, /* void */ );
1866 
1867  const float H = glyph->maxy - glyph->miny;
1868 
1869  Save();
1870 
1871  Translate( VECTOR2D( -aLength, -aHeight-1.5*H ) );
1872 
1873  currentManager->Reserve( 6 );
1875 
1876  currentManager->Shader( 0 );
1877 
1878  currentManager->Vertex( 0, 0, 0 ); // v0
1879  currentManager->Vertex( aLength, 0, 0 ); // v1
1880  currentManager->Vertex( 0, H, 0 ); // v2
1881 
1882  currentManager->Vertex( aLength, 0, 0 ); // v1
1883  currentManager->Vertex( 0, H, 0 ); // v2
1884  currentManager->Vertex( aLength, H, 0 ); // v3
1885 
1886  Restore();
1887 }
VERTEX_MANAGER * currentManager
Currently used VERTEX_MANAGER (for storing VERTEX_ITEMs)
Definition: opengl_gal.h:303
virtual 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.
virtual 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:302
const FONT_GLYPH_TYPE * LookupGlyph(unsigned int aCodepoint)
double b
Blue component.
Definition: color4d.h:303
virtual void Save() override
Save the context.
VECTOR2< double > VECTOR2D
Definition: vector2d.h:586
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:301

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

649 {
650  if( isFillEnabled )
651  {
652  currentManager->Reserve( 3 );
654 
655  /* Draw a triangle that contains the circle, then shade it leaving only the circle.
656  * Parameters given to Shader() are indices of the triangle's vertices
657  * (if you want to understand more, check the vertex shader source [shader.vert]).
658  * Shader uses this coordinates to determine if fragments are inside the circle or not.
659  * Does the calculations in the vertex shader now (pixel alignment)
660  * v2
661  * /\
662  * //\\
663  * v0 /_\/_\ v1
664  */
665  currentManager->Shader( SHADER_FILLED_CIRCLE, 1.0, aRadius );
666  currentManager->Vertex( aCenterPoint.x, aCenterPoint.y, layerDepth );
667 
668  currentManager->Shader( SHADER_FILLED_CIRCLE, 2.0, aRadius );
669  currentManager->Vertex( aCenterPoint.x, aCenterPoint.y, layerDepth );
670 
671  currentManager->Shader( SHADER_FILLED_CIRCLE, 3.0, aRadius );
672  currentManager->Vertex( aCenterPoint.x, aCenterPoint.y, layerDepth );
673  }
674  if( isStrokeEnabled )
675  {
676  currentManager->Reserve( 3 );
678 
679  /* Draw a triangle that contains the circle, then shade it leaving only the circle.
680  * Parameters given to Shader() are indices of the triangle's vertices
681  * (if you want to understand more, check the vertex shader source [shader.vert]).
682  * and the line width. Shader uses this coordinates to determine if fragments are
683  * inside the circle or not.
684  * v2
685  * /\
686  * //\\
687  * v0 /_\/_\ v1
688  */
690  currentManager->Vertex( aCenterPoint.x, // v0
691  aCenterPoint.y, layerDepth );
692 
694  currentManager->Vertex( aCenterPoint.x, // v1
695  aCenterPoint.y, layerDepth );
696 
698  currentManager->Vertex( aCenterPoint.x, aCenterPoint.y, // v2
699  layerDepth );
700  }
701 }
VERTEX_MANAGER * currentManager
Currently used VERTEX_MANAGER (for storing VERTEX_ITEMs)
Definition: opengl_gal.h:303
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:302
COLOR4D fillColor
The fill color.
double b
Blue component.
Definition: color4d.h:303
double a
Alpha component.
Definition: color4d.h:304
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:301

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

1600 {
1601  // Now we should only store the position of the mouse cursor
1602  // The real drawing routines are in blitCursor()
1603  //VECTOR2D screenCursor = worldScreenMatrix * aCursorPosition;
1604  //cursorPosition = screenWorldMatrix * VECTOR2D( screenCursor.x, screenCursor.y );
1605  cursorPosition = aCursorPosition;
1606 }
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 
)
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.

Reimplemented from KIGFX::GAL.

Definition at line 1036 of file opengl_gal.cpp.

1038 {
1039  // FIXME The drawing quality needs to be improved
1040  // FIXME Perhaps choose a quad/triangle strip instead?
1041  // FIXME Brute force method, use a better (recursive?) algorithm
1042 
1043  std::deque<VECTOR2D> pointList;
1044 
1045  double t = 0.0;
1046  double dt = 1.0 / (double) CURVE_POINTS;
1047 
1048  for( int i = 0; i <= CURVE_POINTS; i++ )
1049  {
1050  double omt = 1.0 - t;
1051  double omt2 = omt * omt;
1052  double omt3 = omt * omt2;
1053  double t2 = t * t;
1054  double t3 = t * t2;
1055 
1056  VECTOR2D vertex = omt3 * aStartPoint + 3.0 * t * omt2 * aControlPointA
1057  + 3.0 * t2 * omt * aControlPointB + t3 * aEndPoint;
1058 
1059  pointList.push_back( vertex );
1060 
1061  t += dt;
1062  }
1063 
1064  DrawPolyline( pointList );
1065 }
static const int CURVE_POINTS
The number of points for curve approximation.
Definition: opengl_gal.h:289
virtual void DrawPolyline(const std::deque< VECTOR2D > &aPointList) override
Draw a polyline.
Definition: opengl_gal.cpp:904
size_t i
Definition: json11.cpp:597

References CURVE_POINTS, DrawPolyline(), and i.

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

1672 {
1673  Save();
1674 
1675  currentManager->Reserve( 3 );
1676  currentManager->Translate( aCenterPoint.x, aCenterPoint.y, 0.0f );
1677  currentManager->Rotate( aAngle, 0.0f, 0.0f, 1.0f );
1678 
1679  /* Draw a triangle that contains the semicircle, then shade it to leave only
1680  * the semicircle. Parameters given to Shader() are indices of the triangle's vertices
1681  * (if you want to understand more, check the vertex shader source [shader.vert]).
1682  * Shader uses these coordinates to determine if fragments are inside the semicircle or not.
1683  * v2
1684  * /\
1685  * /__\
1686  * v0 //__\\ v1
1687  */
1689  currentManager->Vertex( -aRadius * 3.0f / sqrt( 3.0f ), 0.0f, layerDepth ); // v0
1690 
1692  currentManager->Vertex( aRadius * 3.0f / sqrt( 3.0f ), 0.0f, layerDepth ); // v1
1693 
1695  currentManager->Vertex( 0.0f, aRadius * 2.0f, layerDepth ); // v2
1696 
1697  Restore();
1698 }
VERTEX_MANAGER * currentManager
Currently used VERTEX_MANAGER (for storing VERTEX_ITEMs)
Definition: opengl_gal.h:303
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.
virtual 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...
virtual 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 1225 of file opengl_gal.cpp.

1226 {
1229 
1231 
1232  // sub-pixel lines all render the same
1233  float minorLineWidth =
1234  std::fmax( 1.0f, gridLineWidth ) * getWorldPixelSize() / GetBackingScaleFactor();
1235  float majorLineWidth = minorLineWidth * 2.0f;
1236 
1237  // Draw the axis and grid
1238  // For the drawing the start points, end points and increments have
1239  // to be calculated in world coordinates
1240  VECTOR2D worldStartPoint = screenWorldMatrix * VECTOR2D( 0.0, 0.0 );
1241  VECTOR2D worldEndPoint = screenWorldMatrix * VECTOR2D( screenSize );
1242 
1243  // Draw axes if desired
1244  if( axesEnabled )
1245  {
1246  SetLineWidth( minorLineWidth );
1248 
1249  DrawLine( VECTOR2D( worldStartPoint.x, 0 ), VECTOR2D( worldEndPoint.x, 0 ) );
1250  DrawLine( VECTOR2D( 0, worldStartPoint.y ), VECTOR2D( 0, worldEndPoint.y ) );
1251  }
1252 
1253  // force flush
1255 
1256  if( !gridVisibility || gridSize.x == 0 || gridSize.y == 0 )
1257  return;
1258 
1259  VECTOR2D gridScreenSize( gridSize );
1260 
1261  double gridThreshold = computeMinGridSpacing() / worldScale;
1262 
1264  gridThreshold *= 2.0;
1265 
1266  // If we cannot display the grid density, scale down by a tick size and
1267  // try again. Eventually, we get some representation of the grid
1268  while( std::min( gridScreenSize.x, gridScreenSize.y ) <= gridThreshold )
1269  {
1270  gridScreenSize = gridScreenSize * static_cast<double>( gridTick );
1271  }
1272 
1273  // Compute grid starting and ending indexes to draw grid points on the
1274  // visible screen area
1275  // Note: later any point coordinate will be offsetted by gridOrigin
1276  int gridStartX = KiROUND( ( worldStartPoint.x - gridOrigin.x ) / gridScreenSize.x );
1277  int gridEndX = KiROUND( ( worldEndPoint.x - gridOrigin.x ) / gridScreenSize.x );
1278  int gridStartY = KiROUND( ( worldStartPoint.y - gridOrigin.y ) / gridScreenSize.y );
1279  int gridEndY = KiROUND( ( worldEndPoint.y - gridOrigin.y ) / gridScreenSize.y );
1280 
1281  // Ensure start coordinate > end coordinate
1282  SWAP( gridStartX, >, gridEndX );
1283  SWAP( gridStartY, >, gridEndY );
1284 
1285  // Ensure the grid fills the screen
1286  --gridStartX; ++gridEndX;
1287  --gridStartY; ++gridEndY;
1288 
1289  glDisable( GL_DEPTH_TEST );
1290  glDisable( GL_TEXTURE_2D );
1291 
1292  if( gridStyle == GRID_STYLE::DOTS )
1293  {
1294  glEnable( GL_STENCIL_TEST );
1295  glStencilFunc( GL_ALWAYS, 1, 1 );
1296  glStencilOp( GL_KEEP, GL_KEEP, GL_INCR );
1297  glColor4d( 0.0, 0.0, 0.0, 0.0 );
1298  SetStrokeColor( COLOR4D( 0.0, 0.0, 0.0, 0.0 ) );
1299  }
1300  else
1301  {
1302  glColor4d( gridColor.r, gridColor.g, gridColor.b, gridColor.a );
1304  }
1305 
1307  {
1308 
1309  // Vertical positions
1310  for( int j = gridStartY; j <= gridEndY; j++ )
1311  {
1312  bool tickY = ( j % gridTick == 0 );
1313  const double posY = j * gridScreenSize.y + gridOrigin.y;
1314 
1315  // Horizontal positions
1316  for( int i = gridStartX; i <= gridEndX; i++ )
1317  {
1318  bool tickX = ( i % gridTick == 0 );
1319  SetLineWidth( ( ( tickX && tickY ) ? majorLineWidth : minorLineWidth ) );
1320  auto lineLen = 2.0 * GetLineWidth();
1321  auto posX = i * gridScreenSize.x + gridOrigin.x;
1322 
1323  DrawLine( VECTOR2D( posX - lineLen, posY ), VECTOR2D( posX + lineLen, posY ) );
1324  DrawLine( VECTOR2D( posX, posY - lineLen ), VECTOR2D( posX, posY + lineLen ) );
1325  }
1326  }
1327 
1329  }
1330  else
1331  {
1332  // Vertical lines
1333  for( int j = gridStartY; j <= gridEndY; j++ )
1334  {
1335  const double y = j * gridScreenSize.y + gridOrigin.y;
1336 
1337  // If axes are drawn, skip the lines that would cover them
1338  if( axesEnabled && y == 0.0 )
1339  continue;
1340 
1341  SetLineWidth( ( j % gridTick == 0 ) ? majorLineWidth : minorLineWidth );
1342  VECTOR2D a ( gridStartX * gridScreenSize.x + gridOrigin.x, y );
1343  VECTOR2D b ( gridEndX * gridScreenSize.x + gridOrigin.x, y );
1344 
1345  DrawLine( a, b );
1346  }
1347 
1349 
1350  if( gridStyle == GRID_STYLE::DOTS )
1351  {
1352  glStencilFunc( GL_NOTEQUAL, 0, 1 );
1353  glColor4d( gridColor.r, gridColor.g, gridColor.b, gridColor.a );
1355  }
1356 
1357  // Horizontal lines
1358  for( int i = gridStartX; i <= gridEndX; i++ )
1359  {
1360  const double x = i * gridScreenSize.x + gridOrigin.x;
1361 
1362  // If axes are drawn, skip the lines that would cover them
1363  if( axesEnabled && x == 0.0 )
1364  continue;
1365 
1366  SetLineWidth( ( i % gridTick == 0 ) ? majorLineWidth : minorLineWidth );
1367  VECTOR2D a ( x, gridStartY * gridScreenSize.y + gridOrigin.y );
1368  VECTOR2D b ( x, gridEndY * gridScreenSize.y + gridOrigin.y );
1369  DrawLine( a, b );
1370  }
1371 
1373 
1374  if( gridStyle == GRID_STYLE::DOTS )
1375  glDisable( GL_STENCIL_TEST );
1376  }
1377 
1378  glEnable( GL_DEPTH_TEST );
1379  glEnable( GL_TEXTURE_2D );
1380 }
int gridTick
Every tick line gets the double width.
float GetLineWidth() const
Get the line width.
bool axesEnabled
Should the axes be drawn.
static int KiROUND(double v)
Round a floating point number to an integer using "round halfway cases away from zero".
Definition: common.h:115
double computeMinGridSpacing() const
compute minimum grid spacing from the grid settings
GRID_STYLE gridStyle
Grid display style.
double g
Green component.
Definition: color4d.h:302
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:305
double b
Blue component.
Definition: color4d.h:303
Auxiliary rendering target (noncached)
Definition: definitions.h:49
double getWorldPixelSize() const
Definition: opengl_gal.cpp:355
double a
Alpha component.
Definition: color4d.h:304
OPENGL_COMPOSITOR * compositor
Handles multiple rendering targets.
Definition: opengl_gal.h:309
VECTOR2< double > VECTOR2D
Definition: vector2d.h:586
unsigned int mainBuffer
Main rendering target.
Definition: opengl_gal.h:310
COLOR4D axesColor
Color of the axes.
float gridLineWidth
Line width of the grid.
virtual void DrawLine(const VECTOR2D &aStartPoint, const VECTOR2D &aEndPoint) override
Draw a line.
Definition: opengl_gal.cpp:594
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.
virtual 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.
virtual float GetBackingScaleFactor() const
double worldScale
The scale factor world->screen.
VECTOR2D gridSize
The grid size.
size_t i
Definition: json11.cpp:597
VECTOR2I screenSize
Screen size in screen coordinates.
#define SWAP(varA, condition, varB)
Swap the variables if a condition is met.
Definition: definitions.h:31
double r
Red component.
Definition: color4d.h:301
#define min(a, b)
Definition: auxiliary.h:85
Class COLOR4D is the color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:39

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, HIDPI_GL_CANVAS::GetBackingScaleFactor(), KIGFX::GAL::GetLineWidth(), getWorldPixelSize(), KIGFX::GAL::gridColor, KIGFX::GAL::gridLineWidth, KIGFX::GAL::gridOrigin, KIGFX::GAL::gridSize, KIGFX::GAL::gridStyle, KIGFX::GAL::gridTick, KIGFX::GAL::gridVisibility, i, KiROUND(), mainBuffer, min, 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 1490 of file opengl_gal.cpp.

1491 {
1492  if( groups[aGroupNumber] )
1493  cachedManager->DrawItem( *groups[aGroupNumber] );
1494 }
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:301
VERTEX_MANAGER * cachedManager
Container for storing cached VERTEX_ITEMs.
Definition: opengl_gal.h:304

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

595 {
597 
598  drawLineQuad( aStartPoint, aEndPoint );
599 }
VERTEX_MANAGER * currentManager
Currently used VERTEX_MANAGER (for storing VERTEX_ITEMs)
Definition: opengl_gal.h:303
void drawLineQuad(const VECTOR2D &aStartPoint, const VECTOR2D &aEndPoint)
Draw a quad for the line.
double g
Green component.
Definition: color4d.h:302
double b
Blue component.
Definition: color4d.h:303
double a
Alpha component.
Definition: color4d.h:304
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:301

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

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

1610 {
1611  /* Helper drawing: ____--- v3 ^
1612  * ____---- ... \ \
1613  * ____---- ... \ end \
1614  * v1 ____---- ... ____---- \ width
1615  * ---- ...___---- \ \
1616  * \ ___...-- \ v
1617  * \ ____----... ____---- v2
1618  * ---- ... ____----
1619  * start \ ... ____----
1620  * \... ____----
1621  * ----
1622  * v0
1623  * dots mark triangles' hypotenuses
1624  */
1625 
1626  auto v1 = currentManager->GetTransformation() * glm::vec4( aStartPoint.x, aStartPoint.y, 0.0, 0.0 );
1627  auto v2 = currentManager->GetTransformation() * glm::vec4( aEndPoint.x, aEndPoint.y, 0.0, 0.0 );
1628 
1629  VECTOR2D vs( v2.x - v1.x, v2.y - v1.y );
1630 
1631  currentManager->Reserve( 6 );
1632 
1633  // Line width is maintained by the vertex shader
1634  currentManager->Shader( SHADER_LINE_A, lineWidth, vs.x, vs.y );
1635  currentManager->Vertex( aStartPoint, layerDepth );
1636 
1637  currentManager->Shader( SHADER_LINE_B, lineWidth, vs.x, vs.y );
1638  currentManager->Vertex( aStartPoint, layerDepth );
1639 
1640  currentManager->Shader( SHADER_LINE_C, lineWidth, vs.x, vs.y );
1641  currentManager->Vertex( aEndPoint, layerDepth );
1642 
1643  currentManager->Shader( SHADER_LINE_D, lineWidth, vs.x, vs.y );
1644  currentManager->Vertex( aEndPoint, layerDepth );
1645 
1646  currentManager->Shader( SHADER_LINE_E, lineWidth, vs.x, vs.y );
1647  currentManager->Vertex( aEndPoint, layerDepth );
1648 
1649  currentManager->Shader( SHADER_LINE_F, lineWidth, vs.x, vs.y );
1650  currentManager->Vertex( aStartPoint, layerDepth );
1651 }
VERTEX_MANAGER * currentManager
Currently used VERTEX_MANAGER (for storing VERTEX_ITEMs)
Definition: opengl_gal.h:303
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 927 of file opengl_gal.cpp.

928 {
929  auto points = std::unique_ptr<GLdouble[]>( new GLdouble[3 * aPointList.size()] );
930  GLdouble* ptr = points.get();
931 
932  for( const VECTOR2D& p : aPointList )
933  {
934  *ptr++ = p.x;
935  *ptr++ = p.y;
936  *ptr++ = layerDepth;
937  }
938 
939  drawPolygon( points.get(), aPointList.size() );
940 }
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 943 of file opengl_gal.cpp.

944 {
945  auto points = std::unique_ptr<GLdouble[]>( new GLdouble[3 * aListSize] );
946  GLdouble* target = points.get();
947  const VECTOR2D* src = aPointList;
948 
949  for( int i = 0; i < aListSize; ++i )
950  {
951  *target++ = src->x;
952  *target++ = src->y;
953  *target++ = layerDepth;
954  ++src;
955  }
956 
957  drawPolygon( points.get(), aListSize );
958 }
double layerDepth
The actual layer depth.
void drawPolygon(GLdouble *aPoints, int aPointCount)
Draws a filled polygon.
size_t i
Definition: json11.cpp:597

References drawPolygon(), i, 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 998 of file opengl_gal.cpp.

999 {
1000  if ( aPolySet.IsTriangulationUpToDate() )
1001  {
1002  drawTriangulatedPolyset( aPolySet );
1003  return;
1004  }
1005 
1006  for( int j = 0; j < aPolySet.OutlineCount(); ++j )
1007  {
1008  const SHAPE_LINE_CHAIN& outline = aPolySet.COutline( j );
1009  DrawPolygon( outline );
1010  }
1011 }
int OutlineCount() const
Returns the number of outlines in the set
virtual void DrawPolygon(const std::deque< VECTOR2D > &aPointList) override
Draw a polygon.
Definition: opengl_gal.cpp:927
bool IsTriangulationUpToDate() const
void drawTriangulatedPolyset(const SHAPE_POLY_SET &aPoly)
Draws a set of polygons with a cached triangulation.
Definition: opengl_gal.cpp:961
Class 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 1015 of file opengl_gal.cpp.

1016 {
1017  if( aPolygon.SegmentCount() == 0 )
1018  return;
1019 
1020  const int pointCount = aPolygon.SegmentCount() + 1;
1021  std::unique_ptr<GLdouble[]> points( new GLdouble[3 * pointCount] );
1022  GLdouble* ptr = points.get();
1023 
1024  for( int i = 0; i < pointCount; ++i )
1025  {
1026  const VECTOR2I& p = aPolygon.CPoint( i );
1027  *ptr++ = p.x;
1028  *ptr++ = p.y;
1029  *ptr++ = layerDepth;
1030  }
1031 
1032  drawPolygon( points.get(), pointCount );
1033 }
double layerDepth
The actual layer depth.
void drawPolygon(GLdouble *aPoints, int aPointCount)
Draws a filled polygon.
size_t i
Definition: json11.cpp:597

References SHAPE_LINE_CHAIN::CPoint(), drawPolygon(), i, KIGFX::GAL::layerDepth, 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 1735 of file opengl_gal.cpp.

1736 {
1737  if( isFillEnabled )
1738  {
1741 
1742  // Any non convex polygon needs to be tesselated
1743  // for this purpose the GLU standard functions are used
1744  TessParams params = { currentManager, tessIntersects };
1745  gluTessBeginPolygon( tesselator, &params );
1746  gluTessBeginContour( tesselator );
1747 
1748  GLdouble* point = aPoints;
1749 
1750  for( int i = 0; i < aPointCount; ++i )
1751  {
1752  gluTessVertex( tesselator, point, point );
1753  point += 3; // 3 coordinates
1754  }
1755 
1756  gluTessEndContour( tesselator );
1757  gluTessEndPolygon( tesselator );
1758 
1759  // Free allocated intersecting points
1760  tessIntersects.clear();
1761  }
1762 
1763  if( isStrokeEnabled )
1764  {
1765  drawPolyline( [&](int idx) { return VECTOR2D( aPoints[idx * 3], aPoints[idx * 3 + 1] ); },
1766  aPointCount );
1767  }
1768 }
VERTEX_MANAGER * currentManager
Currently used VERTEX_MANAGER (for storing VERTEX_ITEMs)
Definition: opengl_gal.h:303
double g
Green component.
Definition: color4d.h:302
COLOR4D fillColor
The fill color.
double b
Blue component.
Definition: color4d.h:303
double a
Alpha component.
Definition: color4d.h:304
bool isStrokeEnabled
Are the outlines stroked ?
VECTOR2< double > VECTOR2D
Definition: vector2d.h:586
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:353
bool isFillEnabled
Is filling of graphic objects enabled ?
std::deque< boost::shared_array< GLdouble > > tessIntersects
Storage for intersecting points.
Definition: opengl_gal.h:355
size_t i
Definition: json11.cpp:597
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:301

References KIGFX::COLOR4D::a, KIGFX::COLOR4D::b, KIGFX::VERTEX_MANAGER::Color(), currentManager, drawPolyline(), KIGFX::GAL::fillColor, KIGFX::COLOR4D::g, i, 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 904 of file opengl_gal.cpp.

905 {
906  drawPolyline( [&](int idx) { return aPointList[idx]; }, aPointList.size() );
907 }
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 910 of file opengl_gal.cpp.

911 {
912  drawPolyline( [&](int idx) { return aPointList[idx]; }, aListSize );
913 }
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 916 of file opengl_gal.cpp.

917 {
918  auto numPoints = aLineChain.PointCount();
919 
920  if( aLineChain.IsClosed() )
921  numPoints += 1;
922 
923  drawPolyline( [&](int idx) { return aLineChain.CPoint(idx); }, numPoints );
924 }
int PointCount() const
Function PointCount()
const VECTOR2I & CPoint(int aIndex) const
Function CPoint()
void drawPolyline(const std::function< VECTOR2D(int)> &aPointGetter, int aPointCount)
Generic way of drawing a polyline stored in different containers.
bool IsClosed() const
Function IsClosed()

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

1772 {
1773  if( aPointCount < 2 )
1774  return;
1775 
1777  int i;
1778 
1779  for( i = 1; i < aPointCount; ++i )
1780  {
1781  auto start = aPointGetter( i - 1 );
1782  auto end = aPointGetter( i );
1783 
1784  drawLineQuad( start, end );
1785  }
1786 }
VERTEX_MANAGER * currentManager
Currently used VERTEX_MANAGER (for storing VERTEX_ITEMs)
Definition: opengl_gal.h:303
void drawLineQuad(const VECTOR2D &aStartPoint, const VECTOR2D &aEndPoint)
Draw a quad for the line.
double g
Green component.
Definition: color4d.h:302
double b
Blue component.
Definition: color4d.h:303
double a
Alpha component.
Definition: color4d.h:304
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.
size_t i
Definition: json11.cpp:597
double r
Red component.
Definition: color4d.h:301

References KIGFX::COLOR4D::a, KIGFX::COLOR4D::b, KIGFX::VERTEX_MANAGER::Color(), currentManager, drawLineQuad(), KIGFX::COLOR4D::g, i, 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 866 of file opengl_gal.cpp.

867 {
868  // Compute the diagonal points of the rectangle
869  VECTOR2D diagonalPointA( aEndPoint.x, aStartPoint.y );
870  VECTOR2D diagonalPointB( aStartPoint.x, aEndPoint.y );
871 
872  // Fill the rectangle
873  if( isFillEnabled )
874  {
875  currentManager->Reserve( 6 );
878 
879  currentManager->Vertex( aStartPoint.x, aStartPoint.y, layerDepth );
880  currentManager->Vertex( diagonalPointA.x, diagonalPointA.y, layerDepth );
881  currentManager->Vertex( aEndPoint.x, aEndPoint.y, layerDepth );
882 
883  currentManager->Vertex( aStartPoint.x, aStartPoint.y, layerDepth );
884  currentManager->Vertex( aEndPoint.x, aEndPoint.y, layerDepth );
885  currentManager->Vertex( diagonalPointB.x, diagonalPointB.y, layerDepth );
886  }
887 
888  // Stroke the outline
889  if( isStrokeEnabled )
890  {
892 
893  std::deque<VECTOR2D> pointList;
894  pointList.push_back( aStartPoint );
895  pointList.push_back( diagonalPointA );
896  pointList.push_back( aEndPoint );
897  pointList.push_back( diagonalPointB );
898  pointList.push_back( aStartPoint );
899  DrawPolyline( pointList );
900  }
901 }
VERTEX_MANAGER * currentManager
Currently used VERTEX_MANAGER (for storing VERTEX_ITEMs)
Definition: opengl_gal.h:303
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:302
COLOR4D fillColor
The fill color.
double b
Blue component.
Definition: color4d.h:303
double a
Alpha component.
Definition: color4d.h:304
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 ?
virtual void DrawPolyline(const std::deque< VECTOR2D > &aPointList) override
Draw a polyline.
Definition: opengl_gal.cpp:904
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:301

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

604 {
605  if( aStartPoint == aEndPoint ) // 0 length segments are just a circle.
606  {
607  DrawCircle( aStartPoint, aWidth/2 );
608  return;
609  }
610 
611  if( isFillEnabled || aWidth == 1.0 )
612  {
614 
615  SetLineWidth( aWidth );
616  drawLineQuad( aStartPoint, aEndPoint );
617  }
618  else
619  {
620  auto startEndVector = aEndPoint - aStartPoint;
621  auto lineAngle = startEndVector.Angle();
622  // Outlined tracks
623  double lineLength = startEndVector.EuclideanNorm();
624 
625  SetLineWidth( 1.0 );
627 
628  Save();
629 
630  currentManager->Translate( aStartPoint.x, aStartPoint.y, 0.0 );
631  currentManager->Rotate( lineAngle, 0.0f, 0.0f, 1.0f );
632 
633  drawLineQuad( VECTOR2D( 0.0, aWidth / 2.0 ),
634  VECTOR2D( lineLength, aWidth / 2.0 ) );
635 
636  drawLineQuad( VECTOR2D( 0.0, -aWidth / 2.0 ),
637  VECTOR2D( lineLength, -aWidth / 2.0 ) );
638 
639  // Draw line caps
640  drawStrokedSemiCircle( VECTOR2D( 0.0, 0.0 ), aWidth / 2, M_PI / 2 );
641  drawStrokedSemiCircle( VECTOR2D( lineLength, 0.0 ), aWidth / 2, -M_PI / 2 );
642 
643  Restore();
644  }
645 }
VERTEX_MANAGER * currentManager
Currently used VERTEX_MANAGER (for storing VERTEX_ITEMs)
Definition: opengl_gal.h:303
void drawLineQuad(const VECTOR2D &aStartPoint, const VECTOR2D &aEndPoint)
Draw a quad for the line.
virtual 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:302
COLOR4D fillColor
The fill color.
virtual void SetLineWidth(float aLineWidth)
Set the line width.
double b
Blue component.
Definition: color4d.h:303
virtual void Save() override
Save the context.
double a
Alpha component.
Definition: color4d.h:304
VECTOR2< double > VECTOR2D
Definition: vector2d.h:586
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:306
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:301
virtual void DrawCircle(const VECTOR2D &aCenterPoint, double aRadius) override
Draw a circle using world coordinates.
Definition: opengl_gal.cpp:648

References KIGFX::COLOR4D::a, VECTOR2< T >::Angle(), KIGFX::COLOR4D::b, KIGFX::VERTEX_MANAGER::Color(), currentManager, DrawCircle(), drawLineQuad(), drawStrokedSemiCircle(), 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 1654 of file opengl_gal.cpp.

1655 {
1656  if( isFillEnabled )
1657  {
1659  drawFilledSemiCircle( aCenterPoint, aRadius, aAngle );
1660  }
1661 
1662  if( isStrokeEnabled )
1663  {
1665  drawStrokedSemiCircle( aCenterPoint, aRadius, aAngle );
1666  }
1667 }
VERTEX_MANAGER * currentManager
Currently used VERTEX_MANAGER (for storing VERTEX_ITEMs)
Definition: opengl_gal.h:303
double g
Green component.
Definition: color4d.h:302
COLOR4D fillColor
The fill color.
double b
Blue component.
Definition: color4d.h:303
double a
Alpha component.
Definition: color4d.h:304
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:301
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 1701 of file opengl_gal.cpp.

1703 {
1704  double outerRadius = aRadius + ( lineWidth / 2 );
1705 
1706  Save();
1707 
1708  currentManager->Reserve( 3 );
1709  currentManager->Translate( aCenterPoint.x, aCenterPoint.y, 0.0f );
1710  currentManager->Rotate( aAngle, 0.0f, 0.0f, 1.0f );
1711 
1712  /* Draw a triangle that contains the semicircle, then shade it to leave only
1713  * the semicircle. Parameters given to Shader() are indices of the triangle's vertices
1714  * (if you want to understand more, check the vertex shader source [shader.vert]), the
1715  * radius and the line width. Shader uses these coordinates to determine if fragments are
1716  * inside the semicircle or not.
1717  * v2
1718  * /\
1719  * /__\
1720  * v0 //__\\ v1
1721  */
1723  currentManager->Vertex( -outerRadius * 3.0f / sqrt( 3.0f ), 0.0f, layerDepth ); // v0
1724 
1726  currentManager->Vertex( outerRadius * 3.0f / sqrt( 3.0f ), 0.0f, layerDepth ); // v1
1727 
1729  currentManager->Vertex( 0.0f, outerRadius * 2.0f, layerDepth ); // v2
1730 
1731  Restore();
1732 }
VERTEX_MANAGER * currentManager
Currently used VERTEX_MANAGER (for storing VERTEX_ITEMs)
Definition: opengl_gal.h:303
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.
virtual 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...
virtual 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 961 of file opengl_gal.cpp.

962 {
965 
966  if( isFillEnabled )
967  {
968  for( unsigned int j = 0; j < aPolySet.TriangulatedPolyCount(); ++j )
969  {
970  auto triPoly = aPolySet.TriangulatedPolygon( j );
971 
972  for( size_t i = 0; i < triPoly->GetTriangleCount(); i++ )
973  {
974  VECTOR2I a, b, c;
975  triPoly->GetTriangle( i, a, b, c );
976  currentManager->Vertex( a.x, a.y, layerDepth );
977  currentManager->Vertex( b.x, b.y, layerDepth );
978  currentManager->Vertex( c.x, c.y, layerDepth );
979  }
980  }
981  }
982 
983  if( isStrokeEnabled )
984  {
985  for( int j = 0; j < aPolySet.OutlineCount(); ++j )
986  {
987  const auto& poly = aPolySet.Polygon( j );
988 
989  for( const auto& lc : poly )
990  {
991  DrawPolyline( lc );
992  }
993  }
994  }
995 }
VERTEX_MANAGER * currentManager
Currently used VERTEX_MANAGER (for storing VERTEX_ITEMs)
Definition: opengl_gal.h:303
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:302
COLOR4D fillColor
The fill color.
double b
Blue component.
Definition: color4d.h:303
double a
Alpha component.
Definition: color4d.h:304
bool isStrokeEnabled
Are the outlines stroked ?
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 ?
virtual void DrawPolyline(const std::deque< VECTOR2D > &aPointList) override
Draw a polyline.
Definition: opengl_gal.cpp:904
size_t i
Definition: json11.cpp:597
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:301

References KIGFX::COLOR4D::a, KIGFX::COLOR4D::b, KIGFX::VERTEX_MANAGER::Color(), currentManager, DrawPolyline(), KIGFX::GAL::fillColor, KIGFX::COLOR4D::g, i, KIGFX::GAL::isFillEnabled, KIGFX::GAL::isStrokeEnabled, KIGFX::GAL::layerDepth, SHAPE_POLY_SET::OutlineCount(), SHAPE_POLY_SET::Polygon(), KIGFX::COLOR4D::r, KIGFX::VERTEX_MANAGER::Shader(), KIGFX::SHADER_NONE, SHAPE_POLY_SET::TriangulatedPolyCount(), SHAPE_POLY_SET::TriangulatedPolygon(), KIGFX::VERTEX_MANAGER::Vertex(), VECTOR2< T >::x, and VECTOR2< T >::y.

Referenced by DrawPolygon().

◆ EnableDepthTest()

void OPENGL_GAL::EnableDepthTest ( bool  aEnabled = false)
overridevirtual

Parameters passed to the GLU tesselator.

Reimplemented from KIGFX::GAL.

Definition at line 2099 of file opengl_gal.cpp.

2100 {
2101  cachedManager->EnableDepthTest( aEnabled );
2102  nonCachedManager->EnableDepthTest( aEnabled );
2103  overlayManager->EnableDepthTest( aEnabled );
2104 }
VERTEX_MANAGER * overlayManager
Container for storing overlaid VERTEX_ITEMs.
Definition: opengl_gal.h:306
VERTEX_MANAGER * nonCachedManager
Container for storing non-cached VERTEX_ITEMs.
Definition: opengl_gal.h:305
VERTEX_MANAGER * cachedManager
Container for storing cached VERTEX_ITEMs.
Definition: opengl_gal.h:304
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 510 of file opengl_gal.cpp.

511 {
512  wxASSERT_MSG( isContextLocked, "What happened to the context lock?" );
513 
514 #ifdef __WXDEBUG__
515  PROF_COUNTER totalRealTime( "OPENGL_GAL::endDrawing()", true );
516 #endif /* __WXDEBUG__ */
517 
518  // Cached & non-cached containers are rendered to the same buffer
522 
523  // Overlay container is rendered to a different buffer
526 
527  // Be sure that the framebuffer is not colorized (happens on specific GPU&drivers combinations)
528  glColor4d( 1.0, 1.0, 1.0, 1.0 );
529 
530  // Draw the remaining contents, blit the rendering targets to the screen, swap the buffers
533  compositor->Present();
534  blitCursor();
535 
536  SwapBuffers();
537 
538 #ifdef __WXDEBUG__
539  totalRealTime.Stop();
540  wxLogTrace( "GAL_PROFILE", wxT( "OPENGL_GAL::endDrawing(): %.1f ms" ), totalRealTime.msecs() );
541 #endif /* __WXDEBUG__ */
542 }
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:311
VERTEX_MANAGER * overlayManager
Container for storing overlaid VERTEX_ITEMs.
Definition: opengl_gal.h:306
bool isContextLocked
Used for assertion checking.
Definition: opengl_gal.h:324
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:305
OPENGL_COMPOSITOR * compositor
Handles multiple rendering targets.
Definition: opengl_gal.h:309
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:310
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:304
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 1483 of file opengl_gal.cpp.

1484 {
1486  isGrouping = false;
1487 }
bool isGrouping
Was a group started?
Definition: opengl_gal.h:323
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:304

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

◆ endUpdate()

void OPENGL_GAL::endUpdate ( )
overrideprivatevirtual

Reimplemented from KIGFX::GAL.

Definition at line 585 of file opengl_gal.cpp.

586 {
587  if( !isInitialized )
588  return;
589 
590  cachedManager->Unmap();
591 }
void Unmap()
Function Unmap() unmaps vertex buffer.
VERTEX_MANAGER * cachedManager
Container for storing cached VERTEX_ITEMs.
Definition: opengl_gal.h:304
bool isInitialized
Basic initialization flag, has to be done when the window is visible.
Definition: opengl_gal.h:321

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

1408 {
1409  glFlush();
1410 }

◆ GetBackingScaleFactor()

float HIDPI_GL_CANVAS::GetBackingScaleFactor ( ) const
virtualinherited

Definition at line 56 of file hidpi_gl_canvas.cpp.

57 {
58 #ifdef RETINA_OPENGL_PATCH
59  // this is ugly, but original method isn't marked const although it doesn't modify anything
60  // => clean up when it officially has arrived in wxWidgets
61  return static_cast< wxGLCanvas* >( const_cast< HIDPI_GL_CANVAS* >( this ))->GetBackingScaleFactor();
62 #else
63 
64  // Return the cached value (which originally was set from config or automatically)
65  return m_scale_factor;
66 #endif
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(), and ResizeScreen().

◆ GetClearColor()

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

Definition at line 215 of file graphics_abstraction_layer.h.

216  {
217  return m_clearColor;
218  }

References KIGFX::GAL::m_clearColor.

Referenced by EDIT_POINTS::ViewDraw().

◆ getCursorColor()

COLOR4D GAL::getCursorColor ( ) const
protectedinherited

Gets the actual cursor color to draw.

Definition at line 238 of file graphics_abstraction_layer.cpp.

239 {
240  auto color = cursorColor;
241 
242  // dim the cursor if it's only on because it was forced
243  // (this helps to provide a hint for active tools)
244  if( !isCursorEnabled )
245  {
246  color.a = color.a * 0.5;
247  }
248 
249  return color;
250 }
bool isCursorEnabled
Is the cursor enabled?
int color
Definition: DXF_plotter.cpp:62
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 265 of file graphics_abstraction_layer.h.

266  {
267  return fillColor;
268  }
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 943 of file graphics_abstraction_layer.h.

944  {
945  return gridLineWidth;
946  }
float gridLineWidth
Line width of the grid.

References KIGFX::GAL::gridLineWidth.

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

217 {
218 #if 0
219  // This old code expects a non zero grid size, which can be wrong here.
220  return VECTOR2D( KiROUND( ( aPoint.x - gridOffset.x ) / gridSize.x ) * gridSize.x + gridOffset.x,
221  KiROUND( ( aPoint.y - gridOffset.y ) / gridSize.y ) * gridSize.y + gridOffset.y );
222 #else
223  // if grid size == 0.0 there is no grid, so use aPoint as grid reference position
224  double cx = gridSize.x > 0.0 ? KiROUND( ( aPoint.x - gridOffset.x ) / gridSize.x ) * gridSize.x + gridOffset.x
225  : aPoint.x;
226  double cy = gridSize.y > 0.0 ? KiROUND( ( aPoint.y - gridOffset.y ) / gridSize.y ) * gridSize.y + gridOffset.y
227  : aPoint.y;
228 
229  return VECTOR2D( cx, cy );
230 #endif
231 }
VECTOR2D gridOffset
The grid offset to compensate cursor position.
static int KiROUND(double v)
Round a floating point number to an integer using "round halfway cases away from zero".
Definition: common.h:115
VECTOR2< double > VECTOR2D
Definition: vector2d.h:586
VECTOR2D gridSize
The grid size.

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

Referenced by EDIT_POINTS_FACTORY::buildForPolyOutline(), and 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 895 of file graphics_abstraction_layer.h.

896  {
897  return gridSize;
898  }
VECTOR2D gridSize
The grid size.

References KIGFX::GAL::gridSize.

Referenced by SCH_DRAW_PANEL::SwitchBackend().

◆ GetHorizontalJustify()

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

Returns current text horizontal justification setting.

Definition at line 487 of file graphics_abstraction_layer.h.

488  {
490  }
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 687 of file graphics_abstraction_layer.h.

688  {
689  return lookAtPoint;
690  }
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 756 of file graphics_abstraction_layer.h.

757  {
758  return depthRange.y;
759  }
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 748 of file graphics_abstraction_layer.h.

749  {
750  return depthRange.x;
751  }
VECTOR2D depthRange
Range of the depth.

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

◆ GetNativePixelSize()

wxSize HIDPI_GL_CANVAS::GetNativePixelSize ( ) const
virtualinherited

Definition at line 44 of file hidpi_gl_canvas.cpp.

45 {
46  wxSize size = wxGLCanvas::GetClientSize();
47 
48  const float scaleFactor = GetBackingScaleFactor();
49  size.x *= scaleFactor;
50  size.y *= scaleFactor;
51 
52  return size;
53 }
virtual float GetBackingScaleFactor() const

References HIDPI_GL_CANVAS::GetBackingScaleFactor().

Referenced by EDA_3D_CANVAS::OnMouseMove(), EDA_3D_CANVAS::OnPaint(), 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 1972 of file opengl_gal.cpp.

1973 {
1974  wxASSERT_MSG( groups.size() < std::numeric_limits<unsigned int>::max(),
1975  wxT( "There are no free slots to store a group" ) );
1976 
1977  while( groups.find( groupCounter ) != groups.end() )
1978  {
1979  groupCounter++;
1980  }
1981 
1982  return groupCounter++;
1983 }
GROUPS_MAP groups
Stores informations about VBO objects (groups)
Definition: opengl_gal.h:301
#define max(a, b)
Definition: auxiliary.h:86
unsigned int groupCounter
Counter used for generating keys for groups.
Definition: opengl_gal.h:302

References groupCounter, groups, and max.

Referenced by BeginGroup().

◆ GetOverbarVerticalPosition()

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

Compute the vertical position of an overbar, sometimes used in texts.

This is the distance between the text base line and the overbar.

Returns
the relative position of the overbar axis.

Definition at line 382 of file graphics_abstraction_layer.h.

383  {
385  }
STROKE_FONT strokeFont
Instance of object that stores information about how to draw texts.
double computeOverbarVerticalPosition() const
Compute the vertical position of an overbar, sometimes used in texts.

References KIGFX::STROKE_FONT::computeOverbarVerticalPosition(), and KIGFX::GAL::strokeFont.

◆ GetRotation()

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

Get the rotation angle.

Returns
The rotation angle (radians).

Definition at line 727 of file graphics_abstraction_layer.h.

728  {
729  return rotation;
730  }
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 76 of file hidpi_gl_canvas.cpp.

77 {
78  return m_scale_factor;
79 }
double m_scale_factor
The current scale factor (e.g.

References HIDPI_GL_CANVAS::m_scale_factor.

Referenced by updatedGalDisplayOptions().

◆ GetScreenPixelSize()

const VECTOR2I& KIGFX::GAL::GetScreenPixelSize ( ) const
inlineinherited

◆ getScreenPixelSize()

VECTOR2D OPENGL_GAL::getScreenPixelSize ( ) const
private

Definition at line 362 of file opengl_gal.cpp.

363 {
364  auto sf = GetBackingScaleFactor();
365  return VECTOR2D( 2.0 / (double) ( screenSize.x * sf ), 2.0 / (double) ( screenSize.y * sf ) );
366 }
VECTOR2< double > VECTOR2D
Definition: vector2d.h:586
virtual float GetBackingScaleFactor() const
VECTOR2I screenSize
Screen size in screen coordinates.

References HIDPI_GL_CANVAS::GetBackingScaleFactor(), 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 623 of file graphics_abstraction_layer.h.

624  {
625  return screenWorldMatrix;
626  }
MATRIX3x3D screenWorldMatrix
Screen transformation.

References KIGFX::GAL::screenWorldMatrix.

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

286  {
287  return strokeColor;
288  }
COLOR4D strokeColor
The color of the outlines.

References KIGFX::GAL::strokeColor.

◆ GetStrokeFont()

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

Definition at line 327 of file graphics_abstraction_layer.h.

328  {
329  return strokeFont;
330  }
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 1563 of file opengl_gal.cpp.

1564 {
1565  return currentTarget;
1566 }
RENDER_TARGET currentTarget
Current rendering target.
Definition: opengl_gal.h:312

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

171 {
172  // Compute the X and Y size of a given text.
173  // Because computeTextLineSize expects a one line text,
174  // aText is expected to be only one line text.
175  return strokeFont.computeTextLineSize( aText );
176 }
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 505 of file graphics_abstraction_layer.h.

506  {
508  }
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 355 of file opengl_gal.cpp.

356 {
357  auto matrix = GetScreenWorldMatrix();
358  return std::min( std::abs( matrix.GetScale().x ), std::abs( matrix.GetScale().y ) );
359 }
const MATRIX3x3D & GetScreenWorldMatrix() const
Get the screen <-> world transformation matrix.
#define abs(a)
Definition: auxiliary.h:84
#define min(a, b)
Definition: auxiliary.h:85

References abs, KIGFX::GAL::GetScreenWorldMatrix(), and min.

Referenced by beginDrawing(), and DrawGrid().

◆ GetWorldScale()

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

Get the world scale.

Returns
the actual world scale factor.

Definition at line 766 of file graphics_abstraction_layer.h.

767  {
768  return worldScale;
769  }
double worldScale
The scale factor world->screen.

References KIGFX::GAL::worldScale.

Referenced by GRID_HELPER::BestDragOrigin(), GRID_HELPER::BestSnapAnchor(), KIGFX::PCB_PAINTER::draw(), SCH_BASE_FRAME::RedrawScreen(), and KIGFX::PREVIEW::SetConstantGlyphHeight().

◆ GetWorldScreenMatrix()

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

Get the world <-> screen transformation matrix.

Returns
the transformation matrix.

Definition at line 613 of file graphics_abstraction_layer.h.

614  {
615  return worldScreenMatrix;
616  }
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 707 of file graphics_abstraction_layer.h.

708  {
709  return zoomFactor;
710  }
double zoomFactor
The zoom factor.

References KIGFX::GAL::zoomFactor.

Referenced by EDA_DRAW_PANEL_GAL::GetLegacyZoom(), EDA_DRAW_FRAME::GetZoomLevelIndicator(), and SCH_BASE_FRAME::RedrawScreen().

◆ init()

void OPENGL_GAL::init ( )
private

Basic OpenGL initialization.

Definition at line 1986 of file opengl_gal.cpp.

1987 {
1988  wxASSERT( IsShownOnScreen() );
1989 
1990  wxASSERT_MSG( isContextLocked, "This should only be called from within a locked context." );
1991 
1992  GLenum err = glewInit();
1993 
1994  if( GLEW_OK != err )
1995  throw std::runtime_error( (const char*) glewGetErrorString( err ) );
1996 
1997  // Check the OpenGL version (minimum 2.1 is required)
1998  if( !GLEW_VERSION_2_1 )
1999  throw std::runtime_error( "OpenGL 2.1 or higher is required!" );
2000 
2001 #if defined (__LINUX__) // calling enableGlDebug crashes opengl on some OS (OSX and some Windows)
2002 #ifdef DEBUG
2003  if( GLEW_ARB_debug_output )
2004  enableGlDebug( true );
2005 #endif
2006 #endif
2007 
2008  // Framebuffers have to be supported
2009  if( !GLEW_EXT_framebuffer_object )
2010  throw std::runtime_error( "Framebuffer objects are not supported!" );
2011 
2012  // Vertex buffer has to be supported
2013  if( !GLEW_ARB_vertex_buffer_object )
2014  throw std::runtime_error( "Vertex buffer objects are not supported!" );
2015 
2016  // Prepare shaders
2018  throw std::runtime_error( "Cannot compile vertex shader!" );
2019 
2021  throw std::runtime_error( "Cannot compile fragment shader!" );
2022 
2023  if( !shader->IsLinked() && !shader->Link() )
2024  throw std::runtime_error( "Cannot link the shaders!" );
2025 
2026  // Check if video card supports textures big enough to fit the font atlas
2027  int maxTextureSize;
2028  glGetIntegerv( GL_MAX_TEXTURE_SIZE, &maxTextureSize );
2029 
2030  if( maxTextureSize < (int) font_image.width || maxTextureSize < (int)font_image.height )
2031  {
2032  // TODO implement software texture scaling
2033  // for bitmap fonts and use a higher resolution texture?
2034  throw std::runtime_error( "Requested texture size is not supported" );
2035  }
2036 
2037  cachedManager = new VERTEX_MANAGER( true );
2038  nonCachedManager = new VERTEX_MANAGER( false );
2039  overlayManager = new VERTEX_MANAGER( false );
2040 
2041  // Make VBOs use shaders
2045 
2046  isInitialized = true;
2047 }
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
VERTEX_MANAGER * overlayManager
Container for storing overlaid VERTEX_ITEMs.
Definition: opengl_gal.h:306
bool isContextLocked
Used for assertion checking.
Definition: opengl_gal.h:324
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:315
void enableGlDebug(bool aEnable)
Enables/disables OpenGL driver messages output.
Definition: utils.cpp:140
VERTEX_MANAGER * nonCachedManager
Container for storing non-cached VERTEX_ITEMs.
Definition: opengl_gal.h:305
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
string & err
Definition: json11.cpp:598
VERTEX_MANAGER * cachedManager
Container for storing cached VERTEX_ITEMs.
Definition: opengl_gal.h:304
bool isInitialized
Basic initialization flag, has to be done when the window is visible.
Definition: opengl_gal.h:321

References cachedManager, enableGlDebug(), err, KIGFX::BUILTIN_FONT::font_image, 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, overlayManager, KIGFX::VERTEX_MANAGER::SetShader(), shader, KIGFX::SHADER_TYPE_FRAGMENT, KIGFX::SHADER_TYPE_VERTEX, and KIGFX::BUILTIN_FONT::FONT_IMAGE_TYPE::width.

Referenced by beginDrawing(), and beginUpdate().

◆ 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; }

◆ IsCursorEnabled()

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

Returns information about cursor visibility.

Returns
True if cursor is visible.

Definition at line 996 of file graphics_abstraction_layer.h.

997  {
999  }
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

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

Definition at line 786 of file graphics_abstraction_layer.h.

787  {
788  return globalFlipX;
789  }
bool globalFlipX
Flag for X axis flipping.

References KIGFX::GAL::globalFlipX.

Referenced by KIGFX::CAIRO_GAL_BASE::angle_xform(), and KIGFX::CAIRO_GAL_BASE::arc_angles_xform_and_normalize().

◆ IsFlippedY()

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

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

Definition at line 794 of file graphics_abstraction_layer.h.

795  {
796  return globalFlipY;
797  }
bool globalFlipY
Flag for Y axis flipping.

References KIGFX::GAL::globalFlipY.

◆ IsFontBold()

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

Returns true if current font has 'bold' attribute enabled.

Definition at line 433 of file graphics_abstraction_layer.h.

434  {
435  return textProperties.m_bold;
436  }
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

Returns true if current font has 'italic' attribute enabled.

Definition at line 451 of file graphics_abstraction_layer.h.

452  {
453  return textProperties.m_italic;
454  }
struct KIGFX::GAL::TEXT_PROPERTIES textProperties

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

Referenced by KIGFX::STROKE_FONT::ComputeStringBoundaryLimits(), and KIGFX::STROKE_FONT::drawSingleLineText().

◆ IsInitialized()

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

Returns the initalization status for the canvas.

Reimplemented from KIGFX::GAL.

Definition at line 92 of file opengl_gal.h.

93  {
94  // is*Initialized flags, but it is enough for OpenGL to show up
95  return IsShownOnScreen() && !GetClientRect().IsEmpty();
96  }

◆ IsOpenGlEngine()

virtual bool KIGFX::OPENGL_GAL::IsOpenGlEngine ( )
inlineoverridevirtual

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

Reimplemented from KIGFX::GAL.

Definition at line 89 of file opengl_gal.h.

89 { return true; }

◆ IsTextMirrored()

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

Returns true if text should displayed mirrored.

Definition at line 469 of file graphics_abstraction_layer.h.

470  {
471  return textProperties.m_mirrored;
472  }
struct KIGFX::GAL::TEXT_PROPERTIES textProperties

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

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

◆ IsVisible()

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

Reimplemented from KIGFX::GAL.

Definition at line 99 of file opengl_gal.h.

100  {
101  return IsShownOnScreen() && !GetClientRect().IsEmpty();
102  }

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

546 {
547  wxASSERT_MSG( !isContextLocked, "Context already locked." );
548  isContextLocked = true;
549  lockClientCookie = aClientCookie;
550 
552 }
bool isContextLocked
Used for assertion checking.
Definition: opengl_gal.h:324
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:292

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

91 {
92  // defer to the child class first
93  updatedGalDisplayOptions( aOptions );
94 
95  // there is no refresh to do at this level
96 }
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 1926 of file opengl_gal.cpp.

1927 {
1928  PostPaint();
1929 }
void PostPaint()
Function PostPaint posts an event to m_paint_listener.
Definition: opengl_gal.h:253

References PostPaint().

Referenced by OPENGL_GAL().

◆ PopDepth()

void KIGFX::GAL::PopDepth ( )
inlineinherited

Restores previously stored drawing depth for the depth stack.

Definition at line 1038 of file graphics_abstraction_layer.h.

1039  {
1040  layerDepth = depthStack.top();
1041  depthStack.pop();
1042  }
double layerDepth
The actual layer depth.
std::stack< double > depthStack
Stored depth values.

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

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

◆ PostPaint()

void KIGFX::OPENGL_GAL::PostPaint ( )
inline

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.

Definition at line 253 of file opengl_gal.h.

254  {
255  if( paintListener )
256  {
257  wxPaintEvent redrawEvent;
258  wxPostEvent( paintListener, redrawEvent );
259  }
260  }
wxEvtHandler * paintListener
Definition: opengl_gal.h:295

References paintListener.

Referenced by onPaint().

◆ PushDepth()

void KIGFX::GAL::PushDepth ( )
inlineinherited

Stores current drawing depth on the depth stack.

Definition at line 1030 of file graphics_abstraction_layer.h.

1031  {
1032  depthStack.push( layerDepth );
1033  }
double layerDepth
The actual layer depth.
std::stack< double > depthStack
Stored depth values.

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

Referenced by 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 155 of file graphics_abstraction_layer.cpp.

156 {
157  // Tiny but non-zero - this will always need setting
158  // there is no built-in default
159  SetGlyphSize( { 1.0, 1.0 } );
160 
163 
164  SetFontBold( false );
165  SetFontItalic( false );
166  SetTextMirrored( false );
167 }
void SetFontItalic(const bool aItalic)
Set italic property of current font.
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 SetGlyphSize(const VECTOR2D aGlyphSize)
Set the font glyph size.
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::SetGlyphSize(), KIGFX::GAL::SetHorizontalJustify(), KIGFX::GAL::SetTextMirrored(), and KIGFX::GAL::SetVerticalJustify().

Referenced by KIGFX::PCB_PAINTER::draw(), KIGFX::GAL::GAL(), 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 1383 of file opengl_gal.cpp.

1384 {
1385  screenSize = VECTOR2I( aWidth, aHeight );
1386 
1387  // Resize framebuffers
1388  const float scaleFactor = GetBackingScaleFactor();
1389  compositor->Resize( aWidth * scaleFactor, aHeight * scaleFactor );
1390  isFramebufferInitialized = false;
1391 
1392  wxGLCanvas::SetSize( aWidth, aHeight );
1393 }
VECTOR2< int > VECTOR2I
Definition: vector2d.h:587
OPENGL_COMPOSITOR * compositor
Handles multiple rendering targets.
Definition: opengl_gal.h:309
bool isFramebufferInitialized
Are the framebuffers initialized?
Definition: opengl_gal.h:318
virtual void Resize(unsigned int aWidth, unsigned int aHeight) override
Function Resize() clears the state of COMPOSITOR, so it has to be reinitialized again with the new di...
virtual float GetBackingScaleFactor() const
VECTOR2I screenSize
Screen size in screen coordinates.

References compositor, HIDPI_GL_CANVAS::GetBackingScaleFactor(), isFramebufferInitialized, KIGFX::OPENGL_COMPOSITOR::Resize(), and KIGFX::GAL::screenSize.

◆ Restore()

void OPENGL_GAL::Restore ( )
overridevirtual

Restore the context.

Reimplemented from KIGFX::GAL.

Definition at line 1465 of file opengl_gal.cpp.

1466 {
1468 }
VERTEX_MANAGER * currentManager
Currently used VERTEX_MANAGER (for storing VERTEX_ITEMs)
Definition: opengl_gal.h:303
void PopMatrix()
Function PopMatrix() pops the current transformation matrix stack.

References currentManager, and KIGFX::VERTEX_MANAGER::PopMatrix().

Referenced by BitmapText(), DrawArc(), DrawArcSegment(), drawBitmapOverbar(), drawFilledSemiCircle(), DrawSegment(), and drawStrokedSemiCircle().

◆ RestoreScreen()

void OPENGL_GAL::RestoreScreen ( )
overridevirtual

Restore the screen contents.

Reimplemented from KIGFX::GAL.

Definition at line 1535 of file opengl_gal.cpp.

1536 {
1537  wxASSERT_MSG( false, wxT( "Not implemented yet" ) );
1538 }

◆ Rotate()

void OPENGL_GAL::Rotate ( double  aAngle)
overridevirtual

Rotate the context.

Parameters
aAngleis the rotation angle in radians.

Reimplemented from KIGFX::GAL.

Definition at line 1441 of file opengl_gal.cpp.

1442 {
1443  currentManager->Rotate( aAngle, 0.0f, 0.0f, 1.0f );
1444 }
VERTEX_MANAGER * currentManager
Currently used VERTEX_MANAGER (for storing VERTEX_ITEMs)
Definition: opengl_gal.h:303
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...

References currentManager, and KIGFX::VERTEX_MANAGER::Rotate().

◆ Save()

void OPENGL_GAL::Save ( )
overridevirtual

Save the context.

Reimplemented from KIGFX::GAL.

Definition at line 1459 of file opengl_gal.cpp.

1460 {
1462 }
VERTEX_MANAGER * currentManager
Currently used VERTEX_MANAGER (for storing VERTEX_ITEMs)
Definition: opengl_gal.h:303
void PushMatrix()
Function PushMatrix() pushes the current transformation matrix stack.

References currentManager, and KIGFX::VERTEX_MANAGER::PushMatrix().

Referenced by BitmapText(), DrawArc(), DrawArcSegment(), drawBitmapOverbar(), drawFilledSemiCircle(), DrawSegment(), and drawStrokedSemiCircle().

◆ SaveScreen()

void OPENGL_GAL::SaveScreen ( )
overridevirtual

Save the screen contents.

Reimplemented from KIGFX::GAL.

Definition at line 1529 of file opengl_gal.cpp.

1530 {
1531  wxASSERT_MSG( false, wxT( "Not implemented yet" ) );
1532 }

◆ Scale()

void OPENGL_GAL::Scale ( const VECTOR2D aScale)
overridevirtual

Scale the context.

Parameters
aScaleis the scale factor for the x- and y-axis.

Reimplemented from KIGFX::GAL.

Definition at line 1453 of file opengl_gal.cpp.

1454 {
1455  currentManager->Scale( aScale.x, aScale.y, 0.0f );
1456 }
VERTEX_MANAGER * currentManager
Currently used VERTEX_MANAGER (for storing VERTEX_ITEMs)
Definition: opengl_gal.h:303
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...

References currentManager, KIGFX::VERTEX_MANAGER::Scale(), VECTOR2< T >::x, and VECTOR2< T >::y.

◆ SetAxesColor()

void KIGFX::GAL::SetAxesColor ( const COLOR4D aAxesColor)
inlineinherited

Set the axes color.

Parameters
aAxesColoris the color to draw the axes if enabled.

Definition at line 915 of file graphics_abstraction_layer.h.

916  {
917  axesColor = aAxesColor;
918  }
COLOR4D axesColor
Color of the axes.

References KIGFX::GAL::axesColor.

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

◆ SetAxesEnabled()

void KIGFX::GAL::SetAxesEnabled ( bool  aAxesEnabled)
inlineinherited

◆ SetClearColor()

void KIGFX::GAL::SetClearColor ( const COLOR4D aColor)
inlineinherited

◆ SetCoarseGrid()

void KIGFX::GAL::SetCoarseGrid ( int  aInterval)
inlineinherited

Draw every tick line wider.

Parameters
aIntervalincrease the width of every aInterval line, if 0 do not use this feature.

Definition at line 933 of file graphics_abstraction_layer.h.

934  {
935  gridTick = aInterval;
936  }
int gridTick
Every tick line gets the double width.

References KIGFX::GAL::gridTick.

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

◆ SetCursorColor()

void KIGFX::GAL::SetCursorColor ( const COLOR4D aCursorColor)
inlineinherited

Set the cursor color.

Parameters
aCursorColoris the color of the cursor.

Definition at line 1006 of file graphics_abstraction_layer.h.

1007  {
1008  cursorColor = aCursorColor;
1009  }
COLOR4D cursorColor
Cursor color.