42#include <unordered_map>
51#define SEG_PER_CIRCLE_COUNT 64
87 wxEvtHandler* aMouseListener =
nullptr, wxEvtHandler* aPaintListener =
nullptr,
88 const wxString& aName = wxT(
"GLCanvas" ) );
106 return IsShownOnScreen() && !GetClientRect().IsEmpty();
115 void SetMinLineWidth(
float aLineWidth )
override;
122 void DrawLine(
const VECTOR2D& aStartPoint,
const VECTOR2D& aEndPoint )
override;
126 double aWidth )
override;
129 void DrawSegmentChain(
const std::vector<VECTOR2D>& aPointList,
double aWidth )
override;
130 void DrawSegmentChain(
const SHAPE_LINE_CHAIN& aLineChain,
double aWidth )
override;
133 void DrawCircle(
const VECTOR2D& aCenterPoint,
double aRadius )
override;
136 void DrawHoleWall(
const VECTOR2D& aCenterPoint,
double aHoleRadius,
137 double aWallWidth )
override;
140 void DrawArc(
const VECTOR2D& aCenterPoint,
double aRadius,
const EDA_ANGLE& aStartAngle,
144 void DrawArcSegment(
const VECTOR2D& aCenterPoint,
double aRadius,
const EDA_ANGLE& aStartAngle,
145 const EDA_ANGLE& aAngle,
double aWidth,
double aMaxError )
override;
148 void DrawEllipse(
const VECTOR2D& aCenterPoint,
double aMajorRadius,
double aMinorRadius,
152 void DrawEllipseArc(
const VECTOR2D& aCenterPoint,
double aMajorRadius,
double aMinorRadius,
157 void DrawRectangle(
const VECTOR2D& aStartPoint,
const VECTOR2D& aEndPoint )
override;
160 void DrawPolyline(
const std::deque<VECTOR2D>& aPointList )
override;
161 void DrawPolyline(
const std::vector<VECTOR2D>& aPointList )
override;
162 void DrawPolyline(
const VECTOR2D aPointList[],
int aListSize )
override;
166 void DrawPolylines(
const std::vector<std::vector<VECTOR2D>>& aPointLists )
override;
169 void DrawPolygon(
const std::deque<VECTOR2D>& aPointList )
override;
170 void DrawPolygon(
const VECTOR2D aPointList[],
int aListSize )
override;
171 void DrawPolygon(
const SHAPE_POLY_SET& aPolySet,
bool aStrokeTriangulation =
false )
override;
175 virtual void DrawGlyph(
const KIFONT::GLYPH& aGlyph,
int aNth,
int aTotal )
override;
178 virtual void DrawGlyphs(
const std::vector<std::unique_ptr<KIFONT::GLYPH>>& aGlyphs )
override;
183 double aFilterValue = 0.0 )
override;
186 void DrawBitmap(
const BITMAP_BASE& aBitmap,
double alphaBlend = 1.0 )
override;
189 void BitmapText(
const wxString& aText,
const VECTOR2I& aPosition,
193 void DrawGrid()
override;
200 void ResizeScreen(
int aWidth,
int aHeight )
override;
203 bool Show(
bool aShow )
override;
209 void Flush()
override;
211 void ClearScreen()
override;
218 void Transform(
const MATRIX3x3D& aTransformation )
override;
221 void Rotate(
double aAngle )
override;
224 void Translate(
const VECTOR2D& aTranslation )
override;
227 void Scale(
const VECTOR2D& aScale )
override;
230 void Save()
override;
233 void Restore()
override;
240 int BeginGroup()
override;
243 void EndGroup()
override;
246 void DrawGroup(
int aGroupNumber )
override;
249 void ChangeGroupColor(
int aGroupNumber,
const COLOR4D& aNewColor )
override;
252 void ChangeGroupDepth(
int aGroupNumber,
int aDepth )
override;
255 void DeleteGroup(
int aGroupNumber )
override;
258 void ClearCache()
override;
280 void StartDiffLayer()
override;
283 void EndDiffLayer()
override;
285 void ComputeWorldScreenMatrix()
override;
291 bool SetNativeCursorStyle(
KICURSOR aCursor,
bool aHiDPI )
override;
294 void DrawCursor(
const VECTOR2D& aCursorPosition )
override;
302 void PostPaint( wxPaintEvent& aEvent );
314 void EnableDepthTest(
bool aEnabled =
false )
override;
328 bool IsResetSettled()
override;
330 void LockContext(
int aClientCookie )
override;
332 void UnlockContext(
int aClientCookie )
override;
335 void BeginDrawing()
override;
338 void EndDrawing()
override;
340 bool GetScreenshot( wxImage& aDstImage );
377 typedef std::unordered_map< unsigned int, std::shared_ptr<VERTEX_ITEM> >
GROUPS_MAP;
444 bool aReserve =
true );
486 bool aReserve =
true );
495 void drawCircle(
const VECTOR2D& aCenterPoint,
double aRadius,
bool aReserve =
true );
505 bool aReserve =
true );
516 double aWidth,
bool aReserve =
true );
522 bool aReserve =
true );
531 void drawPolygon( GLdouble* aPoints,
int aPointCount );
594 void onPaint( wxPaintEvent& aEvent );
638 double getWorldPixelSize()
const;
640 VECTOR2D getScreenPixelSize()
const;
647 void setupShaderParameters();
657 bool detectContextReset();
660 void orphanContextGroup();
This class handle bitmap images in KiCad.
HIDPI_GL_CANVAS(const KIGFX::VC_SETTINGS &aSettings, wxWindow *aParent, const wxGLAttributes &aGLAttribs, wxWindowID aId=wxID_ANY, const wxPoint &aPos=wxDefaultPosition, const wxSize &aSize=wxDefaultSize, long aStyle=0, const wxString &aName=wxGLCanvasName, const wxPalette &aPalette=wxNullPalette)
A color representation with 4 components: red, green, blue, alpha.
GAL(GAL_DISPLAY_OPTIONS &aOptions)
Limit how often the OpenGL canvases are rebuilt after GPU resets.
void drawPolygon(GLdouble *aPoints, int aPointCount)
Draw a filled polygon.
void skipMouseEvent(wxMouseEvent &aEvent)
Skip the mouse event to the parent.
void drawSegment(const VECTOR2D &aStartPoint, const VECTOR2D &aEndPoint, double aWidth, bool aReserve=true)
Internal method for segment drawing.
unsigned int m_groupCounter
Counter used for generating keys for groups.
std::unordered_map< unsigned int, std::shared_ptr< VERTEX_ITEM > > GROUPS_MAP
VERTEX_MANAGER * m_overlayManager
Container for storing overlaid VERTEX_ITEMs.
bool m_isInitialized
Basic initialization flag, has to be done when the window is visible.
VERTEX_MANAGER * m_currentManager
Currently used VERTEX_MANAGER (for storing VERTEX_ITEMs).
void drawCircle(const VECTOR2D &aCenterPoint, double aRadius, bool aReserve=true)
Internal method for circle drawing.
std::deque< std::shared_ptr< GLdouble > > m_tessIntersects
void SetNegativeDrawMode(bool aSetting) override
Set negative draw mode in the renderer.
bool IsInitialized() const override
Return the initialization status for the canvas.
WX_CURSOR_TYPE m_currentwxCursor
wx cursor showing the current native cursor.
unsigned int m_mainBuffer
Main rendering target.
static std::set< OPENGL_GAL * > m_instances
Canvases to repaint after a reset.
std::unique_ptr< GL_BITMAP_CACHE > m_bitmapCache
std::pair< VECTOR2D, float > computeBitmapTextSize(const UTF8 &aText) const
Compute a size of text drawn using bitmap font with current text setting applied.
bool IsContextLocked() override
Checks the state of the context lock.
void blitCursor()
Blit cursor into the current screen.
static wxString CheckFeatures(GAL_DISPLAY_OPTIONS &aOptions)
Check OpenGL features.
void drawBitmapOverbar(double aLength, double aHeight, bool aReserve=true)
Draw an overbar over the currently drawn text.
bool m_isBitmapFontInitialized
Is the shader set to use bitmap fonts?
static GL_RESET_BUDGET m_resetBudget
Rate of resets tolerated before falling back.
void drawSegmentChain(const std::function< VECTOR2D(int)> &aPointGetter, int aPointCount, double aWidth, bool aReserve=true)
Generic way of drawing a chain of segments stored in different containers.
bool updatedGalDisplayOptions(const GAL_DISPLAY_OPTIONS &aOptions) override
Update handler for OpenGL settings.
unsigned int m_overlayBuffer
Auxiliary rendering target (for menus etc.)
OPENGL_COMPOSITOR * m_compositor
Handles multiple rendering targets.
VERTEX_MANAGER * m_cachedManager
Container for storing cached VERTEX_ITEMs.
void SetPaintListener(wxEvtHandler *aPaintListener)
static bool m_glLoaded
GL entry points are loaded, so resets can be queried.
void drawFilledSemiCircle(const VECTOR2D &aCenterPoint, double aRadius, double aAngle)
Draw a filled semicircle.
void onPaint(wxPaintEvent &aEvent)
This is the OnPaint event handler.
GLint ufm_minLinePixelWidth
int m_ownContextGroupId
Group this canvas' contexts were created in.
static GL_RESET_BUDGET::CLOCK::time_point m_resetDetectedAt
When the last reset was detected, to stop waiting on a driver that never reports completion.
void drawStrokedSemiCircle(const VECTOR2D &aCenterPoint, double aRadius, double aAngle, bool aReserve=true)
Draw a stroked semicircle.
unsigned int getNewGroupNumber()
Return a valid key that can be used as a new group number.
GLint ufm_antialiasingOffset
bool IsVisible() const override
Return true if the GAL canvas is visible on the screen.
wxEvtHandler * m_mouseListener
int m_swapInterval
Used to store swap interval information.
GROUPS_MAP m_groups
Stores information about VBO objects (groups)
void endUpdate() override
Disable item update mode.
GLint ufm_fontTextureWidth
void drawTriangulatedPolyset(const SHAPE_POLY_SET &aPoly, bool aStrokeTriangulation)
Draw a set of polygons with a cached triangulation.
int GetSwapInterval() const override
Return the swap interval. -1 for adaptive, 0 for disabled/unknown.
GAL super
Super class definition.
bool IsContextValid() const override
Check whether the locked context is actually the current one.
void SetMouseListener(wxEvtHandler *aMouseListener)
VERTEX_MANAGER * m_nonCachedManager
Container for storing non-cached VERTEX_ITEMs.
int drawBitmapChar(unsigned long aChar, bool aReserve=true)
Draw a single character using bitmap font.
GLUtesselator * m_tesselator
wxEvtHandler * m_paintListener
void drawGridCoverageShape(const GRID_SOURCE &aSrc)
Fill a source's coverage region into the current color/stencil state.
static bool m_resetSettled
Driver finished the last reset.
bool m_isContextLocked
Used for assertion checking.
bool m_isFramebufferInitialized
Are the framebuffers initialized?
static GLuint g_fontTexture
Bitmap font texture handle (shared)
GAL_CONTEXT_LOSS GetContextLoss() const override
Check whether a GPU reset destroyed this canvas' rendering context.
void reserveLineQuads(const int aLineCount)
Reserve specified number of line quads.
OPENGL_GAL(const KIGFX::VC_SETTINGS &aVcSettings, GAL_DISPLAY_OPTIONS &aDisplayOptions, wxWindow *aParent, wxEvtHandler *aMouseListener=nullptr, wxEvtHandler *aPaintListener=nullptr, const wxString &aName=wxT("GLCanvas"))
void beginUpdate() override
Enable item update mode.
double calcAngleStep(double aRadius) const
Compute the angle step when drawing arcs/circles approximated with lines.
bool m_isGrouping
Was a group started?
GLint ufm_screenPixelSize
GLint ufm_pixelSizeMultiplier
void drawGridSources()
Render m_gridSources priority-descending; each writes its coverage into the stencil so lower-priority...
static int m_contextGroupId
Changes each time a reset kills the shared group.
void drawPolyline(const std::function< VECTOR2D(int)> &aPointGetter, int aPointCount, bool aReserve=true)
Generic way of drawing a polyline stored in different containers.
void skipGestureEvent(wxGestureEvent &aEvent)
Skip the gesture event to the parent.
void drawSemiCircle(const VECTOR2D &aCenterPoint, double aRadius, double aAngle)
Draw a semicircle.
void drawLineQuad(const VECTOR2D &aStartPoint, const VECTOR2D &aEndPoint, bool aReserve=true)
Draw a quad for the line.
VERTEX_MANAGER * m_tempManager
Container for storing temp (diff mode) VERTEX_ITEMs.
void onSetNativeCursor(wxSetCursorEvent &aEvent)
Give the correct cursor image when the native widget asks for it.
SHADER * m_shader
There is only one shader used for different objects.
bool m_isContextValid
Did the last lock make us current?
RENDER_TARGET m_currentTarget
Current rendering target.
wxGLContext * m_glPrivContext
Canvas-specific OpenGL context.
static bool m_isBitmapFontLoaded
Is the bitmap font texture loaded?
static bool m_resetBudgetExhausted
Resets came too often to keep using OpenGL.
static wxGLContext * m_glMainContext
Parent OpenGL context.
unsigned int m_tempBuffer
Temporary rendering target (for diffing etc.)
static int m_instanceCounter
GL GAL instance counter.
bool IsOpenGlEngine() override
Return true if the GAL engine is a OpenGL based type.
Provide the access to the OpenGL shaders.
Class to control vertex container and GPU with possibility of emulating old-style OpenGL 1....
Represent a polyline containing arcs as well as line segments: A chain of connected line and/or arc s...
Represent a set of closed polygons.
An 8 bit string that is assuredly encoded in UTF8, and supplies special conversion support to and fro...
wxCursor WX_CURSOR_TYPE
Represents either a wxCursorBundle for wx 3.3+ or a wxCursor for older versions.
MATRIX3x3< double > MATRIX3x3D
The Cairo implementation of the graphics abstraction layer.
GAL_CONTEXT_LOSS
State of a canvas' rendering context after a GPU reset.
RENDER_TARGET
RENDER_TARGET: Possible rendering targets.
Class to store instances of VERTEX without caching.
Handle multitarget rendering (ie.
#define SEG_PER_CIRCLE_COUNT
The default number of points for circle approximation.
void DrawSegment(const ROUND_SEGMENT_2D &aSegment, unsigned int aNrSidesPerCircle)
Draw a thick line segment with rounded ends.
Render-time projection of a grid: GRID_GEOMETRY (kind/origin/pitch/orientation/extent) plus rendering...
Parameters passed to the GLU tesselator.
VERTEX_MANAGER * vboManager
Manager used for storing new vertices.
std::deque< std::shared_ptr< GLdouble > > & intersectPoints
Intersect points, that have to be freed after tessellation.
Structure to keep VIEW_CONTROLS settings for easy store/restore operations.
VECTOR2< int32_t > VECTOR2I
VECTOR2< double > VECTOR2D
Class to handle an item held in a container.