From e7227a4f217b31ce08d929acb71c672f70305d81 Mon Sep 17 00:00:00 2001 From: Wayne Stambaugh Date: Tue, 16 Feb 2021 17:25:27 -0500 Subject: [PATCH] GAL code cleaning. --- common/draw_panel_gal.cpp | 104 ++--- common/gal/cairo/cairo_compositor.cpp | 40 +- common/gal/cairo/cairo_gal.cpp | 302 +++++++------ common/gal/cairo/cairo_print.cpp | 44 +- common/gal/opengl/antialiasing.cpp | 325 ++++++++------ common/gal/opengl/cached_container.cpp | 32 +- common/gal/opengl/cached_container_gpu.cpp | 42 +- common/gal/opengl/cached_container_ram.cpp | 12 +- common/gal/opengl/gpu_manager.cpp | 56 ++- common/gal/opengl/noncached_container.cpp | 18 +- common/gal/opengl/opengl_compositor.cpp | 104 ++--- common/gal/opengl/opengl_gal.cpp | 468 +++++++++++---------- common/gal/opengl/shader.cpp | 35 +- common/gal/opengl/utils.cpp | 155 ++++--- common/gal/opengl/vertex_container.cpp | 10 +- common/gal/opengl/vertex_item.cpp | 6 +- common/gal/opengl/vertex_manager.cpp | 11 +- 17 files changed, 938 insertions(+), 826 deletions(-) diff --git a/common/draw_panel_gal.cpp b/common/draw_panel_gal.cpp index bd9073e4d6..cfbf5d54e9 100644 --- a/common/draw_panel_gal.cpp +++ b/common/draw_panel_gal.cpp @@ -2,7 +2,8 @@ * This program source code file is part of KiCad, a free EDA CAD application. * * Copyright (C) 2013-2017 CERN - * Copyright (C) 2013-2020 KiCad Developers, see AUTHORS.txt for contributors. + * Copyright (C) 2013-2021 KiCad Developers, see AUTHORS.txt for contributors. + * * @author Tomasz Wlostowski * @author Maciej Suminski * @@ -53,21 +54,20 @@ EDA_DRAW_PANEL_GAL::EDA_DRAW_PANEL_GAL( wxWindow* aParentWindow, wxWindowID aWindowId, const wxPoint& aPosition, const wxSize& aSize, - KIGFX::GAL_DISPLAY_OPTIONS& aOptions, - GAL_TYPE aGalType ) - : wxScrolledCanvas( aParentWindow, aWindowId, aPosition, aSize ), - m_edaFrame( nullptr ), - m_gal( nullptr ), - m_view( nullptr ), - m_painter( nullptr ), - m_viewControls( nullptr ), - m_backend( GAL_TYPE_NONE ), - m_options( aOptions ), - m_eventDispatcher( nullptr ), - m_lostFocus( false ), - m_stealsFocus( true ) + KIGFX::GAL_DISPLAY_OPTIONS& aOptions, GAL_TYPE aGalType ) : + wxScrolledCanvas( aParentWindow, aWindowId, aPosition, aSize ), + m_edaFrame( nullptr ), + m_gal( nullptr ), + m_view( nullptr ), + m_painter( nullptr ), + m_viewControls( nullptr ), + m_backend( GAL_TYPE_NONE ), + m_options( aOptions ), + m_eventDispatcher( nullptr ), + m_lostFocus( false ), + m_stealsFocus( true ) { - m_parent = aParentWindow; + m_parent = aParentWindow; m_currentKiCursor = KICURSOR::DEFAULT; SetCurrentCursor( KICURSOR::ARROW ); @@ -91,23 +91,32 @@ EDA_DRAW_PANEL_GAL::EDA_DRAW_PANEL_GAL( wxWindow* aParentWindow, wxWindowID aWin SetBackgroundStyle( wxBG_STYLE_CUSTOM ); ShowScrollbars( wxSHOW_SB_ALWAYS, wxSHOW_SB_ALWAYS ); - EnableScrolling( false, false ); // otherwise Zoom Auto disables GAL canvas + EnableScrolling( false, false ); // otherwise Zoom Auto disables GAL canvas Connect( wxEVT_SIZE, wxSizeEventHandler( EDA_DRAW_PANEL_GAL::onSize ), NULL, this ); Connect( wxEVT_ENTER_WINDOW, wxMouseEventHandler( EDA_DRAW_PANEL_GAL::onEnter ), NULL, this ); Connect( wxEVT_KILL_FOCUS, wxFocusEventHandler( EDA_DRAW_PANEL_GAL::onLostFocus ), NULL, this ); - Connect( wxEVT_SET_CURSOR, wxSetCursorEventHandler( EDA_DRAW_PANEL_GAL::onSetCursor ), NULL, this ); + Connect( wxEVT_SET_CURSOR, wxSetCursorEventHandler( EDA_DRAW_PANEL_GAL::onSetCursor ), NULL, + this ); - const wxEventType events[] = - { + const wxEventType events[] = { // Binding both EVT_CHAR and EVT_CHAR_HOOK ensures that all key events, // especially special key like arrow keys, are handled by the GAL event dispatcher, // and not sent to GUI without filtering, because they have a default action (scroll) // that must not be called. - wxEVT_LEFT_UP, wxEVT_LEFT_DOWN, wxEVT_LEFT_DCLICK, - wxEVT_RIGHT_UP, wxEVT_RIGHT_DOWN, wxEVT_RIGHT_DCLICK, - wxEVT_MIDDLE_UP, wxEVT_MIDDLE_DOWN, wxEVT_MIDDLE_DCLICK, - wxEVT_MOTION, wxEVT_MOUSEWHEEL, wxEVT_CHAR, wxEVT_CHAR_HOOK, + wxEVT_LEFT_UP, + wxEVT_LEFT_DOWN, + wxEVT_LEFT_DCLICK, + wxEVT_RIGHT_UP, + wxEVT_RIGHT_DOWN, + wxEVT_RIGHT_DCLICK, + wxEVT_MIDDLE_UP, + wxEVT_MIDDLE_DOWN, + wxEVT_MIDDLE_DCLICK, + wxEVT_MOTION, + wxEVT_MOUSEWHEEL, + wxEVT_CHAR, + wxEVT_CHAR_HOOK, #if wxCHECK_VERSION( 3, 1, 0 ) || defined( USE_OSX_MAGNIFY_EVENT ) wxEVT_MAGNIFY, #endif @@ -115,7 +124,8 @@ EDA_DRAW_PANEL_GAL::EDA_DRAW_PANEL_GAL( wxWindow* aParentWindow, wxWindowID aWin }; for( wxEventType eventType : events ) - Connect( eventType, wxEventHandler( EDA_DRAW_PANEL_GAL::OnEvent ), NULL, m_eventDispatcher ); + Connect( eventType, wxEventHandler( EDA_DRAW_PANEL_GAL::OnEvent ), NULL, + m_eventDispatcher ); m_pendingRefresh = false; m_drawing = false; @@ -187,7 +197,8 @@ void EDA_DRAW_PANEL_GAL::DoRePaint() wxASSERT( m_painter ); m_drawing = true; - KIGFX::RENDER_SETTINGS* settings = static_cast( m_painter->GetSettings() ); + KIGFX::RENDER_SETTINGS* settings = + static_cast( m_painter->GetSettings() ); try { @@ -196,7 +207,7 @@ void EDA_DRAW_PANEL_GAL::DoRePaint() KIGFX::GAL_DRAWING_CONTEXT ctx( m_gal ); if( m_view->IsTargetDirty( KIGFX::TARGET_OVERLAY ) - && !m_gal->HasTarget( KIGFX::TARGET_OVERLAY ) ) + && !m_gal->HasTarget( KIGFX::TARGET_OVERLAY ) ) { m_view->MarkDirty(); } @@ -206,14 +217,14 @@ void EDA_DRAW_PANEL_GAL::DoRePaint() m_gal->SetCursorColor( settings->GetCursorColor() ); // TODO: find why ClearScreen() must be called here in opengl mode - // and only if m_view->IsDirty() in Cairo mode to avoid distaly artifacts + // and only if m_view->IsDirty() in Cairo mode to avoid display artifacts // when moving the mouse cursor if( m_backend == GAL_TYPE_OPENGL ) m_gal->ClearScreen(); if( m_view->IsDirty() ) { - if( m_backend != GAL_TYPE_OPENGL && // Already called in opengl + if( m_backend != GAL_TYPE_OPENGL && // Already called in opengl m_view->IsTargetDirty( KIGFX::TARGET_NONCACHED ) ) m_gal->ClearScreen(); @@ -262,7 +273,7 @@ void EDA_DRAW_PANEL_GAL::onSize( wxSizeEvent& aEvent ) return; KIGFX::GAL_CONTEXT_LOCKER locker( m_gal ); - wxSize clientSize = GetClientSize(); + wxSize clientSize = GetClientSize(); WX_INFOBAR* infobar = GetParentEDAFrame() ? GetParentEDAFrame()->GetInfoBar() : nullptr; if( VECTOR2I( clientSize ) == m_gal->GetScreenPixelSize() ) @@ -313,8 +324,6 @@ void EDA_DRAW_PANEL_GAL::Refresh( bool aEraseBackground, const wxRect* aRect ) void EDA_DRAW_PANEL_GAL::ForceRefresh() { - //wxPaintEvent redrawEvent; - //wxPostEvent( this, redrawEvent ); m_pendingRefresh = true; DoRePaint(); } @@ -338,9 +347,10 @@ void EDA_DRAW_PANEL_GAL::SetEventDispatcher( TOOL_DISPATCHER* aEventDispatcher ) for( wxEventType type : eventTypes ) { // While loop is used to be sure that all event handlers are removed. - while( m_parent->Disconnect( type, - wxCommandEventHandler( TOOL_DISPATCHER::DispatchWxCommand ), - NULL, m_eventDispatcher ) ); + while( m_parent->Disconnect( + type, wxCommandEventHandler( TOOL_DISPATCHER::DispatchWxCommand ), NULL, + m_eventDispatcher ) ) + ; } } } @@ -416,9 +426,10 @@ bool EDA_DRAW_PANEL_GAL::SwitchBackend( GAL_TYPE aGalType ) if( GAL_FALLBACK != aGalType ) { aGalType = GAL_FALLBACK; - DisplayInfoMessage( m_parent, - _( "Could not use OpenGL, falling back to software rendering" ), - errormsg ); + DisplayInfoMessage( + m_parent, + _( "Could not use OpenGL, falling back to software rendering" ), + errormsg ); new_gal = new KIGFX::CAIRO_GAL( m_options, this, this, this ); } else @@ -430,9 +441,7 @@ bool EDA_DRAW_PANEL_GAL::SwitchBackend( GAL_TYPE aGalType ) break; } - case GAL_TYPE_CAIRO: - new_gal = new KIGFX::CAIRO_GAL( m_options, this, this, this ); - break; + case GAL_TYPE_CAIRO: new_gal = new KIGFX::CAIRO_GAL( m_options, this, this, this ); break; default: wxASSERT( false ); @@ -455,8 +464,7 @@ bool EDA_DRAW_PANEL_GAL::SwitchBackend( GAL_TYPE aGalType ) result = false; } - // trigger update of the gal options in case they differ - // from the defaults + // trigger update of the gal options in case they differ from the defaults m_options.NotifyChanged(); wxWindow* galWindow = dynamic_cast( new_gal ); @@ -499,9 +507,8 @@ bool EDA_DRAW_PANEL_GAL::SwitchBackend( GAL_TYPE aGalType ) void EDA_DRAW_PANEL_GAL::OnEvent( wxEvent& aEvent ) { - bool shouldSetFocus = m_lostFocus && m_stealsFocus - && !KIUI::IsInputControlFocused() - && !KIUI::IsModalDialogFocused(); + bool shouldSetFocus = m_lostFocus && m_stealsFocus && !KIUI::IsInputControlFocused() + && !KIUI::IsModalDialogFocused(); #if defined( _WIN32 ) // Ensure we are the active foreground window before we attempt to steal focus @@ -523,9 +530,8 @@ void EDA_DRAW_PANEL_GAL::OnEvent( wxEvent& aEvent ) void EDA_DRAW_PANEL_GAL::onEnter( wxMouseEvent& aEvent ) { - bool shouldSetFocus = m_stealsFocus - && !KIUI::IsInputControlFocused() - && !KIUI::IsModalDialogFocused(); + bool shouldSetFocus = + m_stealsFocus && !KIUI::IsInputControlFocused() && !KIUI::IsModalDialogFocused(); #if defined( _WIN32 ) // Ensure we are the active foreground window before we attempt to steal focus @@ -570,8 +576,6 @@ void EDA_DRAW_PANEL_GAL::onRefreshTimer( wxTimerEvent& aEvent ) } } - //wxPaintEvent redrawEvent; - //wxPostEvent( this, redrawEvent ); DoRePaint(); } diff --git a/common/gal/cairo/cairo_compositor.cpp b/common/gal/cairo/cairo_compositor.cpp index b6f0439903..40d8f224f9 100644 --- a/common/gal/cairo/cairo_compositor.cpp +++ b/common/gal/cairo/cairo_compositor.cpp @@ -2,7 +2,8 @@ * This program source code file is part of KiCad, a free EDA CAD application. * * Copyright (C) 2013 CERN - * Copyright (C) 2019 KiCad Developers, see AUTHORS.txt for contributors. + * Copyright (C) 2019-2021 KiCad Developers, see AUTHORS.txt for contributors. + * * @author Maciej Suminski * * This program is free software; you can redistribute it and/or @@ -35,8 +36,10 @@ using namespace KIGFX; CAIRO_COMPOSITOR::CAIRO_COMPOSITOR( cairo_t** aMainContext ) : - m_current( 0 ), m_currentContext( aMainContext ), m_mainContext( *aMainContext ), - m_currentAntialiasingMode( CAIRO_ANTIALIAS_DEFAULT ) + m_current( 0 ), + m_currentContext( aMainContext ), + m_mainContext( *aMainContext ), + m_currentAntialiasingMode( CAIRO_ANTIALIAS_DEFAULT ) { // Do not have uninitialized members: cairo_matrix_init_identity( &m_matrix ); @@ -59,20 +62,12 @@ void CAIRO_COMPOSITOR::Initialize() void CAIRO_COMPOSITOR::SetAntialiasingMode( CAIRO_ANTIALIASING_MODE aMode ) { - switch( aMode ) { - case CAIRO_ANTIALIASING_MODE::FAST: - m_currentAntialiasingMode = CAIRO_ANTIALIAS_FAST; - break; - case CAIRO_ANTIALIASING_MODE::GOOD: - m_currentAntialiasingMode = CAIRO_ANTIALIAS_GOOD; - break; - case CAIRO_ANTIALIASING_MODE::BEST: - m_currentAntialiasingMode = CAIRO_ANTIALIAS_BEST; - break; - default: - m_currentAntialiasingMode = CAIRO_ANTIALIAS_NONE; + case CAIRO_ANTIALIASING_MODE::FAST: m_currentAntialiasingMode = CAIRO_ANTIALIAS_FAST; break; + case CAIRO_ANTIALIASING_MODE::GOOD: m_currentAntialiasingMode = CAIRO_ANTIALIAS_GOOD; break; + case CAIRO_ANTIALIASING_MODE::BEST: m_currentAntialiasingMode = CAIRO_ANTIALIAS_BEST; break; + default: m_currentAntialiasingMode = CAIRO_ANTIALIAS_NONE; } clean(); @@ -83,10 +78,10 @@ void CAIRO_COMPOSITOR::Resize( unsigned int aWidth, unsigned int aHeight ) { clean(); - m_width = aWidth; + m_width = aWidth; m_height = aHeight; - m_stride = cairo_format_stride_for_width( CAIRO_FORMAT_ARGB32, m_width ); + m_stride = cairo_format_stride_for_width( CAIRO_FORMAT_ARGB32, m_width ); m_bufferSize = m_stride * m_height; } @@ -98,10 +93,9 @@ unsigned int CAIRO_COMPOSITOR::CreateBuffer() // Create the Cairo surface cairo_surface_t* surface = cairo_image_surface_create_for_data( - (unsigned char*) bitmap, - CAIRO_FORMAT_ARGB32, m_width, - m_height, m_stride ); + (unsigned char*) bitmap, CAIRO_FORMAT_ARGB32, m_width, m_height, m_stride ); cairo_t* context = cairo_create( surface ); + #ifdef DEBUG cairo_status_t status = cairo_status( context ); wxASSERT_MSG( status == CAIRO_STATUS_SUCCESS, wxT( "Cairo context creation error" ) ); @@ -136,14 +130,16 @@ void CAIRO_COMPOSITOR::SetBuffer( unsigned int aBufferHandle ) cairo_set_matrix( *m_currentContext, &m_matrix ); } + void CAIRO_COMPOSITOR::Begin() { } + void CAIRO_COMPOSITOR::ClearBuffer( const COLOR4D& aColor ) { // Clear the pixel storage - memset( m_buffers[m_current].bitmap, 0x00, m_bufferSize * sizeof(int) ); + memset( m_buffers[m_current].bitmap, 0x00, m_bufferSize * sizeof( int ) ); } @@ -164,10 +160,12 @@ void CAIRO_COMPOSITOR::DrawBuffer( unsigned int aBufferHandle ) cairo_set_matrix( m_mainContext, &m_matrix ); } + void CAIRO_COMPOSITOR::Present() { } + void CAIRO_COMPOSITOR::clean() { CAIRO_BUFFERS::const_iterator it; diff --git a/common/gal/cairo/cairo_gal.cpp b/common/gal/cairo/cairo_gal.cpp index aae049a0eb..e7bd28c4c3 100644 --- a/common/gal/cairo/cairo_gal.cpp +++ b/common/gal/cairo/cairo_gal.cpp @@ -2,8 +2,9 @@ * This program source code file is part of KICAD, a free EDA CAD application. * * Copyright (C) 2012 Torsten Hueter, torstenhtr gmx.de - * Copyright (C) 2012-2020 Kicad Developers, see AUTHORS.txt for contributors. + * Copyright (C) 2012-2021 Kicad Developers, see AUTHORS.txt for contributors. * Copyright (C) 2017-2018 CERN + * * @author Maciej Suminski * * CairoGal - Graphics Abstraction Layer for Cairo @@ -33,7 +34,7 @@ #include #include #include -#include // for KiROUND +#include // for KiROUND #include #include @@ -45,15 +46,13 @@ using namespace KIGFX; - -CAIRO_GAL_BASE::CAIRO_GAL_BASE( GAL_DISPLAY_OPTIONS& aDisplayOptions ) : - GAL( aDisplayOptions ) +CAIRO_GAL_BASE::CAIRO_GAL_BASE( GAL_DISPLAY_OPTIONS& aDisplayOptions ) : GAL( aDisplayOptions ) { // Initialise grouping - isGrouping = false; - isElementAdded = false; - groupCounter = 0; - currentGroup = nullptr; + isGrouping = false; + isElementAdded = false; + groupCounter = 0; + currentGroup = nullptr; lineWidth = 1.0; linePixelWidth = 1.0; @@ -62,9 +61,9 @@ CAIRO_GAL_BASE::CAIRO_GAL_BASE( GAL_DISPLAY_OPTIONS& aDisplayOptions ) : // Initialise Cairo state cairo_matrix_init_identity( &cairoWorldScreenMatrix ); - currentContext = nullptr; - context = nullptr; - surface = nullptr; + currentContext = nullptr; + context = nullptr; + surface = nullptr; // Grid color settings are different in Cairo and OpenGL SetGridColor( COLOR4D( 0.1, 0.1, 0.1, 0.8 ) ); @@ -103,6 +102,7 @@ void CAIRO_GAL_BASE::endDrawing() Flush(); } + void CAIRO_GAL_BASE::updateWorldScreenMatrix() { cairo_matrix_multiply( ¤tWorld2Screen, ¤tXform, &cairoWorldScreenMatrix ); @@ -164,8 +164,8 @@ void CAIRO_GAL_BASE::arc_angles_xform_and_normalize( double& aStartAngle, double // So, if this is the case, force the aEndAngle value to draw a circle. aStartAngle = angle_xform( startAngle ); - if( std::abs( aEndAngle - aStartAngle ) >= 2*M_PI ) // arc is a full circle - aEndAngle = aStartAngle + 2*M_PI; + if( std::abs( aEndAngle - aStartAngle ) >= 2 * M_PI ) // arc is a full circle + aEndAngle = aStartAngle + 2 * M_PI; else aEndAngle = angle_xform( endAngle ); } @@ -210,9 +210,9 @@ void CAIRO_GAL_BASE::DrawLine( const VECTOR2D& aStartPoint, const VECTOR2D& aEnd void CAIRO_GAL_BASE::syncLineWidth( bool aForceWidth, double aWidth ) { - auto w = floor( xform( aForceWidth ? aWidth : lineWidth ) + 0.5 ); + auto w = floor( xform( aForceWidth ? aWidth : lineWidth ) + 0.5 ); - if (w <= 1.0) + if( w <= 1.0 ) { w = 1.0; cairo_set_line_join( currentContext, CAIRO_LINE_JOIN_MITER ); @@ -225,7 +225,7 @@ void CAIRO_GAL_BASE::syncLineWidth( bool aForceWidth, double aWidth ) cairo_set_line_join( currentContext, CAIRO_LINE_JOIN_ROUND ); cairo_set_line_cap( currentContext, CAIRO_LINE_CAP_ROUND ); cairo_set_line_width( currentContext, w ); - lineWidthIsOdd = ((int)w % 2) == 1; + lineWidthIsOdd = ( (int) w % 2 ) == 1; } lineWidthInPixels = w; @@ -233,7 +233,7 @@ void CAIRO_GAL_BASE::syncLineWidth( bool aForceWidth, double aWidth ) void CAIRO_GAL_BASE::DrawSegment( const VECTOR2D& aStartPoint, const VECTOR2D& aEndPoint, - double aWidth ) + double aWidth ) { if( isFillEnabled ) { @@ -255,20 +255,21 @@ void CAIRO_GAL_BASE::DrawSegment( const VECTOR2D& aStartPoint, const VECTOR2D& a // Outline mode for tracks VECTOR2D startEndVector = aEndPoint - aStartPoint; - double lineAngle = atan2( startEndVector.y, startEndVector.x ); + double lineAngle = atan2( startEndVector.y, startEndVector.x ); double sa = sin( lineAngle + M_PI / 2.0 ); double ca = cos( lineAngle + M_PI / 2.0 ); - auto pa0 = xform ( aStartPoint + VECTOR2D(aWidth * ca, aWidth * sa ) ); - auto pa1 = xform ( aStartPoint - VECTOR2D(aWidth * ca, aWidth * sa ) ); - auto pb0 = xform ( aEndPoint + VECTOR2D(aWidth * ca, aWidth * sa ) ); - auto pb1 = xform ( aEndPoint - VECTOR2D(aWidth * ca, aWidth * sa ) ); + auto pa0 = xform( aStartPoint + VECTOR2D( aWidth * ca, aWidth * sa ) ); + auto pa1 = xform( aStartPoint - VECTOR2D( aWidth * ca, aWidth * sa ) ); + auto pb0 = xform( aEndPoint + VECTOR2D( aWidth * ca, aWidth * sa ) ); + auto pb1 = xform( aEndPoint - VECTOR2D( aWidth * ca, aWidth * sa ) ); auto pa = xform( aStartPoint ); auto pb = xform( aEndPoint ); - auto rb = (pa0 - pa).EuclideanNorm(); + auto rb = ( pa0 - pa ).EuclideanNorm(); - cairo_set_source_rgba( currentContext, strokeColor.r, strokeColor.g, strokeColor.b, strokeColor.a ); + cairo_set_source_rgba( currentContext, strokeColor.r, strokeColor.g, strokeColor.b, + strokeColor.a ); cairo_move_to( currentContext, pa0.x, pa0.y ); cairo_line_to( currentContext, pb0.x, pb0.y ); @@ -277,7 +278,8 @@ void CAIRO_GAL_BASE::DrawSegment( const VECTOR2D& aStartPoint, const VECTOR2D& a cairo_line_to( currentContext, pb1.x, pb1.y ); cairo_arc( currentContext, pb.x, pb.y, rb, lineAngle - M_PI / 2.0, lineAngle + M_PI / 2.0 ); - cairo_arc( currentContext, pa.x, pa.y, rb, lineAngle + M_PI / 2.0, lineAngle + 3.0 * M_PI / 2.0 ); + cairo_arc( currentContext, pa.x, pa.y, rb, lineAngle + M_PI / 2.0, + lineAngle + 3.0 * M_PI / 2.0 ); flushPath(); } @@ -303,7 +305,7 @@ void CAIRO_GAL_BASE::DrawCircle( const VECTOR2D& aCenterPoint, double aRadius ) void CAIRO_GAL_BASE::DrawArc( const VECTOR2D& aCenterPoint, double aRadius, double aStartAngle, - double aEndAngle ) + double aEndAngle ) { syncLineWidth(); @@ -338,8 +340,8 @@ void CAIRO_GAL_BASE::DrawArc( const VECTOR2D& aCenterPoint, double aRadius, doub } -void CAIRO_GAL_BASE::DrawArcSegment( const VECTOR2D& aCenterPoint, double aRadius, double aStartAngle, - double aEndAngle, double aWidth ) +void CAIRO_GAL_BASE::DrawArcSegment( const VECTOR2D& aCenterPoint, double aRadius, + double aStartAngle, double aEndAngle, double aWidth ) { if( isFillEnabled ) { @@ -368,14 +370,15 @@ void CAIRO_GAL_BASE::DrawArcSegment( const VECTOR2D& aCenterPoint, double aRadiu // whole arc to change position/size lineWidthIsOdd = !( static_cast( aRadius ) % 2 ); - auto mid = roundp( xform( aCenterPoint ) ); + auto mid = roundp( xform( aCenterPoint ) ); double width = xform( aWidth / 2.0 ); - auto startPointS = VECTOR2D( r, 0.0 ).Rotate( startAngleS ); - auto endPointS = VECTOR2D( r, 0.0 ).Rotate( endAngleS ); + auto startPointS = VECTOR2D( r, 0.0 ).Rotate( startAngleS ); + auto endPointS = VECTOR2D( r, 0.0 ).Rotate( endAngleS ); cairo_save( currentContext ); - cairo_set_source_rgba( currentContext, strokeColor.r, strokeColor.g, strokeColor.b, strokeColor.a ); + cairo_set_source_rgba( currentContext, strokeColor.r, strokeColor.g, strokeColor.b, + strokeColor.a ); cairo_translate( currentContext, mid.x, mid.y ); @@ -386,7 +389,8 @@ void CAIRO_GAL_BASE::DrawArcSegment( const VECTOR2D& aCenterPoint, double aRadiu cairo_arc( currentContext, 0, 0, r + width, startAngleS, endAngleS ); cairo_new_sub_path( currentContext ); - cairo_arc_negative( currentContext, startPointS.x, startPointS.y, width, startAngleS, startAngleS + M_PI ); + cairo_arc_negative( currentContext, startPointS.x, startPointS.y, width, startAngleS, + startAngleS + M_PI ); cairo_new_sub_path( currentContext ); cairo_arc( currentContext, endPointS.x, endPointS.y, width, endAngleS, endAngleS + M_PI ); @@ -477,12 +481,12 @@ void CAIRO_GAL_BASE::DrawBitmap( const BITMAP_BASE& aBitmap ) cairo_surface_flush( image ); unsigned char* pix_buffer = cairo_image_surface_get_data( image ); + // The pixel buffer of the initial bitmap: const wxImage& bm_pix_buffer = *aBitmap.GetImageData(); - uint32_t mask_color = ( bm_pix_buffer.GetMaskRed() << 16 ) + - ( bm_pix_buffer.GetMaskGreen() << 8 ) + - ( bm_pix_buffer.GetMaskBlue() ); + uint32_t mask_color = ( bm_pix_buffer.GetMaskRed() << 16 ) + + ( bm_pix_buffer.GetMaskGreen() << 8 ) + ( bm_pix_buffer.GetMaskBlue() ); // Copy the source bitmap to the cairo bitmap buffer. // In cairo bitmap buffer, a ARGB32 bitmap is an ARGB pixel packed into a uint_32 @@ -639,12 +643,9 @@ void CAIRO_GAL_BASE::Transform( const MATRIX3x3D& aTransformation ) { cairo_matrix_t cairoTransformation, newXform; - cairo_matrix_init( &cairoTransformation, - aTransformation.m_data[0][0], - aTransformation.m_data[1][0], - aTransformation.m_data[0][1], - aTransformation.m_data[1][1], - aTransformation.m_data[0][2], + cairo_matrix_init( &cairoTransformation, aTransformation.m_data[0][0], + aTransformation.m_data[1][0], aTransformation.m_data[0][1], + aTransformation.m_data[1][1], aTransformation.m_data[0][2], aTransformation.m_data[1][2] ); cairo_matrix_multiply( &newXform, ¤tXform, &cairoTransformation ); @@ -686,7 +687,7 @@ void CAIRO_GAL_BASE::Translate( const VECTOR2D& aTranslation ) } else { - cairo_matrix_translate ( ¤tXform, aTranslation.x, aTranslation.y ); + cairo_matrix_translate( ¤tXform, aTranslation.x, aTranslation.y ); updateWorldScreenMatrix(); } } @@ -759,10 +760,10 @@ int CAIRO_GAL_BASE::BeginGroup() storePath(); GROUP group; - int groupNumber = getNewGroupNumber(); + int groupNumber = getNewGroupNumber(); groups.insert( std::make_pair( groupNumber, group ) ); currentGroup = &groups[groupNumber]; - isGrouping = true; + isGrouping = true; return groupNumber; } @@ -782,8 +783,7 @@ void CAIRO_GAL_BASE::DrawGroup( int aGroupNumber ) storePath(); - for( GROUP::iterator it = groups[aGroupNumber].begin(); - it != groups[aGroupNumber].end(); ++it ) + for( GROUP::iterator it = groups[aGroupNumber].begin(); it != groups[aGroupNumber].end(); ++it ) { switch( it->command ) { @@ -796,34 +796,36 @@ void CAIRO_GAL_BASE::DrawGroup( int aGroupNumber ) break; case CMD_SET_FILLCOLOR: - fillColor = COLOR4D( it->argument.dblArg[0], it->argument.dblArg[1], it->argument.dblArg[2], - it->argument.dblArg[3] ); + fillColor = COLOR4D( it->argument.dblArg[0], it->argument.dblArg[1], + it->argument.dblArg[2], it->argument.dblArg[3] ); break; case CMD_SET_STROKECOLOR: - strokeColor = COLOR4D( it->argument.dblArg[0], it->argument.dblArg[1], it->argument.dblArg[2], - it->argument.dblArg[3] ); + strokeColor = COLOR4D( it->argument.dblArg[0], it->argument.dblArg[1], + it->argument.dblArg[2], it->argument.dblArg[3] ); break; case CMD_SET_LINE_WIDTH: - { - // Make lines appear at least 1 pixel wide, no matter of zoom - double x = 1.0, y = 1.0; - cairo_device_to_user_distance( currentContext, &x, &y ); - double minWidth = std::min( fabs( x ), fabs( y ) ); - cairo_set_line_width( currentContext, std::max( it->argument.dblArg[0], minWidth ) ); - } + { + // Make lines appear at least 1 pixel wide, no matter of zoom + double x = 1.0, y = 1.0; + cairo_device_to_user_distance( currentContext, &x, &y ); + double minWidth = std::min( fabs( x ), fabs( y ) ); + cairo_set_line_width( currentContext, std::max( it->argument.dblArg[0], minWidth ) ); break; + } case CMD_STROKE_PATH: - cairo_set_source_rgba( currentContext, strokeColor.r, strokeColor.g, strokeColor.b, strokeColor.a ); + cairo_set_source_rgba( currentContext, strokeColor.r, strokeColor.g, strokeColor.b, + strokeColor.a ); cairo_append_path( currentContext, it->cairoPath ); cairo_stroke( currentContext ); break; case CMD_FILL_PATH: - cairo_set_source_rgba( currentContext, fillColor.r, fillColor.g, fillColor.b, strokeColor.a ); + cairo_set_source_rgba( currentContext, fillColor.r, fillColor.g, fillColor.b, + strokeColor.a ); cairo_append_path( currentContext, it->cairoPath ); cairo_fill( currentContext ); break; @@ -869,8 +871,7 @@ void CAIRO_GAL_BASE::ChangeGroupColor( int aGroupNumber, const COLOR4D& aNewColo { storePath(); - for( GROUP::iterator it = groups[aGroupNumber].begin(); - it != groups[aGroupNumber].end(); ++it ) + for( GROUP::iterator it = groups[aGroupNumber].begin(); it != groups[aGroupNumber].end(); ++it ) { if( it->command == CMD_SET_FILLCOLOR || it->command == CMD_SET_STROKECOLOR ) { @@ -972,10 +973,10 @@ void CAIRO_GAL_BASE::drawAxes( const VECTOR2D& aStartPoint, const VECTOR2D& aEnd auto p0 = roundp( xform( aStartPoint ) ); auto p1 = roundp( xform( aEndPoint ) ); - auto org = roundp( xform( VECTOR2D( 0.0, 0.0 ) ) ); // Axis origin = 0,0 coord + auto org = roundp( xform( VECTOR2D( 0.0, 0.0 ) ) ); // Axis origin = 0,0 coord cairo_set_source_rgba( currentContext, axesColor.r, axesColor.g, axesColor.b, axesColor.a ); - cairo_move_to( currentContext, p0.x, org.y); + cairo_move_to( currentContext, p0.x, org.y ); cairo_line_to( currentContext, p1.x, org.y ); cairo_move_to( currentContext, org.x, p0.y ); cairo_line_to( currentContext, org.x, p1.y ); @@ -1000,7 +1001,7 @@ void CAIRO_GAL_BASE::drawGridCross( const VECTOR2D& aPoint ) { syncLineWidth(); VECTOR2D offset( 0, 0 ); - double size = 2.0 * lineWidthInPixels + 0.5; + double size = 2.0 * lineWidthInPixels + 0.5; VECTOR2D p0 = roundp( xform( aPoint ) ) - VECTOR2D( size, 0 ) + offset; VECTOR2D p1 = roundp( xform( aPoint ) ) + VECTOR2D( size, 0 ) + offset; @@ -1025,30 +1026,30 @@ void CAIRO_GAL_BASE::drawGridPoint( const VECTOR2D& aPoint, double aWidth, doubl cairo_set_source_rgba( currentContext, gridColor.r, gridColor.g, gridColor.b, gridColor.a ); cairo_rectangle( currentContext, p.x - std::floor( sw / 2 ) - 0.5, - p.y - std::floor( sh / 2 ) - 0.5, sw, sh ); + p.y - std::floor( sh / 2 ) - 0.5, sw, sh ); cairo_fill( currentContext ); } + void CAIRO_GAL_BASE::flushPath() { - if( isFillEnabled ) - { - cairo_set_source_rgba( currentContext, - fillColor.r, fillColor.g, fillColor.b, fillColor.a ); + if( isFillEnabled ) + { + cairo_set_source_rgba( currentContext, fillColor.r, fillColor.g, fillColor.b, fillColor.a ); - if( isStrokeEnabled ) - cairo_fill_preserve( currentContext ); - else - cairo_fill( currentContext ); - } + if( isStrokeEnabled ) + cairo_fill_preserve( currentContext ); + else + cairo_fill( currentContext ); + } - if( isStrokeEnabled ) - { - cairo_set_source_rgba( currentContext, - strokeColor.r, strokeColor.g, strokeColor.b, strokeColor.a ); - cairo_stroke( currentContext ); - } + if( isStrokeEnabled ) + { + cairo_set_source_rgba( currentContext, strokeColor.r, strokeColor.g, strokeColor.b, + strokeColor.a ); + cairo_stroke( currentContext ); + } } @@ -1062,14 +1063,15 @@ void CAIRO_GAL_BASE::storePath() { if( isFillEnabled ) { - cairo_set_source_rgba( currentContext, fillColor.r, fillColor.g, fillColor.b, fillColor.a ); + cairo_set_source_rgba( currentContext, fillColor.r, fillColor.g, fillColor.b, + fillColor.a ); cairo_fill_preserve( currentContext ); } if( isStrokeEnabled ) { - cairo_set_source_rgba( currentContext, strokeColor.r, strokeColor.g, - strokeColor.b, strokeColor.a ); + cairo_set_source_rgba( currentContext, strokeColor.r, strokeColor.g, strokeColor.b, + strokeColor.a ); cairo_stroke_preserve( currentContext ); } } @@ -1082,7 +1084,7 @@ void CAIRO_GAL_BASE::storePath() { GROUP_ELEMENT groupElement; groupElement.cairoPath = cairo_copy_path( currentContext ); - groupElement.command = CMD_STROKE_PATH; + groupElement.command = CMD_STROKE_PATH; currentGroup->push_back( groupElement ); } @@ -1090,7 +1092,7 @@ void CAIRO_GAL_BASE::storePath() { GROUP_ELEMENT groupElement; groupElement.cairoPath = cairo_copy_path( currentContext ); - groupElement.command = CMD_FILL_PATH; + groupElement.command = CMD_FILL_PATH; currentGroup->push_back( groupElement ); } } @@ -1108,10 +1110,10 @@ void CAIRO_GAL_BASE::blitCursor( wxMemoryDC& clientDC ) auto p = ToScreen( cursorPosition ); const auto cColor = getCursorColor(); - const int cursorSize = fullscreenCursor ? 8000 : 80; + const int cursorSize = fullscreenCursor ? 8000 : 80; - wxColour color( cColor.r * cColor.a * 255, cColor.g * cColor.a * 255, - cColor.b * cColor.a * 255, 255 ); + wxColour color( cColor.r * cColor.a * 255, cColor.g * cColor.a * 255, cColor.b * cColor.a * 255, + 255 ); clientDC.SetPen( wxPen( color ) ); clientDC.DrawLine( p.x - cursorSize / 2, p.y, p.x + cursorSize / 2, p.y ); clientDC.DrawLine( p.x, p.y - cursorSize / 2, p.x, p.y + cursorSize / 2 ); @@ -1179,13 +1181,13 @@ void CAIRO_GAL_BASE::drawPoly( const SHAPE_LINE_CHAIN& aLineChain ) numPoints += 1; const VECTOR2I start = aLineChain.CPoint( 0 ); - const auto p = roundp( xform( start.x, start.y ) ); + const auto p = roundp( xform( start.x, start.y ) ); cairo_move_to( currentContext, p.x, p.y ); for( int i = 1; i < numPoints; ++i ) { const VECTOR2I& pw = aLineChain.CPoint( i ); - const auto ps = roundp( xform( pw.x, pw.y ) ); + const auto ps = roundp( xform( pw.x, pw.y ) ); cairo_line_to( currentContext, ps.x, ps.y ); } @@ -1206,42 +1208,42 @@ unsigned int CAIRO_GAL_BASE::getNewGroupNumber() } -CAIRO_GAL::CAIRO_GAL( GAL_DISPLAY_OPTIONS& aDisplayOptions, - wxWindow* aParent, wxEvtHandler* aMouseListener, - wxEvtHandler* aPaintListener, const wxString& aName ) : - CAIRO_GAL_BASE( aDisplayOptions ), - wxWindow( aParent, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxEXPAND, aName ) +CAIRO_GAL::CAIRO_GAL( GAL_DISPLAY_OPTIONS& aDisplayOptions, wxWindow* aParent, + wxEvtHandler* aMouseListener, wxEvtHandler* aPaintListener, + const wxString& aName ) : + CAIRO_GAL_BASE( aDisplayOptions ), + wxWindow( aParent, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxEXPAND, aName ) { // Initialise compositing state - mainBuffer = 0; - overlayBuffer = 0; - validCompositor = false; + mainBuffer = 0; + overlayBuffer = 0; + validCompositor = false; SetTarget( TARGET_NONCACHED ); - bitmapBuffer = nullptr; - wxOutput = nullptr; + bitmapBuffer = nullptr; + wxOutput = nullptr; - parentWindow = aParent; + parentWindow = aParent; mouseListener = aMouseListener; paintListener = aPaintListener; // Connecting the event handlers - Connect( wxEVT_PAINT, wxPaintEventHandler( CAIRO_GAL::onPaint ) ); + Connect( wxEVT_PAINT, wxPaintEventHandler( CAIRO_GAL::onPaint ) ); // Mouse events are skipped to the parent - Connect( wxEVT_MOTION, wxMouseEventHandler( CAIRO_GAL::skipMouseEvent ) ); - Connect( wxEVT_LEFT_DOWN, wxMouseEventHandler( CAIRO_GAL::skipMouseEvent ) ); - Connect( wxEVT_LEFT_UP, wxMouseEventHandler( CAIRO_GAL::skipMouseEvent ) ); - Connect( wxEVT_LEFT_DCLICK, wxMouseEventHandler( CAIRO_GAL::skipMouseEvent ) ); - Connect( wxEVT_MIDDLE_DOWN, wxMouseEventHandler( CAIRO_GAL::skipMouseEvent ) ); - Connect( wxEVT_MIDDLE_UP, wxMouseEventHandler( CAIRO_GAL::skipMouseEvent ) ); - Connect( wxEVT_MIDDLE_DCLICK, wxMouseEventHandler( CAIRO_GAL::skipMouseEvent ) ); - Connect( wxEVT_RIGHT_DOWN, wxMouseEventHandler( CAIRO_GAL::skipMouseEvent ) ); - Connect( wxEVT_RIGHT_UP, wxMouseEventHandler( CAIRO_GAL::skipMouseEvent ) ); - Connect( wxEVT_RIGHT_DCLICK, wxMouseEventHandler( CAIRO_GAL::skipMouseEvent ) ); - Connect( wxEVT_MOUSEWHEEL, wxMouseEventHandler( CAIRO_GAL::skipMouseEvent ) ); + Connect( wxEVT_MOTION, wxMouseEventHandler( CAIRO_GAL::skipMouseEvent ) ); + Connect( wxEVT_LEFT_DOWN, wxMouseEventHandler( CAIRO_GAL::skipMouseEvent ) ); + Connect( wxEVT_LEFT_UP, wxMouseEventHandler( CAIRO_GAL::skipMouseEvent ) ); + Connect( wxEVT_LEFT_DCLICK, wxMouseEventHandler( CAIRO_GAL::skipMouseEvent ) ); + Connect( wxEVT_MIDDLE_DOWN, wxMouseEventHandler( CAIRO_GAL::skipMouseEvent ) ); + Connect( wxEVT_MIDDLE_UP, wxMouseEventHandler( CAIRO_GAL::skipMouseEvent ) ); + Connect( wxEVT_MIDDLE_DCLICK, wxMouseEventHandler( CAIRO_GAL::skipMouseEvent ) ); + Connect( wxEVT_RIGHT_DOWN, wxMouseEventHandler( CAIRO_GAL::skipMouseEvent ) ); + Connect( wxEVT_RIGHT_UP, wxMouseEventHandler( CAIRO_GAL::skipMouseEvent ) ); + Connect( wxEVT_RIGHT_DCLICK, wxMouseEventHandler( CAIRO_GAL::skipMouseEvent ) ); + Connect( wxEVT_MOUSEWHEEL, wxMouseEventHandler( CAIRO_GAL::skipMouseEvent ) ); #if defined _WIN32 || defined _WIN64 - Connect( wxEVT_ENTER_WINDOW, wxMouseEventHandler( CAIRO_GAL::skipMouseEvent ) ); + Connect( wxEVT_ENTER_WINDOW, wxMouseEventHandler( CAIRO_GAL::skipMouseEvent ) ); #endif SetSize( aParent->GetClientSize() ); @@ -1286,21 +1288,22 @@ void CAIRO_GAL::endDrawing() // by cairo into a format understood by wxImage. pixman_image_t* dstImg = pixman_image_create_bits( - wxPlatformInfo::Get().GetEndianness() == wxENDIAN_LITTLE ? PIXMAN_b8g8r8 : - PIXMAN_r8g8b8, + wxPlatformInfo::Get().GetEndianness() == wxENDIAN_LITTLE ? PIXMAN_b8g8r8 + : PIXMAN_r8g8b8, screenSize.x, screenSize.y, (uint32_t*) wxOutput, wxBufferWidth * 3 ); - pixman_image_t* srcImg = pixman_image_create_bits( PIXMAN_a8r8g8b8, screenSize.x, screenSize.y, - (uint32_t*) bitmapBuffer, wxBufferWidth * 4 ); + pixman_image_t* srcImg = + pixman_image_create_bits( PIXMAN_a8r8g8b8, screenSize.x, screenSize.y, + (uint32_t*) bitmapBuffer, wxBufferWidth * 4 ); - pixman_image_composite( PIXMAN_OP_SRC, srcImg, NULL, dstImg, - 0, 0, 0, 0, 0, 0, screenSize.x, screenSize.y ); + pixman_image_composite( PIXMAN_OP_SRC, srcImg, NULL, dstImg, 0, 0, 0, 0, 0, 0, screenSize.x, + screenSize.y ); // Free allocated memory pixman_image_unref( srcImg ); pixman_image_unref( dstImg ); - wxImage img( wxBufferWidth, screenSize.y, wxOutput, true ); - wxBitmap bmp( img ); + wxImage img( wxBufferWidth, screenSize.y, wxOutput, true ); + wxBitmap bmp( img ); wxMemoryDC mdc( bmp ); wxClientDC clientDC( this ); @@ -1379,13 +1382,9 @@ void CAIRO_GAL::SetTarget( RENDER_TARGET aTarget ) { default: case TARGET_CACHED: - case TARGET_NONCACHED: - compositor->SetBuffer( mainBuffer ); - break; + case TARGET_NONCACHED: compositor->SetBuffer( mainBuffer ); break; - case TARGET_OVERLAY: - compositor->SetBuffer( overlayBuffer ); - break; + case TARGET_OVERLAY: compositor->SetBuffer( overlayBuffer ); break; } currentTarget = aTarget; @@ -1408,13 +1407,8 @@ void CAIRO_GAL::ClearTarget( RENDER_TARGET aTarget ) // Cached and noncached items are rendered to the same buffer default: case TARGET_CACHED: - case TARGET_NONCACHED: - compositor->SetBuffer( mainBuffer ); - break; - - case TARGET_OVERLAY: - compositor->SetBuffer( overlayBuffer ); - break; + case TARGET_NONCACHED: compositor->SetBuffer( mainBuffer ); break; + case TARGET_OVERLAY: compositor->SetBuffer( overlayBuffer ); break; } compositor->ClearBuffer( COLOR4D::BLACK ); @@ -1429,8 +1423,8 @@ void CAIRO_GAL::initSurface() if( isInitialized ) return; - surface = cairo_image_surface_create_for_data( bitmapBuffer, GAL_FORMAT, - wxBufferWidth, screenSize.y, stride ); + surface = cairo_image_surface_create_for_data( bitmapBuffer, GAL_FORMAT, wxBufferWidth, + screenSize.y, stride ); context = cairo_create( surface ); @@ -1438,6 +1432,7 @@ void CAIRO_GAL::initSurface() cairo_status_t status = cairo_status( context ); wxASSERT_MSG( status == CAIRO_STATUS_SUCCESS, wxT( "Cairo context creation error" ) ); #endif /* DEBUG */ + currentContext = context; isInitialized = true; @@ -1461,10 +1456,12 @@ void CAIRO_GAL::deinitSurface() void CAIRO_GAL::allocateBitmaps() { wxBufferWidth = screenSize.x; - while( ( ( wxBufferWidth * 3 ) % 4 ) != 0 ) wxBufferWidth++; + + while( ( ( wxBufferWidth * 3 ) % 4 ) != 0 ) + wxBufferWidth++; // Create buffer, use the system independent Cairo context backend - stride = cairo_format_stride_for_width( GAL_FORMAT, wxBufferWidth ); + stride = cairo_format_stride_for_width( GAL_FORMAT, wxBufferWidth ); bufferSize = stride * screenSize.y; wxASSERT( bitmapBuffer == nullptr ); @@ -1520,7 +1517,6 @@ bool CAIRO_GAL::updatedGalDisplayOptions( const GAL_DISPLAY_OPTIONS& aOptions ) if( validCompositor && aOptions.cairo_antialiasing_mode != compositor->GetAntialiasingMode() ) { - compositor->SetAntialiasingMode( options.cairo_antialiasing_mode ); validCompositor = false; deinitSurface(); @@ -1546,7 +1542,7 @@ void CAIRO_GAL_BASE::DrawGrid() // For the drawing the start points, end points and increments have // to be calculated in world coordinates VECTOR2D worldStartPoint = screenWorldMatrix * VECTOR2D( 0.0, 0.0 ); - VECTOR2D worldEndPoint = screenWorldMatrix * VECTOR2D( screenSize ); + VECTOR2D worldEndPoint = screenWorldMatrix * VECTOR2D( screenSize ); // Compute the line marker or point radius of the grid // Note: generic grids can't handle sub-pixel lines without @@ -1574,7 +1570,7 @@ void CAIRO_GAL_BASE::DrawGrid() // If we cannot display the grid density, scale down by a tick size and // try again. Eventually, we get some representation of the grid - while( std::min( gridScreenSize.x, gridScreenSize.y ) <= gridThreshold ) + while( std::min( gridScreenSize.x, gridScreenSize.y ) <= gridThreshold ) { gridScreenSize = gridScreenSize * static_cast( gridTick ); } @@ -1583,9 +1579,9 @@ void CAIRO_GAL_BASE::DrawGrid() // visible screen area // Note: later any point coordinate will be offsetted by gridOrigin int gridStartX = KiROUND( ( worldStartPoint.x - gridOrigin.x ) / gridScreenSize.x ); - int gridEndX = KiROUND( ( worldEndPoint.x - gridOrigin.x ) / gridScreenSize.x ); + int gridEndX = KiROUND( ( worldEndPoint.x - gridOrigin.x ) / gridScreenSize.x ); int gridStartY = KiROUND( ( worldStartPoint.y - gridOrigin.y ) / gridScreenSize.y ); - int gridEndY = KiROUND( ( worldEndPoint.y - gridOrigin.y ) / gridScreenSize.y ); + int gridEndY = KiROUND( ( worldEndPoint.y - gridOrigin.y ) / gridScreenSize.y ); // Ensure start coordinate > end coordinate @@ -1593,8 +1589,10 @@ void CAIRO_GAL_BASE::DrawGrid() SWAP( gridStartY, >, gridEndY ); // Ensure the grid fills the screen - --gridStartX; ++gridEndX; - --gridStartY; ++gridEndY; + --gridStartX; + ++gridEndX; + --gridStartY; + ++gridEndY; // Draw the grid behind all other layers SetLayerDepth( depthRange.y * 0.75 ); @@ -1627,10 +1625,9 @@ void CAIRO_GAL_BASE::DrawGrid() SetLineWidth( ( i % gridTick ) ? marker : doubleMarker ); drawGridLine( VECTOR2D( x, gridStartY * gridScreenSize.y + gridOrigin.y ), VECTOR2D( x, gridEndY * gridScreenSize.y + gridOrigin.y ) ); - } } - else // Dots or Crosses grid + else // Dots or Crosses grid { lineWidthIsOdd = true; isStrokeEnabled = true; @@ -1640,7 +1637,7 @@ void CAIRO_GAL_BASE::DrawGrid() for( int i = gridStartX; i <= gridEndX; i++ ) { - bool tickX = ( i % gridTick == 0 ); + bool tickX = ( i % gridTick == 0 ); VECTOR2D pos{ i * gridScreenSize.x + gridOrigin.x, j * gridScreenSize.y + gridOrigin.y }; @@ -1653,10 +1650,9 @@ void CAIRO_GAL_BASE::DrawGrid() { double doubleGridLineWidth = gridLineWidth * 2.0f; drawGridPoint( pos, ( tickX ) ? doubleGridLineWidth : gridLineWidth, - ( tickY ) ? doubleGridLineWidth : gridLineWidth ); + ( tickY ) ? doubleGridLineWidth : gridLineWidth ); } } } } } - diff --git a/common/gal/cairo/cairo_print.cpp b/common/gal/cairo/cairo_print.cpp index 8b8b082576..3b9468e3ce 100644 --- a/common/gal/cairo/cairo_print.cpp +++ b/common/gal/cairo/cairo_print.cpp @@ -1,5 +1,7 @@ /* * Copyright (C) 2019 CERN + * Copyright (C) 2021 Kicad Developers, see AUTHORS.txt for contributors. + * * Author: Maciej Suminski * Author: Tomasz Wlostowski * @@ -25,10 +27,10 @@ #include #include -#ifdef NOMINMAX /* workaround for gdiplus.h */ +#ifdef NOMINMAX /* workaround for gdiplus.h */ #include -using std::min; using std::max; +using std::min; #endif #ifdef __WXMSW__ @@ -45,8 +47,10 @@ using std::max; using namespace KIGFX; -CAIRO_PRINT_CTX::CAIRO_PRINT_CTX( wxDC* aDC ) - : m_gcdc( nullptr ), m_ctx( nullptr ), m_surface( nullptr ) +CAIRO_PRINT_CTX::CAIRO_PRINT_CTX( wxDC* aDC ) : + m_gcdc( nullptr ), + m_ctx( nullptr ), + m_surface( nullptr ) { if( wxPrinterDC* printerDC = dynamic_cast( aDC ) ) m_gcdc = new wxGCDC( *printerDC ); @@ -69,15 +73,18 @@ CAIRO_PRINT_CTX::CAIRO_PRINT_CTX( wxDC* aDC ) #ifdef __WXGTK__ m_ctx = static_cast( gctx->GetNativeContext() ); m_surface = cairo_get_target( m_ctx ); - // On linux, cairo printers have 72 DPI by default. - // This is an unusable resolution for us. - // A better resolution could be 4800 DPI (at 600 DPI, we still have minor - // but visible artifacts, for instance with arcs, but not at 4800 DPI) - // so modify the default: - #define DEFAULT_DPI 72.0 - #define KICAD_PRINTER_DPI 4800.0 + +// On linux, cairo printers have 72 DPI by default. +// This is an unusable resolution for us. +// A better resolution could be 4800 DPI (at 600 DPI, we still have minor +// but visible artifacts, for instance with arcs, but not at 4800 DPI) +// so modify the default: +#define DEFAULT_DPI 72.0 +#define KICAD_PRINTER_DPI 4800.0 + // our device scale is DEFAULT_DPI / KICAD_PRINTER_DPI - cairo_surface_set_device_scale( m_surface, DEFAULT_DPI/KICAD_PRINTER_DPI, DEFAULT_DPI/KICAD_PRINTER_DPI ); + cairo_surface_set_device_scale( m_surface, DEFAULT_DPI / KICAD_PRINTER_DPI, + DEFAULT_DPI / KICAD_PRINTER_DPI ); m_dpi = KICAD_PRINTER_DPI; #endif /* __WXGTK__ */ @@ -90,7 +97,7 @@ CAIRO_PRINT_CTX::CAIRO_PRINT_CTX( wxDC* aDC ) #endif /* __WXMSW__ */ #ifdef __WXMAC__ - wxSize size = m_gcdc->GetSize(); + wxSize size = m_gcdc->GetSize(); CGContextRef cg = (CGContextRef) gctx->GetNativeContext(); m_surface = cairo_quartz_surface_create_for_cg_context( cg, size.x, size.y ); m_ctx = cairo_create( m_surface ); @@ -124,9 +131,9 @@ CAIRO_PRINT_CTX::~CAIRO_PRINT_CTX() } -CAIRO_PRINT_GAL::CAIRO_PRINT_GAL( GAL_DISPLAY_OPTIONS& aDisplayOptions, - std::unique_ptr aContext ) - : CAIRO_GAL_BASE( aDisplayOptions ) +CAIRO_PRINT_GAL::CAIRO_PRINT_GAL( GAL_DISPLAY_OPTIONS& aDisplayOptions, + std::unique_ptr aContext ) : + CAIRO_GAL_BASE( aDisplayOptions ) { m_printCtx = std::move( aContext ); context = currentContext = m_printCtx->GetContext(); @@ -144,7 +151,8 @@ CAIRO_PRINT_GAL::CAIRO_PRINT_GAL( GAL_DISPLAY_OPTIONS& aDisplayOptions, void CAIRO_PRINT_GAL::ComputeWorldScreenMatrix() { worldScale = screenDPI * worldUnitLength * zoomFactor; - const auto paperSizeIU = VECTOR2D( m_nativePaperSize.y, m_nativePaperSize.x ) /* inches */ / worldUnitLength; /* 1 inch in IU */ + const auto paperSizeIU = VECTOR2D( m_nativePaperSize.y, m_nativePaperSize.x ) /* inches */ + / worldUnitLength; /* 1 inch in IU */ const auto paperSizeIUTransposed = VECTOR2D( paperSizeIU.y, paperSizeIU.x ); MATRIX3x3D scale, translation, flip, rotate, lookat; @@ -192,7 +200,7 @@ void CAIRO_PRINT_GAL::SetSheetSize( const VECTOR2D& aSize ) { // Convert aSize (inches) to pixels SetScreenSize( VECTOR2I( std::ceil( aSize.x * screenDPI ) * 2, - std::ceil( aSize.y * screenDPI ) * 2 ) ); + std::ceil( aSize.y * screenDPI ) * 2 ) ); } diff --git a/common/gal/opengl/antialiasing.cpp b/common/gal/opengl/antialiasing.cpp index 1a84516499..ef2b64c72d 100644 --- a/common/gal/opengl/antialiasing.cpp +++ b/common/gal/opengl/antialiasing.cpp @@ -1,25 +1,25 @@ /* -* This program source code file is part of KICAD, a free EDA CAD application. -* -* Copyright (C) 2016 Kicad Developers, see change_log.txt for contributors. -* -* This program is free software; you can redistribute it and/or -* modify it under the terms of the GNU General Public License -* as published by the Free Software Foundation; either version 2 -* of the License, or (at your option) any later version. -* -* This program is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -* GNU General Public License for more details. -* -* You should have received a copy of the GNU General Public License -* along with this program; if not, you may find one here: -* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html -* or you may search the http://www.gnu.org website for the version 2 license, -* or you may write to the Free Software Foundation, Inc., -* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA -*/ + * This program source code file is part of KICAD, a free EDA CAD application. + * + * Copyright (C) 2016-2021 Kicad Developers, see AUTHORS.txt for contributors. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, you may find one here: + * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html + * or you may search the http://www.gnu.org website for the version 2 license, + * or you may write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA + */ #include #include @@ -39,8 +39,8 @@ using namespace KIGFX; // ANTIALIASING_NONE // ========================= -ANTIALIASING_NONE::ANTIALIASING_NONE( OPENGL_COMPOSITOR* aCompositor ) - : compositor( aCompositor ) +ANTIALIASING_NONE::ANTIALIASING_NONE( OPENGL_COMPOSITOR* aCompositor ) : + compositor( aCompositor ) { } @@ -88,49 +88,49 @@ unsigned int ANTIALIASING_NONE::CreateBuffer() } -namespace { - - void draw_fullscreen_primitive() - { - glMatrixMode( GL_MODELVIEW ); - glPushMatrix(); - glLoadIdentity(); - glMatrixMode( GL_PROJECTION ); - glPushMatrix(); - glLoadIdentity(); +namespace +{ +void draw_fullscreen_primitive() +{ + glMatrixMode( GL_MODELVIEW ); + glPushMatrix(); + glLoadIdentity(); + glMatrixMode( GL_PROJECTION ); + glPushMatrix(); + glLoadIdentity(); - glBegin( GL_TRIANGLES ); - glTexCoord2f( 0.0f, 1.0f ); - glVertex2f( -1.0f, 1.0f ); - glTexCoord2f( 0.0f, 0.0f ); - glVertex2f( -1.0f, -1.0f ); - glTexCoord2f( 1.0f, 1.0f ); - glVertex2f( 1.0f, 1.0f ); + glBegin( GL_TRIANGLES ); + glTexCoord2f( 0.0f, 1.0f ); + glVertex2f( -1.0f, 1.0f ); + glTexCoord2f( 0.0f, 0.0f ); + glVertex2f( -1.0f, -1.0f ); + glTexCoord2f( 1.0f, 1.0f ); + glVertex2f( 1.0f, 1.0f ); - glTexCoord2f( 1.0f, 1.0f ); - glVertex2f( 1.0f, 1.0f ); - glTexCoord2f( 0.0f, 0.0f ); - glVertex2f( -1.0f, -1.0f ); - glTexCoord2f( 1.0f, 0.0f ); - glVertex2f( 1.0f, -1.0f ); - glEnd(); - - glPopMatrix(); - glMatrixMode( GL_MODELVIEW ); - glPopMatrix(); - } + glTexCoord2f( 1.0f, 1.0f ); + glVertex2f( 1.0f, 1.0f ); + glTexCoord2f( 0.0f, 0.0f ); + glVertex2f( -1.0f, -1.0f ); + glTexCoord2f( 1.0f, 0.0f ); + glVertex2f( 1.0f, -1.0f ); + glEnd(); + glPopMatrix(); + glMatrixMode( GL_MODELVIEW ); + glPopMatrix(); } +} // namespace + // ========================= // ANTIALIASING_SUPERSAMPLING // ========================= ANTIALIASING_SUPERSAMPLING::ANTIALIASING_SUPERSAMPLING( OPENGL_COMPOSITOR* aCompositor, - SUPERSAMPLING_MODE aMode ) - : compositor( aCompositor ), mode( aMode ), ssaaMainBuffer( 0 ), - areBuffersCreated( false ), areShadersCreated( false ) + SUPERSAMPLING_MODE aMode ) : + compositor( aCompositor ), + mode( aMode ), ssaaMainBuffer( 0 ), areBuffersCreated( false ), areShadersCreated( false ) { } @@ -139,17 +139,23 @@ bool ANTIALIASING_SUPERSAMPLING::Init() { if( mode == SUPERSAMPLING_MODE::X4 && !areShadersCreated ) { - x4_shader = std::make_unique( ); - x4_shader->LoadShaderFromStrings( KIGFX::SHADER_TYPE_VERTEX, BUILTIN_SHADERS::ssaa_x4_vertex_shader ); - x4_shader->LoadShaderFromStrings( KIGFX::SHADER_TYPE_FRAGMENT, BUILTIN_SHADERS::ssaa_x4_fragment_shader ); + x4_shader = std::make_unique(); + x4_shader->LoadShaderFromStrings( KIGFX::SHADER_TYPE_VERTEX, + BUILTIN_SHADERS::ssaa_x4_vertex_shader ); + x4_shader->LoadShaderFromStrings( KIGFX::SHADER_TYPE_FRAGMENT, + BUILTIN_SHADERS::ssaa_x4_fragment_shader ); x4_shader->Link(); checkGlError( "linking supersampling x4 shader" ); - GLint source_parameter = x4_shader->AddParameter( "source" ); checkGlError( "getting pass 1 colorTex" ); + GLint source_parameter = x4_shader->AddParameter( "source" ); + checkGlError( "getting pass 1 colorTex" ); - x4_shader->Use(); checkGlError( "using pass 1 shader" ); - x4_shader->SetParameter( source_parameter, 0 ); checkGlError( "setting colorTex uniform" ); - x4_shader->Deactivate(); checkGlError( "deactivating pass 2 shader" ); + x4_shader->Use(); + checkGlError( "using pass 1 shader" ); + x4_shader->SetParameter( source_parameter, 0 ); + checkGlError( "setting colorTex uniform" ); + x4_shader->Deactivate(); + checkGlError( "deactivating pass 2 shader" ); areShadersCreated = true; } @@ -232,9 +238,11 @@ unsigned int ANTIALIASING_SUPERSAMPLING::CreateBuffer() // ANTIALIASING_SMAA // =============================== -ANTIALIASING_SMAA::ANTIALIASING_SMAA( OPENGL_COMPOSITOR* aCompositor, SMAA_QUALITY aQuality ) - : areBuffersInitialized( false ), shadersLoaded( false ), - quality( aQuality ), compositor( aCompositor ) +ANTIALIASING_SMAA::ANTIALIASING_SMAA( OPENGL_COMPOSITOR* aCompositor, SMAA_QUALITY aQuality ) : + areBuffersInitialized( false ), + shadersLoaded( false ), + quality( aQuality ), + compositor( aCompositor ) { smaaBaseBuffer = 0; smaaEdgesBuffer = 0; @@ -266,7 +274,8 @@ void ANTIALIASING_SMAA::loadShaders() glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE ); glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR ); glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR ); - glTexImage2D( GL_TEXTURE_2D, 0, GL_RG8, AREATEX_WIDTH, AREATEX_HEIGHT, 0, GL_RG, GL_UNSIGNED_BYTE, areaTexBytes ); + glTexImage2D( GL_TEXTURE_2D, 0, GL_RG8, AREATEX_WIDTH, AREATEX_HEIGHT, 0, GL_RG, + GL_UNSIGNED_BYTE, areaTexBytes ); checkGlError( "loading smaa area tex" ); glGenTextures( 1, &smaaSearchTex ); @@ -275,7 +284,8 @@ void ANTIALIASING_SMAA::loadShaders() glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE ); glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR ); glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR ); - glTexImage2D( GL_TEXTURE_2D, 0, GL_R8, SEARCHTEX_WIDTH, SEARCHTEX_HEIGHT, 0, GL_RED, GL_UNSIGNED_BYTE, searchTexBytes ); + glTexImage2D( GL_TEXTURE_2D, 0, GL_R8, SEARCHTEX_WIDTH, SEARCHTEX_HEIGHT, 0, GL_RED, + GL_UNSIGNED_BYTE, searchTexBytes ); checkGlError( "loading smaa search tex" ); std::string quality_string; @@ -307,70 +317,93 @@ uniform vec4 SMAA_RT_METRICS; uniform vec4 SMAA_RT_METRICS; )SHADER" ); - std::string smaa_source = - std::string( BUILTIN_SHADERS::smaa_base_shader_p1 ) - + std::string( BUILTIN_SHADERS::smaa_base_shader_p2 ) - + std::string( BUILTIN_SHADERS::smaa_base_shader_p3 ) - + std::string( BUILTIN_SHADERS::smaa_base_shader_p4 ); + std::string smaa_source = std::string( BUILTIN_SHADERS::smaa_base_shader_p1 ) + + std::string( BUILTIN_SHADERS::smaa_base_shader_p2 ) + + std::string( BUILTIN_SHADERS::smaa_base_shader_p3 ) + + std::string( BUILTIN_SHADERS::smaa_base_shader_p4 ); // // Set up pass 1 Shader // - pass_1_shader = std::make_unique( ); - pass_1_shader->LoadShaderFromStrings( KIGFX::SHADER_TYPE_VERTEX, vert_preamble, - quality_string, smaa_source, BUILTIN_SHADERS::smaa_pass_1_vertex_shader ); + pass_1_shader = std::make_unique(); + pass_1_shader->LoadShaderFromStrings( KIGFX::SHADER_TYPE_VERTEX, vert_preamble, quality_string, + smaa_source, BUILTIN_SHADERS::smaa_pass_1_vertex_shader ); pass_1_shader->LoadShaderFromStrings( KIGFX::SHADER_TYPE_FRAGMENT, frag_preamble, - quality_string, smaa_source, BUILTIN_SHADERS::smaa_pass_1_fragment_shader ); + quality_string, smaa_source, + BUILTIN_SHADERS::smaa_pass_1_fragment_shader ); pass_1_shader->Link(); checkGlError( "linking pass 1 shader" ); - GLint smaaColorTexParameter = pass_1_shader->AddParameter( "colorTex" ); checkGlError( "pass1: getting colorTex uniform" ); - pass_1_metrics = pass_1_shader->AddParameter( "SMAA_RT_METRICS" ); checkGlError( "pass1: getting metrics uniform" ); + GLint smaaColorTexParameter = pass_1_shader->AddParameter( "colorTex" ); + checkGlError( "pass1: getting colorTex uniform" ); + pass_1_metrics = pass_1_shader->AddParameter( "SMAA_RT_METRICS" ); + checkGlError( "pass1: getting metrics uniform" ); - pass_1_shader->Use(); checkGlError( "pass1: using shader" ); - pass_1_shader->SetParameter( smaaColorTexParameter, 0 ); checkGlError( "pass1: setting colorTex uniform" ); - pass_1_shader->Deactivate(); checkGlError( "pass1: deactivating shader" ); + pass_1_shader->Use(); + checkGlError( "pass1: using shader" ); + pass_1_shader->SetParameter( smaaColorTexParameter, 0 ); + checkGlError( "pass1: setting colorTex uniform" ); + pass_1_shader->Deactivate(); + checkGlError( "pass1: deactivating shader" ); // // set up pass 2 shader // - pass_2_shader = std::make_unique( ); - pass_2_shader->LoadShaderFromStrings( KIGFX::SHADER_TYPE_VERTEX, vert_preamble, - quality_string, smaa_source, BUILTIN_SHADERS::smaa_pass_2_vertex_shader ); + pass_2_shader = std::make_unique(); + pass_2_shader->LoadShaderFromStrings( KIGFX::SHADER_TYPE_VERTEX, vert_preamble, quality_string, + smaa_source, BUILTIN_SHADERS::smaa_pass_2_vertex_shader ); pass_2_shader->LoadShaderFromStrings( KIGFX::SHADER_TYPE_FRAGMENT, frag_preamble, - quality_string, smaa_source, BUILTIN_SHADERS::smaa_pass_2_fragment_shader ); + quality_string, smaa_source, + BUILTIN_SHADERS::smaa_pass_2_fragment_shader ); pass_2_shader->Link(); checkGlError( "linking pass 2 shader" ); - GLint smaaEdgesTexParameter = pass_2_shader->AddParameter( "edgesTex" ); checkGlError( "pass2: getting colorTex uniform" ); - GLint smaaAreaTexParameter = pass_2_shader->AddParameter( "areaTex" ); checkGlError( "pass2: getting areaTex uniform" ); - GLint smaaSearchTexParameter = pass_2_shader->AddParameter( "searchTex" ); checkGlError( "pass2: getting searchTex uniform" ); - pass_2_metrics = pass_2_shader->AddParameter( "SMAA_RT_METRICS" ); checkGlError( "pass2: getting metrics uniform" ); + GLint smaaEdgesTexParameter = pass_2_shader->AddParameter( "edgesTex" ); + checkGlError( "pass2: getting colorTex uniform" ); + GLint smaaAreaTexParameter = pass_2_shader->AddParameter( "areaTex" ); + checkGlError( "pass2: getting areaTex uniform" ); + GLint smaaSearchTexParameter = pass_2_shader->AddParameter( "searchTex" ); + checkGlError( "pass2: getting searchTex uniform" ); + pass_2_metrics = pass_2_shader->AddParameter( "SMAA_RT_METRICS" ); + checkGlError( "pass2: getting metrics uniform" ); - pass_2_shader->Use(); checkGlError( "pass2: using shader" ); - pass_2_shader->SetParameter( smaaEdgesTexParameter, 0 ); checkGlError( "pass2: setting colorTex uniform" ); - pass_2_shader->SetParameter( smaaAreaTexParameter, 1 ); checkGlError( "pass2: setting areaTex uniform" ); - pass_2_shader->SetParameter( smaaSearchTexParameter, 3 ); checkGlError( "pass2: setting searchTex uniform" ); - pass_2_shader->Deactivate(); checkGlError( "pass2: deactivating shader" ); + pass_2_shader->Use(); + checkGlError( "pass2: using shader" ); + pass_2_shader->SetParameter( smaaEdgesTexParameter, 0 ); + checkGlError( "pass2: setting colorTex uniform" ); + pass_2_shader->SetParameter( smaaAreaTexParameter, 1 ); + checkGlError( "pass2: setting areaTex uniform" ); + pass_2_shader->SetParameter( smaaSearchTexParameter, 3 ); + checkGlError( "pass2: setting searchTex uniform" ); + pass_2_shader->Deactivate(); + checkGlError( "pass2: deactivating shader" ); // // set up pass 3 shader // - pass_3_shader = std::make_unique( ); - pass_3_shader->LoadShaderFromStrings( KIGFX::SHADER_TYPE_VERTEX, vert_preamble, - quality_string, smaa_source, BUILTIN_SHADERS::smaa_pass_3_vertex_shader ); + pass_3_shader = std::make_unique(); + pass_3_shader->LoadShaderFromStrings( KIGFX::SHADER_TYPE_VERTEX, vert_preamble, quality_string, + smaa_source, BUILTIN_SHADERS::smaa_pass_3_vertex_shader ); pass_3_shader->LoadShaderFromStrings( KIGFX::SHADER_TYPE_FRAGMENT, frag_preamble, - quality_string, smaa_source, BUILTIN_SHADERS::smaa_pass_3_fragment_shader ); + quality_string, smaa_source, + BUILTIN_SHADERS::smaa_pass_3_fragment_shader ); pass_3_shader->Link(); - GLint smaaP3ColorTexParameter = pass_3_shader->AddParameter( "colorTex" ); checkGlError( "pass3: getting colorTex uniform" ); - GLint smaaBlendTexParameter = pass_3_shader->AddParameter( "blendTex" ); checkGlError( "pass3: getting blendTex uniform" ); - pass_3_metrics = pass_3_shader->AddParameter( "SMAA_RT_METRICS" ); checkGlError( "pass3: getting metrics uniform" ); + GLint smaaP3ColorTexParameter = pass_3_shader->AddParameter( "colorTex" ); + checkGlError( "pass3: getting colorTex uniform" ); + GLint smaaBlendTexParameter = pass_3_shader->AddParameter( "blendTex" ); + checkGlError( "pass3: getting blendTex uniform" ); + pass_3_metrics = pass_3_shader->AddParameter( "SMAA_RT_METRICS" ); + checkGlError( "pass3: getting metrics uniform" ); - pass_3_shader->Use(); checkGlError( "pass3: using shader" ); - pass_3_shader->SetParameter( smaaP3ColorTexParameter, 0 ); checkGlError( "pass3: setting colorTex uniform" ); - pass_3_shader->SetParameter( smaaBlendTexParameter, 1 ); checkGlError( "pass3: setting blendTex uniform" ); - pass_3_shader->Deactivate(); checkGlError( "pass3: deactivating shader" ); + pass_3_shader->Use(); + checkGlError( "pass3: using shader" ); + pass_3_shader->SetParameter( smaaP3ColorTexParameter, 0 ); + checkGlError( "pass3: setting colorTex uniform" ); + pass_3_shader->SetParameter( smaaBlendTexParameter, 1 ); + checkGlError( "pass3: setting blendTex uniform" ); + pass_3_shader->Deactivate(); + checkGlError( "pass3: deactivating shader" ); shadersLoaded = true; } @@ -380,20 +413,29 @@ void ANTIALIASING_SMAA::updateUniforms() { auto dims = compositor->GetScreenSize(); - pass_1_shader->Use(); checkGlError( "pass1: using shader" ); - pass_1_shader->SetParameter( pass_1_metrics, - 1.f / float( dims.x ), 1.f / float( dims.y ), float( dims.x ), float( dims.y ) ); checkGlError( "pass1: setting metrics uniform" ); - pass_1_shader->Deactivate(); checkGlError( "pass1: deactivating shader" ); + pass_1_shader->Use(); + checkGlError( "pass1: using shader" ); + pass_1_shader->SetParameter( pass_1_metrics, 1.f / float( dims.x ), 1.f / float( dims.y ), + float( dims.x ), float( dims.y ) ); + checkGlError( "pass1: setting metrics uniform" ); + pass_1_shader->Deactivate(); + checkGlError( "pass1: deactivating shader" ); - pass_2_shader->Use(); checkGlError( "pass2: using shader" ); - pass_2_shader->SetParameter( pass_2_metrics, - 1.f / float( dims.x ), 1.f / float( dims.y ), float( dims.x ), float( dims.y ) ); checkGlError( "pass2: setting metrics uniform" ); - pass_2_shader->Deactivate(); checkGlError( "pass2: deactivating shader" ); + pass_2_shader->Use(); + checkGlError( "pass2: using shader" ); + pass_2_shader->SetParameter( pass_2_metrics, 1.f / float( dims.x ), 1.f / float( dims.y ), + float( dims.x ), float( dims.y ) ); + checkGlError( "pass2: setting metrics uniform" ); + pass_2_shader->Deactivate(); + checkGlError( "pass2: deactivating shader" ); - pass_3_shader->Use(); checkGlError( "pass3: using shader" ); - pass_3_shader->SetParameter( pass_3_metrics, - 1.f / float( dims.x ), 1.f / float( dims.y ), float( dims.x ), float( dims.y ) ); checkGlError( "pass3: setting metrics uniform" ); - pass_3_shader->Deactivate(); checkGlError( "pass3: deactivating shader" ); + pass_3_shader->Use(); + checkGlError( "pass3: using shader" ); + pass_3_shader->SetParameter( pass_3_metrics, 1.f / float( dims.x ), 1.f / float( dims.y ), + float( dims.x ), float( dims.y ) ); + checkGlError( "pass3: setting metrics uniform" ); + pass_3_shader->Deactivate(); + checkGlError( "pass3: deactivating shader" ); } @@ -451,30 +493,31 @@ void ANTIALIASING_SMAA::Begin() } -namespace { - void draw_fullscreen_triangle() - { - glMatrixMode( GL_MODELVIEW ); - glPushMatrix(); - glLoadIdentity(); - glMatrixMode( GL_PROJECTION ); - glPushMatrix(); - glLoadIdentity(); +namespace +{ +void draw_fullscreen_triangle() +{ + glMatrixMode( GL_MODELVIEW ); + glPushMatrix(); + glLoadIdentity(); + glMatrixMode( GL_PROJECTION ); + glPushMatrix(); + glLoadIdentity(); - glBegin( GL_TRIANGLES ); - glTexCoord2f( 0.0f, 1.0f ); - glVertex2f( -1.0f, 1.0f ); - glTexCoord2f( 0.0f, -1.0f ); - glVertex2f( -1.0f, -3.0f ); - glTexCoord2f( 2.0f, 1.0f ); - glVertex2f( 3.0f, 1.0f ); - glEnd(); + glBegin( GL_TRIANGLES ); + glTexCoord2f( 0.0f, 1.0f ); + glVertex2f( -1.0f, 1.0f ); + glTexCoord2f( 0.0f, -1.0f ); + glVertex2f( -1.0f, -3.0f ); + glTexCoord2f( 2.0f, 1.0f ); + glVertex2f( 3.0f, 1.0f ); + glEnd(); - glPopMatrix(); - glMatrixMode( GL_MODELVIEW ); - glPopMatrix(); - } + glPopMatrix(); + glMatrixMode( GL_MODELVIEW ); + glPopMatrix(); } +} // namespace void ANTIALIASING_SMAA::Present() @@ -492,8 +535,10 @@ void ANTIALIASING_SMAA::Present() compositor->ClearBuffer( COLOR4D::BLACK ); glActiveTexture( GL_TEXTURE0 ); - glBindTexture( GL_TEXTURE_2D, sourceTexture ); checkGlError( "binding colorTex" ); - pass_1_shader->Use(); checkGlError( "using smaa pass 1 shader" ); + glBindTexture( GL_TEXTURE_2D, sourceTexture ); + checkGlError( "binding colorTex" ); + pass_1_shader->Use(); + checkGlError( "using smaa pass 1 shader" ); draw_fullscreen_triangle(); pass_1_shader->Deactivate(); diff --git a/common/gal/opengl/cached_container.cpp b/common/gal/opengl/cached_container.cpp index 98a583ce78..8a29e1af2f 100644 --- a/common/gal/opengl/cached_container.cpp +++ b/common/gal/opengl/cached_container.cpp @@ -2,7 +2,7 @@ * This program source code file is part of KiCad, a free EDA CAD application. * * Copyright 2013-2017 CERN - * Copyright (C) 2020 KiCad Developers, see AUTHORS.txt for contributors. + * Copyright (C) 2020-2021 KiCad Developers, see AUTHORS.txt for contributors. * * @author Maciej Suminski * @@ -48,7 +48,11 @@ using namespace KIGFX; CACHED_CONTAINER::CACHED_CONTAINER( unsigned int aSize ) : - VERTEX_CONTAINER( aSize ), m_item( NULL ), m_chunkSize( 0 ), m_chunkOffset( 0 ), m_maxIndex( 0 ) + VERTEX_CONTAINER( aSize ), + m_item( NULL ), + m_chunkSize( 0 ), + m_chunkOffset( 0 ), + m_maxIndex( 0 ) { // In the beginning there is only free space m_freeChunks.insert( std::make_pair( aSize, 0 ) ); @@ -60,7 +64,7 @@ void CACHED_CONTAINER::SetItem( VERTEX_ITEM* aItem ) assert( aItem != NULL ); unsigned int itemSize = aItem->GetSize(); - m_item = aItem; + m_item = aItem; m_chunkSize = itemSize; // Get the previously set offset if the item was stored previously @@ -149,7 +153,7 @@ void CACHED_CONTAINER::Delete( VERTEX_ITEM* aItem ) int size = aItem->GetSize(); if( size == 0 ) - return; // Item is not stored here + return; // Item is not stored here int offset = aItem->GetOffset(); @@ -236,7 +240,7 @@ bool CACHED_CONTAINER::reallocate( unsigned int aSize ) } // Parameters of the allocated chunk - unsigned int newChunkSize = getChunkSize( *newChunk ); + unsigned int newChunkSize = getChunkSize( *newChunk ); unsigned int newChunkOffset = getChunkOffset( *newChunk ); assert( newChunkSize >= aSize ); @@ -269,12 +273,12 @@ void CACHED_CONTAINER::defragment( VERTEX* aTarget ) { // Defragmentation ITEMS::iterator it, it_end; - int newOffset = 0; + int newOffset = 0; for( VERTEX_ITEM* item : m_items ) { - int itemOffset = item->GetOffset(); - int itemSize = item->GetSize(); + int itemOffset = item->GetOffset(); + int itemSize = item->GetSize(); // Move an item to the new container memcpy( &aTarget[newOffset], &m_vertices[itemOffset], itemSize * VERTEX_SIZE ); @@ -322,8 +326,8 @@ void CACHED_CONTAINER::mergeFreeChunks() freeChunks.sort(); std::list::const_iterator itf, itf_end; - unsigned int offset = freeChunks.front().first; - unsigned int size = freeChunks.front().second; + unsigned int offset = freeChunks.front().first; + unsigned int size = freeChunks.front().second; freeChunks.pop_front(); for( itf = freeChunks.begin(), itf_end = freeChunks.end(); itf != itf_end; ++itf ) @@ -340,8 +344,7 @@ void CACHED_CONTAINER::mergeFreeChunks() m_freeChunks.insert( std::make_pair( size, offset ) ); // and let's check the next chunk offset = itf->first; - size = itf->second; - + size = itf->second; } } @@ -378,7 +381,7 @@ void CACHED_CONTAINER::test() { #ifdef __WXDEBUG__ // Free space check - unsigned int freeSpace = 0; + unsigned int freeSpace = 0; FREE_CHUNK_MAP::iterator itf; for( itf = m_freeChunks.begin(); itf != m_freeChunks.end(); ++itf ) @@ -387,8 +390,9 @@ void CACHED_CONTAINER::test() assert( freeSpace == m_freeSpace ); // Used space check - unsigned int used_space = 0; + unsigned int used_space = 0; ITEMS::iterator itr; + for( itr = m_items.begin(); itr != m_items.end(); ++itr ) used_space += ( *itr )->GetSize(); diff --git a/common/gal/opengl/cached_container_gpu.cpp b/common/gal/opengl/cached_container_gpu.cpp index 7a2a9b8af4..934f6feea8 100644 --- a/common/gal/opengl/cached_container_gpu.cpp +++ b/common/gal/opengl/cached_container_gpu.cpp @@ -2,7 +2,7 @@ * This program source code file is part of KiCad, a free EDA CAD application. * * Copyright 2013-2017 CERN - * Copyright (C) 2020 KiCad Developers, see AUTHORS.txt for contributors. + * Copyright (C) 2020-2021 KiCad Developers, see AUTHORS.txt for contributors. * * @author Maciej Suminski * @@ -30,25 +30,26 @@ #include #include +#include + #include #ifdef __WXDEBUG__ -#include #include #endif /* __WXDEBUG__ */ using namespace KIGFX; CACHED_CONTAINER_GPU::CACHED_CONTAINER_GPU( unsigned int aSize ) : - CACHED_CONTAINER( aSize ), m_isMapped( false ), m_glBufferHandle( -1 ) + CACHED_CONTAINER( aSize ), m_isMapped( false ), m_glBufferHandle( -1 ) { m_useCopyBuffer = GLEW_ARB_copy_buffer; - wxString vendor( glGetString(GL_VENDOR) ); + wxString vendor( glGetString( GL_VENDOR ) ); // workaround for intel GPU drivers: disable glCopyBuffer, causes crashes/freezes on // certain driver versions - if( vendor.Contains ( "Intel " ) || vendor.Contains ( "etnaviv" ) ) + if( vendor.Contains( "Intel " ) || vendor.Contains( "etnaviv" ) ) { m_useCopyBuffer = false; } @@ -92,6 +93,8 @@ void CACHED_CONTAINER_GPU::Unmap() { wxCHECK( IsMapped(), /*void*/ ); + // This gets called from ~CACHED_CONTAINER_GPU. To avoid throwing an exception from + // the dtor, catch it here instead. glUnmapBuffer( GL_ARRAY_BUFFER ); checkGlError( "unmapping vertices buffer" ); glBindBuffer( GL_ARRAY_BUFFER, 0 ); @@ -110,7 +113,8 @@ bool CACHED_CONTAINER_GPU::defragmentResize( unsigned int aNewSize ) wxCHECK( IsMapped(), false ); wxLogTrace( "GAL_CACHED_CONTAINER_GPU", - wxT( "Resizing & defragmenting container from %d to %d" ), m_currentSize, aNewSize ); + wxT( "Resizing & defragmenting container from %d to %d" ), m_currentSize, + aNewSize ); // No shrinking if we cannot fit all the data if( usedSpace() > aNewSize ) @@ -140,18 +144,18 @@ bool CACHED_CONTAINER_GPU::defragmentResize( unsigned int aNewSize ) checkGlError( "creating buffer during defragmentation" ); ITEMS::iterator it, it_end; - int newOffset = 0; + int newOffset = 0; // Defragmentation for( it = m_items.begin(), it_end = m_items.end(); it != it_end; ++it ) { VERTEX_ITEM* item = *it; - int itemOffset = item->GetOffset(); - int itemSize = item->GetSize(); + int itemOffset = item->GetOffset(); + int itemSize = item->GetSize(); // Move an item to the new container - glCopyBufferSubData( GL_ARRAY_BUFFER, GL_ELEMENT_ARRAY_BUFFER, - itemOffset * VERTEX_SIZE, newOffset * VERTEX_SIZE, itemSize * VERTEX_SIZE ); + glCopyBufferSubData( GL_ARRAY_BUFFER, GL_ELEMENT_ARRAY_BUFFER, itemOffset * VERTEX_SIZE, + newOffset * VERTEX_SIZE, itemSize * VERTEX_SIZE ); // Update new offset item->setOffset( newOffset ); @@ -164,8 +168,8 @@ bool CACHED_CONTAINER_GPU::defragmentResize( unsigned int aNewSize ) if( m_item->GetSize() > 0 ) { glCopyBufferSubData( GL_ARRAY_BUFFER, GL_ELEMENT_ARRAY_BUFFER, - m_item->GetOffset() * VERTEX_SIZE, newOffset * VERTEX_SIZE, - m_item->GetSize() * VERTEX_SIZE ); + m_item->GetOffset() * VERTEX_SIZE, newOffset * VERTEX_SIZE, + m_item->GetSize() * VERTEX_SIZE ); m_item->setOffset( newOffset ); m_chunkOffset = newOffset; @@ -188,8 +192,7 @@ bool CACHED_CONTAINER_GPU::defragmentResize( unsigned int aNewSize ) #ifdef __WXDEBUG__ totalTime.Stop(); - wxLogTrace( "GAL_CACHED_CONTAINER_GPU", - "Defragmented container storing %d vertices / %.1f ms", + wxLogTrace( "GAL_CACHED_CONTAINER_GPU", "Defragmented container storing %d vertices / %.1f ms", m_currentSize - m_freeSpace, totalTime.msecs() ); #endif /* __WXDEBUG__ */ @@ -209,8 +212,8 @@ bool CACHED_CONTAINER_GPU::defragmentResizeMemcpy( unsigned int aNewSize ) wxCHECK( IsMapped(), false ); wxLogTrace( "GAL_CACHED_CONTAINER_GPU", - wxT( "Resizing & defragmenting container (memcpy) from %d to %d" ), - m_currentSize, aNewSize ); + wxT( "Resizing & defragmenting container (memcpy) from %d to %d" ), m_currentSize, + aNewSize ); // No shrinking if we cannot fit all the data if( usedSpace() > aNewSize ) @@ -220,7 +223,7 @@ bool CACHED_CONTAINER_GPU::defragmentResizeMemcpy( unsigned int aNewSize ) PROF_COUNTER totalTime; #endif /* __WXDEBUG__ */ - GLuint newBuffer; + GLuint newBuffer; VERTEX* newBufferMem; // Create the destination buffer @@ -254,8 +257,7 @@ bool CACHED_CONTAINER_GPU::defragmentResizeMemcpy( unsigned int aNewSize ) #ifdef __WXDEBUG__ totalTime.Stop(); - wxLogTrace( "GAL_CACHED_CONTAINER_GPU", - "Defragmented container storing %d vertices / %.1f ms", + wxLogTrace( "GAL_CACHED_CONTAINER_GPU", "Defragmented container storing %d vertices / %.1f ms", m_currentSize - m_freeSpace, totalTime.msecs() ); #endif /* __WXDEBUG__ */ diff --git a/common/gal/opengl/cached_container_ram.cpp b/common/gal/opengl/cached_container_ram.cpp index 7d77d79f80..0f41e078e3 100644 --- a/common/gal/opengl/cached_container_ram.cpp +++ b/common/gal/opengl/cached_container_ram.cpp @@ -2,6 +2,8 @@ * This program source code file is part of KiCad, a free EDA CAD application. * * Copyright 2013-2017 CERN + * Copyright (C) 2021 KiCad Developers, see AUTHORS.txt for contributors. + * * @author Maciej Suminski * * This program is free software; you can redistribute it and/or @@ -40,7 +42,8 @@ using namespace KIGFX; CACHED_CONTAINER_RAM::CACHED_CONTAINER_RAM( unsigned int aSize ) : - CACHED_CONTAINER( aSize ), m_verticesBuffer( 0 ) + CACHED_CONTAINER( aSize ), + m_verticesBuffer( 0 ) { glGenBuffers( 1, &m_verticesBuffer ); checkGlError( "generating vertices buffer" ); @@ -76,8 +79,8 @@ void CACHED_CONTAINER_RAM::Unmap() bool CACHED_CONTAINER_RAM::defragmentResize( unsigned int aNewSize ) { wxLogTrace( "GAL_CACHED_CONTAINER", - wxT( "Resizing & defragmenting container (memcpy) from %d to %d" ), - m_currentSize, aNewSize ); + wxT( "Resizing & defragmenting container (memcpy) from %d to %d" ), m_currentSize, + aNewSize ); // No shrinking if we cannot fit all the data if( usedSpace() > aNewSize ) @@ -101,8 +104,7 @@ bool CACHED_CONTAINER_RAM::defragmentResize( unsigned int aNewSize ) #ifdef __WXDEBUG__ totalTime.Stop(); - wxLogTrace( "GAL_CACHED_CONTAINER", - "Defragmented container storing %d vertices / %.1f ms", + wxLogTrace( "GAL_CACHED_CONTAINER", "Defragmented container storing %d vertices / %.1f ms", m_currentSize - m_freeSpace, totalTime.msecs() ); #endif /* __WXDEBUG__ */ diff --git a/common/gal/opengl/gpu_manager.cpp b/common/gal/opengl/gpu_manager.cpp index 48bd0f1fea..3ef7ac8483 100644 --- a/common/gal/opengl/gpu_manager.cpp +++ b/common/gal/opengl/gpu_manager.cpp @@ -2,6 +2,8 @@ * This program source code file is part of KiCad, a free EDA CAD application. * * Copyright 2013-2017 CERN + * Copyright (C) 2021 KiCad Developers, see AUTHORS.txt for contributors. + * * @author Maciej Suminski * * This program is free software; you can redistribute it and/or @@ -49,7 +51,11 @@ GPU_MANAGER* GPU_MANAGER::MakeManager( VERTEX_CONTAINER* aContainer ) GPU_MANAGER::GPU_MANAGER( VERTEX_CONTAINER* aContainer ) : - m_isDrawing( false ), m_container( aContainer ), m_shader( NULL ), m_shaderAttrib( 0 ), m_enableDepthTest( true ) + m_isDrawing( false ), + m_container( aContainer ), + m_shader( NULL ), + m_shaderAttrib( 0 ), + m_enableDepthTest( true ) { } @@ -73,8 +79,12 @@ void GPU_MANAGER::SetShader( SHADER& aShader ) // Cached manager GPU_CACHED_MANAGER::GPU_CACHED_MANAGER( VERTEX_CONTAINER* aContainer ) : - GPU_MANAGER( aContainer ), m_buffersInitialized( false ), m_indicesPtr( NULL ), - m_indicesBuffer( 0 ), m_indicesSize( 0 ), m_indicesCapacity( 0 ) + GPU_MANAGER( aContainer ), + m_buffersInitialized( false ), + m_indicesPtr( NULL ), + m_indicesBuffer( 0 ), + m_indicesSize( 0 ), + m_indicesCapacity( 0 ) { // Allocate the biggest possible buffer for indices resizeIndices( aContainer->GetSize() ); @@ -122,7 +132,8 @@ void GPU_CACHED_MANAGER::DrawIndices( unsigned int aOffset, unsigned int aSize ) wxASSERT( m_isDrawing ); // Copy indices of items that should be drawn to GPU memory - for( unsigned int i = aOffset; i < aOffset + aSize; *m_indicesPtr++ = i++ ); + for( unsigned int i = aOffset; i < aOffset + aSize; *m_indicesPtr++ = i++ ) + ; m_indicesSize += aSize; } @@ -132,7 +143,8 @@ void GPU_CACHED_MANAGER::DrawAll() { wxASSERT( m_isDrawing ); - for( unsigned int i = 0; i < m_indicesSize; *m_indicesPtr++ = i++ ); + for( unsigned int i = 0; i < m_indicesSize; *m_indicesPtr++ = i++ ) + ; m_indicesSize = m_container->GetSize(); } @@ -171,17 +183,17 @@ void GPU_CACHED_MANAGER::EndDrawing() glVertexPointer( COORD_STRIDE, GL_FLOAT, VERTEX_SIZE, (GLvoid*) COORD_OFFSET ); glColorPointer( COLOR_STRIDE, GL_UNSIGNED_BYTE, VERTEX_SIZE, (GLvoid*) COLOR_OFFSET ); - if( m_shader != NULL ) // Use shader if applicable + if( m_shader != NULL ) // Use shader if applicable { m_shader->Use(); glEnableVertexAttribArray( m_shaderAttrib ); - glVertexAttribPointer( m_shaderAttrib, SHADER_STRIDE, GL_FLOAT, GL_FALSE, - VERTEX_SIZE, (GLvoid*) SHADER_OFFSET ); + glVertexAttribPointer( m_shaderAttrib, SHADER_STRIDE, GL_FLOAT, GL_FALSE, VERTEX_SIZE, + (GLvoid*) SHADER_OFFSET ); } glBindBuffer( GL_ELEMENT_ARRAY_BUFFER, m_indicesBuffer ); - glBufferData( GL_ELEMENT_ARRAY_BUFFER, m_indicesSize * sizeof(int), - (GLvoid*) m_indices.get(), GL_DYNAMIC_DRAW ); + glBufferData( GL_ELEMENT_ARRAY_BUFFER, m_indicesSize * sizeof( int ), (GLvoid*) m_indices.get(), + GL_DYNAMIC_DRAW ); glDrawElements( GL_TRIANGLES, m_indicesSize, GL_UNSIGNED_INT, 0 ); @@ -207,8 +219,8 @@ void GPU_CACHED_MANAGER::EndDrawing() #ifdef __WXDEBUG__ totalRealTime.Stop(); - wxLogTrace( "GAL_PROFILE", - wxT( "GPU_CACHED_MANAGER::EndDrawing(): %.1f ms" ), totalRealTime.msecs() ); + wxLogTrace( "GAL_PROFILE", wxT( "GPU_CACHED_MANAGER::EndDrawing(): %.1f ms" ), + totalRealTime.msecs() ); #endif /* __WXDEBUG__ */ } @@ -225,7 +237,7 @@ void GPU_CACHED_MANAGER::resizeIndices( unsigned int aNewSize ) // Noncached manager GPU_NONCACHED_MANAGER::GPU_NONCACHED_MANAGER( VERTEX_CONTAINER* aContainer ) : - GPU_MANAGER( aContainer ) + GPU_MANAGER( aContainer ) { } @@ -258,9 +270,9 @@ void GPU_NONCACHED_MANAGER::EndDrawing() if( m_container->GetSize() == 0 ) return; - VERTEX* vertices = m_container->GetAllVertices(); - GLfloat* coordinates = (GLfloat*) ( vertices ); - GLubyte* colors = (GLubyte*) ( vertices ) + COLOR_OFFSET; + VERTEX* vertices = m_container->GetAllVertices(); + GLfloat* coordinates = (GLfloat*) ( vertices ); + GLubyte* colors = (GLubyte*) ( vertices ) + COLOR_OFFSET; if( m_enableDepthTest ) glEnable( GL_DEPTH_TEST ); @@ -274,14 +286,14 @@ void GPU_NONCACHED_MANAGER::EndDrawing() glVertexPointer( COORD_STRIDE, GL_FLOAT, VERTEX_SIZE, coordinates ); glColorPointer( COLOR_STRIDE, GL_UNSIGNED_BYTE, VERTEX_SIZE, colors ); - if( m_shader != NULL ) // Use shader if applicable + if( m_shader != NULL ) // Use shader if applicable { - GLfloat* shaders = (GLfloat*) ( vertices ) + SHADER_OFFSET / sizeof(GLfloat); + GLfloat* shaders = (GLfloat*) ( vertices ) + SHADER_OFFSET / sizeof( GLfloat ); m_shader->Use(); glEnableVertexAttribArray( m_shaderAttrib ); - glVertexAttribPointer( m_shaderAttrib, SHADER_STRIDE, GL_FLOAT, GL_FALSE, - VERTEX_SIZE, shaders ); + glVertexAttribPointer( m_shaderAttrib, SHADER_STRIDE, GL_FLOAT, GL_FALSE, VERTEX_SIZE, + shaders ); } glDrawArrays( GL_TRIANGLES, 0, m_container->GetSize() ); @@ -304,8 +316,8 @@ void GPU_NONCACHED_MANAGER::EndDrawing() #ifdef __WXDEBUG__ totalRealTime.Stop(); - wxLogTrace( "GAL_PROFILE", - wxT( "GPU_NONCACHED_MANAGER::EndDrawing(): %.1f ms" ), totalRealTime.msecs() ); + wxLogTrace( "GAL_PROFILE", wxT( "GPU_NONCACHED_MANAGER::EndDrawing(): %.1f ms" ), + totalRealTime.msecs() ); #endif /* __WXDEBUG__ */ } diff --git a/common/gal/opengl/noncached_container.cpp b/common/gal/opengl/noncached_container.cpp index 6703da3d23..b159265f8d 100644 --- a/common/gal/opengl/noncached_container.cpp +++ b/common/gal/opengl/noncached_container.cpp @@ -2,6 +2,8 @@ * This program source code file is part of KiCad, a free EDA CAD application. * * Copyright (C) 2013 CERN + * Copyright (C) 2021 KiCad Developers, see AUTHORS.txt for contributors. + * * @author Maciej Suminski * * This program is free software; you can redistribute it and/or @@ -35,7 +37,8 @@ using namespace KIGFX; NONCACHED_CONTAINER::NONCACHED_CONTAINER( unsigned int aSize ) : - VERTEX_CONTAINER( aSize ), m_freePtr( 0 ) + VERTEX_CONTAINER( aSize ), + m_freePtr( 0 ) { m_vertices = static_cast( malloc( aSize * sizeof( VERTEX ) ) ); memset( m_vertices, 0x00, aSize * sizeof( VERTEX ) ); @@ -60,14 +63,13 @@ VERTEX* NONCACHED_CONTAINER::Allocate( unsigned int aSize ) if( m_freeSpace < aSize ) { // Double the space - VERTEX* newVertices = static_cast( realloc( m_vertices, - m_currentSize * 2 * - sizeof(VERTEX) ) ); + VERTEX* newVertices = + static_cast( realloc( m_vertices, m_currentSize * 2 * sizeof( VERTEX ) ) ); if( newVertices != NULL ) { - m_vertices = newVertices; - m_freeSpace += m_currentSize; + m_vertices = newVertices; + m_freeSpace += m_currentSize; m_currentSize *= 2; } else @@ -79,7 +81,7 @@ VERTEX* NONCACHED_CONTAINER::Allocate( unsigned int aSize ) VERTEX* freeVertex = &m_vertices[m_freePtr]; // Move to the next free chunk - m_freePtr += aSize; + m_freePtr += aSize; m_freeSpace -= aSize; return freeVertex; @@ -88,6 +90,6 @@ VERTEX* NONCACHED_CONTAINER::Allocate( unsigned int aSize ) void NONCACHED_CONTAINER::Clear() { - m_freePtr = 0; + m_freePtr = 0; m_freeSpace = m_currentSize; } diff --git a/common/gal/opengl/opengl_compositor.cpp b/common/gal/opengl/opengl_compositor.cpp index c3cc34151a..e87c219276 100644 --- a/common/gal/opengl/opengl_compositor.cpp +++ b/common/gal/opengl/opengl_compositor.cpp @@ -2,6 +2,8 @@ * This program source code file is part of KiCad, a free EDA CAD application. * * Copyright (C) 2013-2017 CERN + * Copyright (C) 2021 KiCad Developers, see AUTHORS.txt for contributors. + * * @author Maciej Suminski * * This program is free software; you can redistribute it and/or @@ -40,9 +42,12 @@ using namespace KIGFX; OPENGL_COMPOSITOR::OPENGL_COMPOSITOR() : - m_initialized( false ), m_curBuffer( 0 ), - m_mainFbo( 0 ), m_depthBuffer( 0 ), m_curFbo( DIRECT_RENDERING ), - m_currentAntialiasingMode( OPENGL_ANTIALIASING_MODE::NONE ) + m_initialized( false ), + m_curBuffer( 0 ), + m_mainFbo( 0 ), + m_depthBuffer( 0 ), + m_curFbo( DIRECT_RENDERING ), + m_currentAntialiasingMode( OPENGL_ANTIALIASING_MODE::NONE ) { m_antialiasing = std::make_unique( this ); } @@ -77,21 +82,23 @@ void OPENGL_COMPOSITOR::Initialize() switch( m_currentAntialiasingMode ) { - case OPENGL_ANTIALIASING_MODE::NONE: - m_antialiasing = std::make_unique( this ); - break; - case OPENGL_ANTIALIASING_MODE::SUBSAMPLE_HIGH: - m_antialiasing = std::make_unique( this, SMAA_QUALITY::HIGH ); - break; - case OPENGL_ANTIALIASING_MODE::SUBSAMPLE_ULTRA: - m_antialiasing = std::make_unique( this, SMAA_QUALITY::ULTRA ); - break; - case OPENGL_ANTIALIASING_MODE::SUPERSAMPLING_X2: - m_antialiasing = std::make_unique( this, SUPERSAMPLING_MODE::X2 ); - break; - case OPENGL_ANTIALIASING_MODE::SUPERSAMPLING_X4: - m_antialiasing = std::make_unique( this, SUPERSAMPLING_MODE::X4 ); - break; + case OPENGL_ANTIALIASING_MODE::NONE: + m_antialiasing = std::make_unique( this ); + break; + case OPENGL_ANTIALIASING_MODE::SUBSAMPLE_HIGH: + m_antialiasing = std::make_unique( this, SMAA_QUALITY::HIGH ); + break; + case OPENGL_ANTIALIASING_MODE::SUBSAMPLE_ULTRA: + m_antialiasing = std::make_unique( this, SMAA_QUALITY::ULTRA ); + break; + case OPENGL_ANTIALIASING_MODE::SUPERSAMPLING_X2: + m_antialiasing = + std::make_unique( this, SUPERSAMPLING_MODE::X2 ); + break; + case OPENGL_ANTIALIASING_MODE::SUPERSAMPLING_X4: + m_antialiasing = + std::make_unique( this, SUPERSAMPLING_MODE::X4 ); + break; } VECTOR2U dims = m_antialiasing->GetInternalBufferSize(); @@ -139,7 +146,7 @@ void OPENGL_COMPOSITOR::Resize( unsigned int aWidth, unsigned int aHeight ) m_antialiasing->OnLostBuffers(); - m_width = aWidth; + m_width = aWidth; m_height = aHeight; } @@ -161,9 +168,10 @@ unsigned int OPENGL_COMPOSITOR::CreateBuffer( VECTOR2U aDimensions ) if( (int) usedBuffers() >= maxBuffers ) { - throw std::runtime_error( "Cannot create more framebuffers. OpenGL rendering " - "backend requires at least 3 framebuffers. You may try to update/change " - "your graphic drivers." ); + throw std::runtime_error( + "Cannot create more framebuffers. OpenGL rendering " + "backend requires at least 3 framebuffers. You may try to update/change " + "your graphic drivers." ); } glGetIntegerv( GL_MAX_TEXTURE_SIZE, (GLint*) &maxTextureSize ); @@ -171,7 +179,7 @@ unsigned int OPENGL_COMPOSITOR::CreateBuffer( VECTOR2U aDimensions ) if( maxTextureSize < (int) aDimensions.x || maxTextureSize < (int) aDimensions.y ) { throw std::runtime_error( "Requested texture size is not supported. " - "Could not create a buffer." ); + "Could not create a buffer." ); } // GL_COLOR_ATTACHMENTn are consecutive integers @@ -195,8 +203,8 @@ unsigned int OPENGL_COMPOSITOR::CreateBuffer( VECTOR2U aDimensions ) // Bind the texture to the specific attachment point, clear and rebind the screen bindFb( m_mainFbo ); - glFramebufferTexture2DEXT( GL_FRAMEBUFFER_EXT, attachmentPoint, - GL_TEXTURE_2D, textureTarget, 0 ); + glFramebufferTexture2DEXT( GL_FRAMEBUFFER_EXT, attachmentPoint, GL_TEXTURE_2D, textureTarget, + 0 ); // Check the status, exit if the framebuffer can't be created GLenum status = glCheckFramebufferStatusEXT( GL_FRAMEBUFFER_EXT ); @@ -215,7 +223,7 @@ unsigned int OPENGL_COMPOSITOR::CreateBuffer( VECTOR2U aDimensions ) case GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER_EXT: throw std::runtime_error( "The framebuffer does not have at least one " - "image attached to it." ); + "image attached to it." ); break; case GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER_EXT: @@ -223,13 +231,14 @@ unsigned int OPENGL_COMPOSITOR::CreateBuffer( VECTOR2U aDimensions ) break; case GL_FRAMEBUFFER_UNSUPPORTED_EXT: - throw std::runtime_error( "The combination of internal formats of the attached " + throw std::runtime_error( + "The combination of internal formats of the attached " "images violates an implementation-dependent set of restrictions." ); break; case GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE_EXT: throw std::runtime_error( "GL_RENDERBUFFER_SAMPLES is not the same for " - "all attached renderbuffers" ); + "all attached renderbuffers" ); break; case GL_FRAMEBUFFER_INCOMPLETE_LAYER_TARGETS_EXT: @@ -283,8 +292,8 @@ void OPENGL_COMPOSITOR::SetBuffer( unsigned int aBufferHandle ) glDrawBuffer( m_buffers[m_curBuffer].attachmentPoint ); checkGlError( "setting draw buffer" ); - glViewport( 0, 0, - m_buffers[m_curBuffer].dimensions.x, m_buffers[m_curBuffer].dimensions.y ); + glViewport( 0, 0, m_buffers[m_curBuffer].dimensions.x, + m_buffers[m_curBuffer].dimensions.y ); } else { @@ -327,7 +336,7 @@ void OPENGL_COMPOSITOR::DrawBuffer( unsigned int aSourceHandle, unsigned int aDe assert( aDestHandle <= usedBuffers() ); // Switch to the destination buffer and blit the scene - SetBuffer ( aDestHandle ); + SetBuffer( aDestHandle ); // Depth test has to be disabled to make transparency working glDisable( GL_DEPTH_TEST ); @@ -346,19 +355,19 @@ void OPENGL_COMPOSITOR::DrawBuffer( unsigned int aSourceHandle, unsigned int aDe glLoadIdentity(); glBegin( GL_TRIANGLES ); - glTexCoord2f( 0.0f, 1.0f ); - glVertex2f ( -1.0f, 1.0f ); - glTexCoord2f( 0.0f, 0.0f ); - glVertex2f ( -1.0f, -1.0f ); - glTexCoord2f( 1.0f, 1.0f ); - glVertex2f ( 1.0f, 1.0f ); + glTexCoord2f( 0.0f, 1.0f ); + glVertex2f( -1.0f, 1.0f ); + glTexCoord2f( 0.0f, 0.0f ); + glVertex2f( -1.0f, -1.0f ); + glTexCoord2f( 1.0f, 1.0f ); + glVertex2f( 1.0f, 1.0f ); - glTexCoord2f( 1.0f, 1.0f ); - glVertex2f ( 1.0f, 1.0f ); - glTexCoord2f( 0.0f, 0.0f ); - glVertex2f ( -1.0f, -1.0f ); - glTexCoord2f( 1.0f, 0.0f ); - glVertex2f ( 1.0f, -1.0f ); + glTexCoord2f( 1.0f, 1.0f ); + glVertex2f( 1.0f, 1.0f ); + glTexCoord2f( 0.0f, 0.0f ); + glVertex2f( -1.0f, -1.0f ); + glTexCoord2f( 1.0f, 0.0f ); + glVertex2f( 1.0f, -1.0f ); glEnd(); glPopMatrix(); @@ -414,11 +423,8 @@ int OPENGL_COMPOSITOR::GetAntialiasSupersamplingFactor() const { switch( m_currentAntialiasingMode ) { - case OPENGL_ANTIALIASING_MODE::SUPERSAMPLING_X2: - return 2; - case OPENGL_ANTIALIASING_MODE::SUPERSAMPLING_X4: - return 4; - default: - return 1; + case OPENGL_ANTIALIASING_MODE::SUPERSAMPLING_X2: return 2; + case OPENGL_ANTIALIASING_MODE::SUPERSAMPLING_X4: return 4; + default: return 1; } } diff --git a/common/gal/opengl/opengl_gal.cpp b/common/gal/opengl/opengl_gal.cpp index 6b1f794f42..c93c85c758 100644 --- a/common/gal/opengl/opengl_gal.cpp +++ b/common/gal/opengl/opengl_gal.cpp @@ -2,7 +2,7 @@ * This program source code file is part of KICAD, a free EDA CAD application. * * Copyright (C) 2012 Torsten Hueter, torstenhtr gmx.de - * Copyright (C) 2012-2020 Kicad Developers, see AUTHORS.txt for contributors. + * Copyright (C) 2012-2021 Kicad Developers, see AUTHORS.txt for contributors. * Copyright (C) 2013-2017 CERN * @author Maciej Suminski * @@ -42,7 +42,7 @@ #include #include #include -#include // for KiROUND +#include // for KiROUND #include @@ -75,32 +75,30 @@ using namespace KIGFX; #include "gl_builtin_shaders.h" using namespace KIGFX::BUILTIN_FONT; -static void InitTesselatorCallbacks( GLUtesselator* aTesselator ); +static void InitTesselatorCallbacks( GLUtesselator* aTesselator ); static const int glAttributes[] = { WX_GL_RGBA, WX_GL_DOUBLEBUFFER, WX_GL_DEPTH_SIZE, 8, 0 }; wxGLContext* OPENGL_GAL::glMainContext = NULL; -int OPENGL_GAL::instanceCounter = 0; -GLuint OPENGL_GAL::fontTexture = 0; -bool OPENGL_GAL::isBitmapFontLoaded = false; +int OPENGL_GAL::instanceCounter = 0; +GLuint OPENGL_GAL::fontTexture = 0; +bool OPENGL_GAL::isBitmapFontLoaded = false; -namespace KIGFX { +namespace KIGFX +{ class GL_BITMAP_CACHE { public: - GL_BITMAP_CACHE() - { - } + GL_BITMAP_CACHE() {} ~GL_BITMAP_CACHE(); GLuint RequestBitmap( const BITMAP_BASE* aBitmap ); private: - struct CACHED_BITMAP { GLuint id; - int w, h; + int w, h; }; GLuint cacheBitmap( const BITMAP_BASE* aBitmap ); @@ -108,21 +106,21 @@ private: std::map m_bitmaps; }; -}; +}; // namespace KIGFX GL_BITMAP_CACHE::~GL_BITMAP_CACHE() { - for ( auto b = m_bitmaps.begin(); b != m_bitmaps.end(); ++b ) + for( auto b = m_bitmaps.begin(); b != m_bitmaps.end(); ++b ) glDeleteTextures( 1, &b->second.id ); } GLuint GL_BITMAP_CACHE::RequestBitmap( const BITMAP_BASE* aBitmap ) { - auto it = m_bitmaps.find( aBitmap) ; + auto it = m_bitmaps.find( aBitmap ); - if ( it != m_bitmaps.end() ) + if( it != m_bitmaps.end() ) { // A bitmap is found in cache bitmap. // Ensure the associated texture is still valid (can be destroyed somewhere) @@ -152,17 +150,17 @@ GLuint GL_BITMAP_CACHE::cacheBitmap( const BITMAP_BASE* aBitmap ) extra_w = 4 - extra_w; GLuint textureID; - glGenTextures(1, &textureID); + glGenTextures( 1, &textureID ); // make_unique initializes this to 0, so extra pixels are transparent - auto buf = std::make_unique( ( bmp.w + extra_w ) * bmp.h * 4 ); + auto buf = std::make_unique( ( bmp.w + extra_w ) * bmp.h * 4 ); const wxImage& imgData = *aBitmap->GetImageData(); for( int y = 0; y < bmp.h; y++ ) { for( int x = 0; x < bmp.w; x++ ) { - uint8_t *p = buf.get() + ( ( bmp.w + extra_w ) * y + x ) * 4; + uint8_t* p = buf.get() + ( ( bmp.w + extra_w ) * y + x ) * 4; p[0] = imgData.GetRed( x, y ); p[1] = imgData.GetGreen( x, y ); @@ -170,8 +168,8 @@ GLuint GL_BITMAP_CACHE::cacheBitmap( const BITMAP_BASE* aBitmap ) if( imgData.HasAlpha() ) p[3] = imgData.GetAlpha( x, y ); - else if( imgData.HasMask() && p[0] == imgData.GetMaskRed() && - p[1] == imgData.GetMaskGreen() && p[2] == imgData.GetMaskBlue() ) + else if( imgData.HasMask() && p[0] == imgData.GetMaskRed() + && p[1] == imgData.GetMaskGreen() && p[2] == imgData.GetMaskBlue() ) p[3] = wxALPHA_TRANSPARENT; else p[3] = wxALPHA_OPAQUE; @@ -179,7 +177,8 @@ GLuint GL_BITMAP_CACHE::cacheBitmap( const BITMAP_BASE* aBitmap ) } glBindTexture( GL_TEXTURE_2D, textureID ); - glTexImage2D( GL_TEXTURE_2D, 0, GL_RGBA8, bmp.w + extra_w, bmp.h, 0, GL_RGBA, GL_UNSIGNED_BYTE, buf.get() ); + glTexImage2D( GL_TEXTURE_2D, 0, GL_RGBA8, bmp.w + extra_w, bmp.h, 0, GL_RGBA, GL_UNSIGNED_BYTE, + buf.get() ); glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST ); glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST ); @@ -187,7 +186,7 @@ GLuint GL_BITMAP_CACHE::cacheBitmap( const BITMAP_BASE* aBitmap ) bmp.id = textureID; #ifndef DISABLE_BITMAP_CACHE - m_bitmaps[ aBitmap ] = bmp; + m_bitmaps[aBitmap] = bmp; #endif return textureID; @@ -196,19 +195,19 @@ GLuint GL_BITMAP_CACHE::cacheBitmap( const BITMAP_BASE* aBitmap ) OPENGL_GAL::OPENGL_GAL( GAL_DISPLAY_OPTIONS& aDisplayOptions, wxWindow* aParent, wxEvtHandler* aMouseListener, wxEvtHandler* aPaintListener, const wxString& aName ) : - GAL( aDisplayOptions ), - HIDPI_GL_CANVAS( aParent, wxID_ANY, (int*) glAttributes, wxDefaultPosition, wxDefaultSize, - wxEXPAND, aName ), - mouseListener( aMouseListener ), - paintListener( aPaintListener ), - currentManager( nullptr ), - cachedManager( nullptr ), - nonCachedManager( nullptr ), - overlayManager( nullptr ), - mainBuffer( 0 ), - overlayBuffer( 0 ), - m_isContextLocked( false ), - lockClientCookie( 0 ) + GAL( aDisplayOptions ), + HIDPI_GL_CANVAS( aParent, wxID_ANY, (int*) glAttributes, wxDefaultPosition, wxDefaultSize, + wxEXPAND, aName ), + mouseListener( aMouseListener ), + paintListener( aPaintListener ), + currentManager( nullptr ), + cachedManager( nullptr ), + nonCachedManager( nullptr ), + overlayManager( nullptr ), + mainBuffer( 0 ), + overlayBuffer( 0 ), + m_isContextLocked( false ), + lockClientCookie( 0 ) { if( glMainContext == NULL ) { @@ -224,38 +223,38 @@ OPENGL_GAL::OPENGL_GAL( GAL_DISPLAY_OPTIONS& aDisplayOptions, wxWindow* aParent, shader = new SHADER(); ++instanceCounter; - bitmapCache = std::make_unique( ); + bitmapCache = std::make_unique(); compositor = new OPENGL_COMPOSITOR; compositor->SetAntialiasingMode( options.gl_antialiasing_mode ); // Initialize the flags isFramebufferInitialized = false; - isBitmapFontInitialized = false; - isInitialized = false; - isGrouping = false; - groupCounter = 0; + isBitmapFontInitialized = false; + isInitialized = false; + isGrouping = false; + groupCounter = 0; // Connecting the event handlers - Connect( wxEVT_PAINT, wxPaintEventHandler( OPENGL_GAL::onPaint ) ); + Connect( wxEVT_PAINT, wxPaintEventHandler( OPENGL_GAL::onPaint ) ); // Mouse events are skipped to the parent - Connect( wxEVT_MOTION, wxMouseEventHandler( OPENGL_GAL::skipMouseEvent ) ); - Connect( wxEVT_LEFT_DOWN, wxMouseEventHandler( OPENGL_GAL::skipMouseEvent ) ); - Connect( wxEVT_LEFT_UP, wxMouseEventHandler( OPENGL_GAL::skipMouseEvent ) ); - Connect( wxEVT_LEFT_DCLICK, wxMouseEventHandler( OPENGL_GAL::skipMouseEvent ) ); - Connect( wxEVT_MIDDLE_DOWN, wxMouseEventHandler( OPENGL_GAL::skipMouseEvent ) ); - Connect( wxEVT_MIDDLE_UP, wxMouseEventHandler( OPENGL_GAL::skipMouseEvent ) ); - Connect( wxEVT_MIDDLE_DCLICK, wxMouseEventHandler( OPENGL_GAL::skipMouseEvent ) ); - Connect( wxEVT_RIGHT_DOWN, wxMouseEventHandler( OPENGL_GAL::skipMouseEvent ) ); - Connect( wxEVT_RIGHT_UP, wxMouseEventHandler( OPENGL_GAL::skipMouseEvent ) ); - Connect( wxEVT_RIGHT_DCLICK, wxMouseEventHandler( OPENGL_GAL::skipMouseEvent ) ); - Connect( wxEVT_MOUSEWHEEL, wxMouseEventHandler( OPENGL_GAL::skipMouseEvent ) ); + Connect( wxEVT_MOTION, wxMouseEventHandler( OPENGL_GAL::skipMouseEvent ) ); + Connect( wxEVT_LEFT_DOWN, wxMouseEventHandler( OPENGL_GAL::skipMouseEvent ) ); + Connect( wxEVT_LEFT_UP, wxMouseEventHandler( OPENGL_GAL::skipMouseEvent ) ); + Connect( wxEVT_LEFT_DCLICK, wxMouseEventHandler( OPENGL_GAL::skipMouseEvent ) ); + Connect( wxEVT_MIDDLE_DOWN, wxMouseEventHandler( OPENGL_GAL::skipMouseEvent ) ); + Connect( wxEVT_MIDDLE_UP, wxMouseEventHandler( OPENGL_GAL::skipMouseEvent ) ); + Connect( wxEVT_MIDDLE_DCLICK, wxMouseEventHandler( OPENGL_GAL::skipMouseEvent ) ); + Connect( wxEVT_RIGHT_DOWN, wxMouseEventHandler( OPENGL_GAL::skipMouseEvent ) ); + Connect( wxEVT_RIGHT_UP, wxMouseEventHandler( OPENGL_GAL::skipMouseEvent ) ); + Connect( wxEVT_RIGHT_DCLICK, wxMouseEventHandler( OPENGL_GAL::skipMouseEvent ) ); + Connect( wxEVT_MOUSEWHEEL, wxMouseEventHandler( OPENGL_GAL::skipMouseEvent ) ); #if wxCHECK_VERSION( 3, 1, 0 ) || defined( USE_OSX_MAGNIFY_EVENT ) - Connect( wxEVT_MAGNIFY, wxMouseEventHandler( OPENGL_GAL::skipMouseEvent ) ); + Connect( wxEVT_MAGNIFY, wxMouseEventHandler( OPENGL_GAL::skipMouseEvent ) ); #endif #if defined _WIN32 || defined _WIN64 - Connect( wxEVT_ENTER_WINDOW, wxMouseEventHandler( OPENGL_GAL::skipMouseEvent ) ); + Connect( wxEVT_ENTER_WINDOW, wxMouseEventHandler( OPENGL_GAL::skipMouseEvent ) ); #endif SetSize( aParent->GetClientSize() ); @@ -415,7 +414,7 @@ void OPENGL_GAL::beginDrawing() #endif /* __WXDEBUG__ */ wxASSERT_MSG( m_isContextLocked, "GAL_DRAWING_CONTEXT RAII object should have locked context. " - "Calling GAL::beginDrawing() directly is not allowed." ); + "Calling GAL::beginDrawing() directly is not allowed." ); wxASSERT_MSG( IsVisible(), "GAL::beginDrawing() must not be entered when GAL is not visible. " "Other drawing routines will expect everything to be initialized " @@ -468,15 +467,15 @@ void OPENGL_GAL::beginDrawing() // Set up the world <-> screen transformation ComputeWorldScreenMatrix(); GLdouble matrixData[16] = { 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1 }; - matrixData[0] = worldScreenMatrix.m_data[0][0]; - matrixData[1] = worldScreenMatrix.m_data[1][0]; - matrixData[2] = worldScreenMatrix.m_data[2][0]; - matrixData[4] = worldScreenMatrix.m_data[0][1]; - matrixData[5] = worldScreenMatrix.m_data[1][1]; - matrixData[6] = worldScreenMatrix.m_data[2][1]; - matrixData[12] = worldScreenMatrix.m_data[0][2]; - matrixData[13] = worldScreenMatrix.m_data[1][2]; - matrixData[14] = worldScreenMatrix.m_data[2][2]; + matrixData[0] = worldScreenMatrix.m_data[0][0]; + matrixData[1] = worldScreenMatrix.m_data[1][0]; + matrixData[2] = worldScreenMatrix.m_data[2][0]; + matrixData[4] = worldScreenMatrix.m_data[0][1]; + matrixData[5] = worldScreenMatrix.m_data[1][1]; + matrixData[6] = worldScreenMatrix.m_data[2][1]; + matrixData[12] = worldScreenMatrix.m_data[0][2]; + matrixData[13] = worldScreenMatrix.m_data[1][2]; + matrixData[14] = worldScreenMatrix.m_data[2][2]; glLoadMatrixd( matrixData ); // Set defaults @@ -502,8 +501,8 @@ void OPENGL_GAL::beginDrawing() glActiveTexture( GL_TEXTURE0 + FONT_TEXTURE_UNIT ); glGenTextures( 1, &fontTexture ); glBindTexture( GL_TEXTURE_2D, fontTexture ); - glTexImage2D( GL_TEXTURE_2D, 0, GL_RGB8, font_image.width, font_image.height, - 0, GL_RGB, GL_UNSIGNED_BYTE, font_image.pixels ); + glTexImage2D( GL_TEXTURE_2D, 0, GL_RGB8, font_image.width, font_image.height, 0, GL_RGB, + GL_UNSIGNED_BYTE, font_image.pixels ); glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR ); glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR ); checkGlError( "loading bitmap font" ); @@ -520,15 +519,15 @@ void OPENGL_GAL::beginDrawing() } // Set shader parameter - GLint ufm_fontTexture = shader->AddParameter( "fontTexture" ); - GLint ufm_fontTextureWidth = shader->AddParameter( "fontTextureWidth" ); - ufm_worldPixelSize = shader->AddParameter( "worldPixelSize" ); - ufm_screenPixelSize = shader->AddParameter( "screenPixelSize" ); - ufm_pixelSizeMultiplier = shader->AddParameter( "pixelSizeMultiplier" ); + GLint ufm_fontTexture = shader->AddParameter( "fontTexture" ); + GLint ufm_fontTextureWidth = shader->AddParameter( "fontTextureWidth" ); + ufm_worldPixelSize = shader->AddParameter( "worldPixelSize" ); + ufm_screenPixelSize = shader->AddParameter( "screenPixelSize" ); + ufm_pixelSizeMultiplier = shader->AddParameter( "pixelSizeMultiplier" ); shader->Use(); - shader->SetParameter( ufm_fontTexture, (int) FONT_TEXTURE_UNIT ); - shader->SetParameter( ufm_fontTextureWidth, (int) font_image.width ); + shader->SetParameter( ufm_fontTexture, (int) FONT_TEXTURE_UNIT ); + shader->SetParameter( ufm_fontTextureWidth, (int) font_image.width ); shader->Deactivate(); checkGlError( "setting bitmap font sampler as shader parameter" ); @@ -551,7 +550,8 @@ void OPENGL_GAL::beginDrawing() #ifdef __WXDEBUG__ totalRealTime.Stop(); - wxLogTrace( "GAL_PROFILE", wxT( "OPENGL_GAL::beginDrawing(): %.1f ms" ), totalRealTime.msecs() ); + wxLogTrace( "GAL_PROFILE", wxT( "OPENGL_GAL::beginDrawing(): %.1f ms" ), + totalRealTime.msecs() ); #endif /* __WXDEBUG__ */ } @@ -608,7 +608,7 @@ void OPENGL_GAL::lockContext( int aClientCookie ) void OPENGL_GAL::unlockContext( int aClientCookie ) { wxASSERT_MSG( m_isContextLocked, "Context not locked. A GAL_CONTEXT_LOCKER RAII object must " - "be stacked rather than making separate lock/unlock calls." ); + "be stacked rather than making separate lock/unlock calls." ); wxASSERT_MSG( lockClientCookie == aClientCookie, "Context was locked by a different client. " "Should not be possible with RAII objects." ); @@ -622,7 +622,7 @@ void OPENGL_GAL::unlockContext( int aClientCookie ) void OPENGL_GAL::beginUpdate() { wxASSERT_MSG( m_isContextLocked, "GAL_UPDATE_CONTEXT RAII object should have locked context. " - "Calling this from anywhere else is not allowed." ); + "Calling this from anywhere else is not allowed." ); wxASSERT_MSG( IsVisible(), "GAL::beginUpdate() must not be entered when GAL is not visible. " "Other update routines will expect everything to be initialized " @@ -656,19 +656,19 @@ void OPENGL_GAL::DrawSegment( const VECTOR2D& aStartPoint, const VECTOR2D& aEndP double aWidth ) { VECTOR2D startEndVector = aEndPoint - aStartPoint; - double lineLength = startEndVector.EuclideanNorm(); + double lineLength = startEndVector.EuclideanNorm(); float startx = aStartPoint.x; float starty = aStartPoint.y; float endx = aStartPoint.x + lineLength; float endy = aStartPoint.y + lineLength; - // Be careful about floating point rounding. As we draw segments in larger and larger coordinates, - // the shader (which uses floats) will lose precision and stop drawing small segments. - // In this case, we need to draw a circle for the minimal segment + // Be careful about floating point rounding. As we draw segments in larger and larger + // coordinates, the shader (which uses floats) will lose precision and stop drawing small + // segments. In this case, we need to draw a circle for the minimal segment. if( startx == endx || starty == endy ) { - DrawCircle( aStartPoint, aWidth/2 ); + DrawCircle( aStartPoint, aWidth / 2 ); return; } @@ -681,7 +681,7 @@ void OPENGL_GAL::DrawSegment( const VECTOR2D& aStartPoint, const VECTOR2D& aEndP } else { - auto lineAngle = startEndVector.Angle(); + auto lineAngle = startEndVector.Angle(); // Outlined tracks SetLineWidth( 1.0 ); @@ -692,11 +692,9 @@ void OPENGL_GAL::DrawSegment( const VECTOR2D& aStartPoint, const VECTOR2D& aEndP currentManager->Translate( aStartPoint.x, aStartPoint.y, 0.0 ); currentManager->Rotate( lineAngle, 0.0f, 0.0f, 1.0f ); - drawLineQuad( VECTOR2D( 0.0, aWidth / 2.0 ), - VECTOR2D( lineLength, aWidth / 2.0 ) ); + drawLineQuad( VECTOR2D( 0.0, aWidth / 2.0 ), VECTOR2D( lineLength, aWidth / 2.0 ) ); - drawLineQuad( VECTOR2D( 0.0, -aWidth / 2.0 ), - VECTOR2D( lineLength, -aWidth / 2.0 ) ); + drawLineQuad( VECTOR2D( 0.0, -aWidth / 2.0 ), VECTOR2D( lineLength, -aWidth / 2.0 ) ); // Draw line caps drawStrokedSemiCircle( VECTOR2D( 0.0, 0.0 ), aWidth / 2, M_PI / 2 ); @@ -749,15 +747,15 @@ void OPENGL_GAL::DrawCircle( const VECTOR2D& aCenterPoint, double aRadius ) * v0 /_\/_\ v1 */ currentManager->Shader( SHADER_STROKED_CIRCLE, 1.0, aRadius, lineWidth ); - currentManager->Vertex( aCenterPoint.x, // v0 + currentManager->Vertex( aCenterPoint.x, // v0 aCenterPoint.y, layerDepth ); currentManager->Shader( SHADER_STROKED_CIRCLE, 2.0, aRadius, lineWidth ); - currentManager->Vertex( aCenterPoint.x, // v1 + currentManager->Vertex( aCenterPoint.x, // v1 aCenterPoint.y, layerDepth ); currentManager->Shader( SHADER_STROKED_CIRCLE, 3.0, aRadius, lineWidth ); - currentManager->Vertex( aCenterPoint.x, aCenterPoint.y, // v2 + currentManager->Vertex( aCenterPoint.x, aCenterPoint.y, // v2 layerDepth ); } } @@ -807,7 +805,7 @@ void OPENGL_GAL::DrawArc( const VECTOR2D& aCenterPoint, double aRadius, double a currentManager->Color( strokeColor.r, strokeColor.g, strokeColor.b, strokeColor.a ); VECTOR2D p( cos( aStartAngle ) * aRadius, sin( aStartAngle ) * aRadius ); - double alpha; + double alpha; for( alpha = aStartAngle + alphaIncrement; alpha <= aEndAngle; alpha += alphaIncrement ) { @@ -849,14 +847,14 @@ void OPENGL_GAL::DrawArcSegment( const VECTOR2D& aCenterPoint, double aRadius, d // Refinement: Use a segment count multiple of 2, because we have a control point // on the middle of the arc, and the look is better if it is on a segment junction // because there is no approx error - int seg_count = KiROUND( (aEndAngle -aStartAngle ) / alphaIncrement ); + int seg_count = KiROUND( ( aEndAngle - aStartAngle ) / alphaIncrement ); - if( seg_count %2 != 0 ) + if( seg_count % 2 != 0 ) seg_count += 1; // Recalculate alphaIncrement with a even integer number of segment if( seg_count ) - alphaIncrement = (aEndAngle -aStartAngle ) / seg_count; + alphaIncrement = ( aEndAngle - aStartAngle ) / seg_count; Save(); currentManager->Translate( aCenterPoint.x, aCenterPoint.y, 0.0 ); @@ -865,11 +863,9 @@ void OPENGL_GAL::DrawArcSegment( const VECTOR2D& aCenterPoint, double aRadius, d { currentManager->Color( strokeColor.r, strokeColor.g, strokeColor.b, strokeColor.a ); - double width = aWidth / 2.0; - VECTOR2D startPoint( cos( aStartAngle ) * aRadius, - sin( aStartAngle ) * aRadius ); - VECTOR2D endPoint( cos( aEndAngle ) * aRadius, - sin( aEndAngle ) * aRadius ); + double width = aWidth / 2.0; + VECTOR2D startPoint( cos( aStartAngle ) * aRadius, sin( aStartAngle ) * aRadius ); + VECTOR2D endPoint( cos( aEndAngle ) * aRadius, sin( aEndAngle ) * aRadius ); drawStrokedSemiCircle( startPoint, width, aStartAngle + M_PI ); drawStrokedSemiCircle( endPoint, width, aEndAngle ); @@ -915,7 +911,7 @@ void OPENGL_GAL::DrawArcSegment( const VECTOR2D& aCenterPoint, double aRadius, d SetLineWidth( aWidth ); VECTOR2D p( cos( aStartAngle ) * aRadius, sin( aStartAngle ) * aRadius ); - double alpha; + double alpha; for( alpha = aStartAngle + alphaIncrement; alpha <= aEndAngle; alpha += alphaIncrement ) { @@ -977,13 +973,23 @@ void OPENGL_GAL::DrawRectangle( const VECTOR2D& aStartPoint, const VECTOR2D& aEn void OPENGL_GAL::DrawPolyline( const std::deque& aPointList ) { - drawPolyline( [&](int idx) { return aPointList[idx]; }, aPointList.size() ); + drawPolyline( + [&]( int idx ) + { + return aPointList[idx]; + }, + aPointList.size() ); } void OPENGL_GAL::DrawPolyline( const VECTOR2D aPointList[], int aListSize ) { - drawPolyline( [&](int idx) { return aPointList[idx]; }, aListSize ); + drawPolyline( + [&]( int idx ) + { + return aPointList[idx]; + }, + aListSize ); } @@ -994,14 +1000,19 @@ void OPENGL_GAL::DrawPolyline( const SHAPE_LINE_CHAIN& aLineChain ) if( aLineChain.IsClosed() ) numPoints += 1; - drawPolyline( [&](int idx) { return aLineChain.CPoint(idx); }, numPoints ); + drawPolyline( + [&]( int idx ) + { + return aLineChain.CPoint( idx ); + }, + numPoints ); } void OPENGL_GAL::DrawPolygon( const std::deque& aPointList ) { wxCHECK( aPointList.size() >= 2, /* void */ ); - auto points = std::unique_ptr( new GLdouble[3 * aPointList.size()] ); + auto points = std::unique_ptr( new GLdouble[3 * aPointList.size()] ); GLdouble* ptr = points.get(); for( const VECTOR2D& p : aPointList ) @@ -1018,8 +1029,8 @@ void OPENGL_GAL::DrawPolygon( const std::deque& aPointList ) void OPENGL_GAL::DrawPolygon( const VECTOR2D aPointList[], int aListSize ) { wxCHECK( aListSize >= 2, /* void */ ); - auto points = std::unique_ptr( new GLdouble[3 * aListSize] ); - GLdouble* target = points.get(); + auto points = std::unique_ptr( new GLdouble[3 * aListSize] ); + GLdouble* target = points.get(); const VECTOR2D* src = aPointList; for( int i = 0; i < aListSize; ++i ) @@ -1071,7 +1082,7 @@ void OPENGL_GAL::drawTriangulatedPolyset( const SHAPE_POLY_SET& aPolySet ) if( ADVANCED_CFG::GetCfg().m_DrawTriangulationOutlines ) { - auto oldStrokeColor = strokeColor; + auto oldStrokeColor = strokeColor; double oldLayerDepth = layerDepth; SetLayerDepth( layerDepth - 1 ); @@ -1099,7 +1110,7 @@ void OPENGL_GAL::drawTriangulatedPolyset( const SHAPE_POLY_SET& aPolySet ) void OPENGL_GAL::DrawPolygon( const SHAPE_POLY_SET& aPolySet ) { - if ( aPolySet.IsTriangulationUpToDate() ) + if( aPolySet.IsTriangulationUpToDate() ) { drawTriangulatedPolyset( aPolySet ); return; @@ -1113,14 +1124,13 @@ void OPENGL_GAL::DrawPolygon( const SHAPE_POLY_SET& aPolySet ) } - void OPENGL_GAL::DrawPolygon( const SHAPE_LINE_CHAIN& aPolygon ) { wxCHECK( aPolygon.PointCount() >= 2, /* void */ ); - const int pointCount = aPolygon.SegmentCount() + 1; + const int pointCount = aPolygon.SegmentCount() + 1; std::unique_ptr points( new GLdouble[3 * pointCount] ); - GLdouble* ptr = points.get(); + GLdouble* ptr = points.get(); for( int i = 0; i < pointCount; ++i ) { @@ -1163,13 +1173,13 @@ void OPENGL_GAL::DrawBitmap( const BITMAP_BASE& aBitmap ) auto xform = currentManager->GetTransformation(); - glm::vec4 v0 = xform * glm::vec4( -w/2, -h/2, 0.0, 0.0 ); - glm::vec4 v1 = xform * glm::vec4( w/2, h/2, 0.0, 0.0 ); + glm::vec4 v0 = xform * glm::vec4( -w / 2, -h / 2, 0.0, 0.0 ); + glm::vec4 v1 = xform * glm::vec4( w / 2, h / 2, 0.0, 0.0 ); glm::vec4 trans = xform[3]; auto texture_id = bitmapCache->RequestBitmap( &aBitmap ); - if( !glIsTexture( texture_id ) ) // ensure the bitmap texture is still valid + if( !glIsTexture( texture_id ) ) // ensure the bitmap texture is still valid return; auto oldTarget = GetTarget(); @@ -1178,7 +1188,7 @@ void OPENGL_GAL::DrawBitmap( const BITMAP_BASE& aBitmap ) glTranslated( trans.x, trans.y, trans.z ); SetTarget( TARGET_NONCACHED ); - glEnable(GL_TEXTURE_2D); + glEnable( GL_TEXTURE_2D ); glActiveTexture( GL_TEXTURE0 ); glBindTexture( GL_TEXTURE_2D, texture_id ); @@ -1218,13 +1228,13 @@ void OPENGL_GAL::BitmapText( const wxString& aText, const VECTOR2D& aPosition, const UTF8 text( aText ); // Compute text size, so it can be properly justified VECTOR2D textSize; - float commonOffset; + float commonOffset; std::tie( textSize, commonOffset ) = computeBitmapTextSize( text ); const double SCALE = 1.4 * GetGlyphSize().y / textSize.y; - bool overbar = false; + bool overbar = false; - int overbarLength = 0; + int overbarLength = 0; double overbarHeight = textSize.y; Save(); @@ -1241,18 +1251,16 @@ void OPENGL_GAL::BitmapText( const wxString& aText, const VECTOR2D& aPosition, switch( GetHorizontalJustify() ) { - case GR_TEXT_HJUSTIFY_CENTER: - Translate( VECTOR2D( -textSize.x / 2.0, 0 ) ); - break; + case GR_TEXT_HJUSTIFY_CENTER: Translate( VECTOR2D( -textSize.x / 2.0, 0 ) ); break; case GR_TEXT_HJUSTIFY_RIGHT: //if( !IsTextMirrored() ) - Translate( VECTOR2D( -textSize.x, 0 ) ); + Translate( VECTOR2D( -textSize.x, 0 ) ); break; case GR_TEXT_HJUSTIFY_LEFT: //if( IsTextMirrored() ) - //Translate( VECTOR2D( -textSize.x, 0 ) ); + //Translate( VECTOR2D( -textSize.x, 0 ) ); break; } @@ -1268,8 +1276,7 @@ void OPENGL_GAL::BitmapText( const wxString& aText, const VECTOR2D& aPosition, overbarHeight = 0; break; - case GR_TEXT_VJUSTIFY_BOTTOM: - break; + case GR_TEXT_VJUSTIFY_BOTTOM: break; } int i = 0; @@ -1373,26 +1380,28 @@ void OPENGL_GAL::DrawGrid() // If we cannot display the grid density, scale down by a tick size and // try again. Eventually, we get some representation of the grid - while( std::min( gridScreenSize.x, gridScreenSize.y ) <= gridThreshold ) + while( std::min( gridScreenSize.x, gridScreenSize.y ) <= gridThreshold ) { - gridScreenSize = gridScreenSize * static_cast( gridTick ); + gridScreenSize = gridScreenSize * static_cast( gridTick ); } // Compute grid starting and ending indexes to draw grid points on the // visible screen area // Note: later any point coordinate will be offsetted by gridOrigin int gridStartX = KiROUND( ( worldStartPoint.x - gridOrigin.x ) / gridScreenSize.x ); - int gridEndX = KiROUND( ( worldEndPoint.x - gridOrigin.x ) / gridScreenSize.x ); + int gridEndX = KiROUND( ( worldEndPoint.x - gridOrigin.x ) / gridScreenSize.x ); int gridStartY = KiROUND( ( worldStartPoint.y - gridOrigin.y ) / gridScreenSize.y ); - int gridEndY = KiROUND( ( worldEndPoint.y - gridOrigin.y ) / gridScreenSize.y ); + int gridEndY = KiROUND( ( worldEndPoint.y - gridOrigin.y ) / gridScreenSize.y ); // Ensure start coordinate > end coordinate SWAP( gridStartX, >, gridEndX ); SWAP( gridStartY, >, gridEndY ); // Ensure the grid fills the screen - --gridStartX; ++gridEndX; - --gridStartY; ++gridEndY; + --gridStartX; + ++gridEndX; + --gridStartY; + ++gridEndY; glDisable( GL_DEPTH_TEST ); glDisable( GL_TEXTURE_2D ); @@ -1413,12 +1422,11 @@ void OPENGL_GAL::DrawGrid() if( gridStyle == GRID_STYLE::SMALL_CROSS ) { - // Vertical positions for( int j = gridStartY; j <= gridEndY; j++ ) { - bool tickY = ( j % gridTick == 0 ); - const double posY = j * gridScreenSize.y + gridOrigin.y; + bool tickY = ( j % gridTick == 0 ); + const double posY = j * gridScreenSize.y + gridOrigin.y; // Horizontal positions for( int i = gridStartX; i <= gridEndX; i++ ) @@ -1447,8 +1455,8 @@ void OPENGL_GAL::DrawGrid() continue; SetLineWidth( ( j % gridTick == 0 ) ? majorLineWidth : minorLineWidth ); - VECTOR2D a ( gridStartX * gridScreenSize.x + gridOrigin.x, y ); - VECTOR2D b ( gridEndX * gridScreenSize.x + gridOrigin.x, y ); + VECTOR2D a( gridStartX * gridScreenSize.x + gridOrigin.x, y ); + VECTOR2D b( gridEndX * gridScreenSize.x + gridOrigin.x, y ); DrawLine( a, b ); } @@ -1472,8 +1480,8 @@ void OPENGL_GAL::DrawGrid() continue; SetLineWidth( ( i % gridTick == 0 ) ? majorLineWidth : minorLineWidth ); - VECTOR2D a ( x, gridStartY * gridScreenSize.y + gridOrigin.y ); - VECTOR2D b ( x, gridEndY * gridScreenSize.y + gridOrigin.y ); + VECTOR2D a( x, gridStartY * gridScreenSize.y + gridOrigin.y ); + VECTOR2D b( x, gridEndY * gridScreenSize.y + gridOrigin.y ); DrawLine( a, b ); } @@ -1518,10 +1526,11 @@ void OPENGL_GAL::Flush() } -void OPENGL_GAL::ClearScreen( ) +void OPENGL_GAL::ClearScreen() { // Clear screen compositor->SetBuffer( OPENGL_COMPOSITOR::DIRECT_RENDERING ); + // NOTE: Black used here instead of m_clearColor; it will be composited later glClearColor( 0, 0, 0, 1 ); glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT ); @@ -1532,15 +1541,15 @@ void OPENGL_GAL::Transform( const MATRIX3x3D& aTransformation ) { GLdouble matrixData[16] = { 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1 }; - matrixData[0] = aTransformation.m_data[0][0]; - matrixData[1] = aTransformation.m_data[1][0]; - matrixData[2] = aTransformation.m_data[2][0]; - matrixData[4] = aTransformation.m_data[0][1]; - matrixData[5] = aTransformation.m_data[1][1]; - matrixData[6] = aTransformation.m_data[2][1]; - matrixData[12] = aTransformation.m_data[0][2]; - matrixData[13] = aTransformation.m_data[1][2]; - matrixData[14] = aTransformation.m_data[2][2]; + matrixData[0] = aTransformation.m_data[0][0]; + matrixData[1] = aTransformation.m_data[1][0]; + matrixData[2] = aTransformation.m_data[2][0]; + matrixData[4] = aTransformation.m_data[0][1]; + matrixData[5] = aTransformation.m_data[1][1]; + matrixData[6] = aTransformation.m_data[2][1]; + matrixData[12] = aTransformation.m_data[0][2]; + matrixData[13] = aTransformation.m_data[1][2]; + matrixData[14] = aTransformation.m_data[2][2]; glMultMatrixd( matrixData ); } @@ -1581,7 +1590,7 @@ int OPENGL_GAL::BeginGroup() isGrouping = true; std::shared_ptr newItem = std::make_shared( *cachedManager ); - int groupNumber = getNewGroupNumber(); + int groupNumber = getNewGroupNumber(); groups.insert( std::make_pair( groupNumber, newItem ) ); return groupNumber; @@ -1625,7 +1634,7 @@ void OPENGL_GAL::DeleteGroup( int aGroupNumber ) void OPENGL_GAL::ClearCache() { - bitmapCache = std::make_unique( ); + bitmapCache = std::make_unique(); groups.clear(); @@ -1639,17 +1648,9 @@ void OPENGL_GAL::SetTarget( RENDER_TARGET aTarget ) switch( aTarget ) { default: - case TARGET_CACHED: - currentManager = cachedManager; - break; - - case TARGET_NONCACHED: - currentManager = nonCachedManager; - break; - - case TARGET_OVERLAY: - currentManager = overlayManager; - break; + case TARGET_CACHED: currentManager = cachedManager; break; + case TARGET_NONCACHED: currentManager = nonCachedManager; break; + case TARGET_OVERLAY: currentManager = overlayManager; break; } currentTarget = aTarget; @@ -1699,11 +1700,9 @@ bool OPENGL_GAL::HasTarget( RENDER_TARGET aTarget ) { default: case TARGET_CACHED: - case TARGET_NONCACHED: - return true; + case TARGET_NONCACHED: return true; - case TARGET_OVERLAY: - return ( overlayBuffer != 0 ); + case TARGET_OVERLAY: return ( overlayBuffer != 0 ); } } @@ -1735,8 +1734,9 @@ void OPENGL_GAL::drawLineQuad( const VECTOR2D& aStartPoint, const VECTOR2D& aEnd * dots mark triangles' hypotenuses */ - auto v1 = currentManager->GetTransformation() * glm::vec4( aStartPoint.x, aStartPoint.y, 0.0, 0.0 ); - auto v2 = currentManager->GetTransformation() * glm::vec4( aEndPoint.x, aEndPoint.y, 0.0, 0.0 ); + auto v1 = currentManager->GetTransformation() + * glm::vec4( aStartPoint.x, aStartPoint.y, 0.0, 0.0 ); + auto v2 = currentManager->GetTransformation() * glm::vec4( aEndPoint.x, aEndPoint.y, 0.0, 0.0 ); VECTOR2D vs( v2.x - v1.x, v2.y - v1.y ); @@ -1779,8 +1779,7 @@ void OPENGL_GAL::drawSemiCircle( const VECTOR2D& aCenterPoint, double aRadius, d } -void OPENGL_GAL::drawFilledSemiCircle( const VECTOR2D& aCenterPoint, double aRadius, - double aAngle ) +void OPENGL_GAL::drawFilledSemiCircle( const VECTOR2D& aCenterPoint, double aRadius, double aAngle ) { Save(); @@ -1798,13 +1797,13 @@ void OPENGL_GAL::drawFilledSemiCircle( const VECTOR2D& aCenterPoint, double aRad * v0 //__\\ v1 */ currentManager->Shader( SHADER_FILLED_CIRCLE, 4.0f ); - currentManager->Vertex( -aRadius * 3.0f / sqrt( 3.0f ), 0.0f, layerDepth ); // v0 + currentManager->Vertex( -aRadius * 3.0f / sqrt( 3.0f ), 0.0f, layerDepth ); // v0 currentManager->Shader( SHADER_FILLED_CIRCLE, 5.0f ); - currentManager->Vertex( aRadius * 3.0f / sqrt( 3.0f ), 0.0f, layerDepth ); // v1 + currentManager->Vertex( aRadius * 3.0f / sqrt( 3.0f ), 0.0f, layerDepth ); // v1 currentManager->Shader( SHADER_FILLED_CIRCLE, 6.0f ); - currentManager->Vertex( 0.0f, aRadius * 2.0f, layerDepth ); // v2 + currentManager->Vertex( 0.0f, aRadius * 2.0f, layerDepth ); // v2 Restore(); } @@ -1832,13 +1831,13 @@ void OPENGL_GAL::drawStrokedSemiCircle( const VECTOR2D& aCenterPoint, double aRa * v0 //__\\ v1 */ currentManager->Shader( SHADER_STROKED_CIRCLE, 4.0f, aRadius, lineWidth ); - currentManager->Vertex( -outerRadius * 3.0f / sqrt( 3.0f ), 0.0f, layerDepth ); // v0 + currentManager->Vertex( -outerRadius * 3.0f / sqrt( 3.0f ), 0.0f, layerDepth ); // v0 currentManager->Shader( SHADER_STROKED_CIRCLE, 5.0f, aRadius, lineWidth ); - currentManager->Vertex( outerRadius * 3.0f / sqrt( 3.0f ), 0.0f, layerDepth ); // v1 + currentManager->Vertex( outerRadius * 3.0f / sqrt( 3.0f ), 0.0f, layerDepth ); // v1 currentManager->Shader( SHADER_STROKED_CIRCLE, 6.0f, aRadius, lineWidth ); - currentManager->Vertex( 0.0f, outerRadius * 2.0f, layerDepth ); // v2 + currentManager->Vertex( 0.0f, outerRadius * 2.0f, layerDepth ); // v2 Restore(); } @@ -1862,7 +1861,7 @@ void OPENGL_GAL::drawPolygon( GLdouble* aPoints, int aPointCount ) for( int i = 0; i < aPointCount; ++i ) { gluTessVertex( tesselator, point, point ); - point += 3; // 3 coordinates + point += 3; // 3 coordinates } gluTessEndContour( tesselator ); @@ -1874,13 +1873,17 @@ void OPENGL_GAL::drawPolygon( GLdouble* aPoints, int aPointCount ) if( isStrokeEnabled ) { - drawPolyline( [&](int idx) { return VECTOR2D( aPoints[idx * 3], aPoints[idx * 3 + 1] ); }, + drawPolyline( + [&]( int idx ) + { + return VECTOR2D( aPoints[idx * 3], aPoints[idx * 3 + 1] ); + }, aPointCount ); } } -void OPENGL_GAL::drawPolyline( const std::function& aPointGetter, int aPointCount ) +void OPENGL_GAL::drawPolyline( const std::function& aPointGetter, int aPointCount ) { wxCHECK( aPointCount >= 2, /* return */ ); @@ -1908,7 +1911,7 @@ int OPENGL_GAL::drawBitmapChar( unsigned long aChar ) const FONT_GLYPH_TYPE* g = LookupGlyph( 'x' ); wxASSERT( g ); - if( !g ) // Should not happen. + if( !g ) // Should not happen. return 0; Translate( VECTOR2D( g->advance, 0 ) ); @@ -1922,50 +1925,51 @@ int OPENGL_GAL::drawBitmapChar( unsigned long aChar ) if( !glyph ) glyph = LookupGlyph( '?' ); - if( !glyph ) // Should not happen. + if( !glyph ) // Should not happen. return 0; const float X = glyph->atlas_x + font_information.smooth_pixels; const float Y = glyph->atlas_y + font_information.smooth_pixels; - const float XOFF = glyph->minx; + const float XOFF = glyph->minx; // adjust for height rounding - const float round_adjust = ( glyph->maxy - glyph->miny ) + const float round_adjust = ( glyph->maxy - glyph->miny ) - float( glyph->atlas_h - font_information.smooth_pixels * 2 ); - const float top_adjust = font_information.max_y - glyph->maxy; + const float top_adjust = font_information.max_y - glyph->maxy; const float YOFF = round_adjust + top_adjust; - const float W = glyph->atlas_w - font_information.smooth_pixels *2; - const float H = glyph->atlas_h - font_information.smooth_pixels *2; - const float B = 0; + const float W = glyph->atlas_w - font_information.smooth_pixels * 2; + const float H = glyph->atlas_h - font_information.smooth_pixels * 2; + const float B = 0; currentManager->Reserve( 6 ); Translate( VECTOR2D( XOFF, YOFF ) ); + /* Glyph: - * v0 v1 - * +--+ - * | /| - * |/ | - * +--+ - * v2 v3 - */ + * v0 v1 + * +--+ + * | /| + * |/ | + * +--+ + * v2 v3 + */ currentManager->Shader( SHADER_FONT, X / TEX_X, ( Y + H ) / TEX_Y ); - currentManager->Vertex( -B, -B, 0 ); // v0 + currentManager->Vertex( -B, -B, 0 ); // v0 currentManager->Shader( SHADER_FONT, ( X + W ) / TEX_X, ( Y + H ) / TEX_Y ); - currentManager->Vertex( W + B, -B, 0 ); // v1 + currentManager->Vertex( W + B, -B, 0 ); // v1 currentManager->Shader( SHADER_FONT, X / TEX_X, Y / TEX_Y ); - currentManager->Vertex( -B, H + B, 0 ); // v2 + currentManager->Vertex( -B, H + B, 0 ); // v2 currentManager->Shader( SHADER_FONT, ( X + W ) / TEX_X, ( Y + H ) / TEX_Y ); - currentManager->Vertex( W + B, -B, 0 ); // v1 + currentManager->Vertex( W + B, -B, 0 ); // v1 currentManager->Shader( SHADER_FONT, X / TEX_X, Y / TEX_Y ); - currentManager->Vertex( -B, H + B, 0 ); // v2 + currentManager->Vertex( -B, H + B, 0 ); // v2 currentManager->Shader( SHADER_FONT, ( X + W ) / TEX_X, Y / TEX_Y ); - currentManager->Vertex( W + B, H + B, 0 ); // v3 + currentManager->Vertex( W + B, H + B, 0 ); // v3 Translate( VECTOR2D( -XOFF + glyph->advance, -YOFF ) ); @@ -1983,20 +1987,20 @@ void OPENGL_GAL::drawBitmapOverbar( double aLength, double aHeight ) Save(); - Translate( VECTOR2D( -aLength, -aHeight-1.5*H ) ); + Translate( VECTOR2D( -aLength, -aHeight - 1.5 * H ) ); currentManager->Reserve( 6 ); currentManager->Color( strokeColor.r, strokeColor.g, strokeColor.b, strokeColor.a ); currentManager->Shader( 0 ); - currentManager->Vertex( 0, 0, 0 ); // v0 - currentManager->Vertex( aLength, 0, 0 ); // v1 - currentManager->Vertex( 0, H, 0 ); // v2 + currentManager->Vertex( 0, 0, 0 ); // v0 + currentManager->Vertex( aLength, 0, 0 ); // v1 + currentManager->Vertex( 0, H, 0 ); // v2 - currentManager->Vertex( aLength, 0, 0 ); // v1 - currentManager->Vertex( 0, H, 0 ); // v2 - currentManager->Vertex( aLength, H, 0 ); // v3 + currentManager->Vertex( aLength, 0, 0 ); // v1 + currentManager->Vertex( 0, H, 0 ); // v2 + currentManager->Vertex( aLength, H, 0 ); // v3 Restore(); } @@ -2040,8 +2044,8 @@ std::pair OPENGL_GAL::computeBitmapTextSize( const UTF8& aText const FONT_GLYPH_TYPE* glyph = LookupGlyph( *chIt ); - if( !glyph // Not coded in font - || *chIt == '-' || *chIt == '_' ) // Strange size of these 2 chars + if( !glyph // Not coded in font + || *chIt == '-' || *chIt == '_' ) // Strange size of these 2 chars { glyph = defaultGlyph; } @@ -2058,7 +2062,7 @@ std::pair OPENGL_GAL::computeBitmapTextSize( const UTF8& aText } } - textSize.y = std::max( textSize.y, char_height ); + textSize.y = std::max( textSize.y, char_height ); commonOffset = std::min( font_information.max_y - defaultGlyph->maxy, commonOffset ); textSize.y -= commonOffset; @@ -2089,13 +2093,12 @@ void OPENGL_GAL::blitCursor() const int cursorSize = fullscreenCursor ? 8000 : 80; - VECTOR2D cursorBegin = cursorPosition - cursorSize / ( 2 * worldScale ); - VECTOR2D cursorEnd = cursorPosition + cursorSize / ( 2 * worldScale ); + VECTOR2D cursorBegin = cursorPosition - cursorSize / ( 2 * worldScale ); + VECTOR2D cursorEnd = cursorPosition + cursorSize / ( 2 * worldScale ); VECTOR2D cursorCenter = ( cursorBegin + cursorEnd ) / 2; const COLOR4D cColor = getCursorColor(); - const COLOR4D color( cColor.r * cColor.a, cColor.g * cColor.a, - cColor.b * cColor.a, 1.0 ); + const COLOR4D color( cColor.r * cColor.a, cColor.g * cColor.a, cColor.b * cColor.a, 1.0 ); glActiveTexture( GL_TEXTURE0 ); glDisable( GL_TEXTURE_2D ); @@ -2128,7 +2131,6 @@ unsigned int OPENGL_GAL::getNewGroupNumber() void OPENGL_GAL::init() { - wxASSERT( IsShownOnScreen() ); wxASSERT_MSG( m_isContextLocked, "This should only be called from within a locked context." ); @@ -2162,7 +2164,7 @@ void OPENGL_GAL::init() if( !GLEW_VERSION_2_1 ) throw std::runtime_error( "OpenGL 2.1 or higher is required!" ); -#if defined (__LINUX__) // calling enableGlDebug crashes opengl on some OS (OSX and some Windows) +#if defined( __LINUX__ ) // calling enableGlDebug crashes opengl on some OS (OSX and some Windows) #ifdef DEBUG if( GLEW_ARB_debug_output ) enableGlDebug( true ); @@ -2178,10 +2180,14 @@ void OPENGL_GAL::init() throw std::runtime_error( "Vertex buffer objects are not supported!" ); // Prepare shaders - if( !shader->IsLinked() && !shader->LoadShaderFromStrings( SHADER_TYPE_VERTEX, BUILTIN_SHADERS::kicad_vertex_shader ) ) + if( !shader->IsLinked() + && !shader->LoadShaderFromStrings( SHADER_TYPE_VERTEX, + BUILTIN_SHADERS::kicad_vertex_shader ) ) throw std::runtime_error( "Cannot compile vertex shader!" ); - if( !shader->IsLinked() && !shader->LoadShaderFromStrings( SHADER_TYPE_FRAGMENT, BUILTIN_SHADERS::kicad_fragment_shader ) ) + if( !shader->IsLinked() + && !shader->LoadShaderFromStrings( SHADER_TYPE_FRAGMENT, + BUILTIN_SHADERS::kicad_fragment_shader ) ) throw std::runtime_error( "Cannot compile fragment shader!" ); if( !shader->IsLinked() && !shader->Link() ) @@ -2213,29 +2219,28 @@ void OPENGL_GAL::init() } -// ------------------------------------- // Callback functions for the tesselator // ------------------------------------- // Compare Redbook Chapter 11 +// Callback functions for the tesselator. Compare Redbook Chapter 11. void CALLBACK VertexCallback( GLvoid* aVertexPtr, void* aData ) { - GLdouble* vertex = static_cast( aVertexPtr ); + GLdouble* vertex = static_cast( aVertexPtr ); OPENGL_GAL::TessParams* param = static_cast( aData ); - VERTEX_MANAGER* vboManager = param->vboManager; + VERTEX_MANAGER* vboManager = param->vboManager; assert( vboManager ); vboManager->Vertex( vertex[0], vertex[1], vertex[2] ); } -void CALLBACK CombineCallback( GLdouble coords[3], - GLdouble* vertex_data[4], - GLfloat weight[4], GLdouble** dataOut, void* aData ) +void CALLBACK CombineCallback( GLdouble coords[3], GLdouble* vertex_data[4], GLfloat weight[4], + GLdouble** dataOut, void* aData ) { - GLdouble* vertex = new GLdouble[3]; + GLdouble* vertex = new GLdouble[3]; OPENGL_GAL::TessParams* param = static_cast( aData ); // Save the pointer so we can delete it later param->intersectPoints.emplace_back( vertex ); - memcpy( vertex, coords, 3 * sizeof(GLdouble) ); + memcpy( vertex, coords, 3 * sizeof( GLdouble ) ); *dataOut = vertex; } @@ -2250,16 +2255,16 @@ void CALLBACK EdgeCallback( GLboolean aEdgeFlag ) void CALLBACK ErrorCallback( GLenum aErrorCode ) { //throw std::runtime_error( std::string( "Tessellation error: " ) + - //std::string( (const char*) gluErrorString( aErrorCode ) ); + //std::string( (const char*) gluErrorString( aErrorCode ) ); } static void InitTesselatorCallbacks( GLUtesselator* aTesselator ) { - gluTessCallback( aTesselator, GLU_TESS_VERTEX_DATA, ( void (CALLBACK*)() )VertexCallback ); - gluTessCallback( aTesselator, GLU_TESS_COMBINE_DATA, ( void (CALLBACK*)() )CombineCallback ); - gluTessCallback( aTesselator, GLU_TESS_EDGE_FLAG, ( void (CALLBACK*)() )EdgeCallback ); - gluTessCallback( aTesselator, GLU_TESS_ERROR, ( void (CALLBACK*)() )ErrorCallback ); + gluTessCallback( aTesselator, GLU_TESS_VERTEX_DATA, (void( CALLBACK* )()) VertexCallback ); + gluTessCallback( aTesselator, GLU_TESS_COMBINE_DATA, (void( CALLBACK* )()) CombineCallback ); + gluTessCallback( aTesselator, GLU_TESS_EDGE_FLAG, (void( CALLBACK* )()) EdgeCallback ); + gluTessCallback( aTesselator, GLU_TESS_ERROR, (void( CALLBACK* )()) ErrorCallback ); } void OPENGL_GAL::EnableDepthTest( bool aEnabled ) @@ -2272,7 +2277,7 @@ void OPENGL_GAL::EnableDepthTest( bool aEnabled ) static double roundr( double f, double r ) { - return floor(f / r + 0.5) * r; + return floor( f / r + 0.5 ) * r; } @@ -2285,4 +2290,3 @@ void OPENGL_GAL::ComputeWorldScreenMatrix() GAL::ComputeWorldScreenMatrix(); } - diff --git a/common/gal/opengl/shader.cpp b/common/gal/opengl/shader.cpp index 5fc461e12e..f471ffc26e 100644 --- a/common/gal/opengl/shader.cpp +++ b/common/gal/opengl/shader.cpp @@ -2,7 +2,7 @@ * This program source code file is part of KICAD, a free EDA CAD application. * * Copyright (C) 2012 Torsten Hueter, torstenhtr gmx.de - * Copyright (C) 2012-2020 Kicad Developers, see change_log.txt for contributors. + * Copyright (C) 2012-2021 Kicad Developers, see AUTHORS.txt for contributors. * * Graphics Abstraction Layer (GAL) for OpenGL * @@ -39,12 +39,12 @@ using namespace KIGFX; SHADER::SHADER() : - isProgramCreated( false ), - isShaderLinked( false ), - active( false ), - maximumVertices( 4 ), - geomInputType( GL_LINES ), - geomOutputType( GL_LINES ) + isProgramCreated( false ), + isShaderLinked( false ), + active( false ), + maximumVertices( 4 ), + geomInputType( GL_LINES ), + geomOutputType( GL_LINES ) { // Do not have uninitialized members: @@ -63,7 +63,7 @@ SHADER::~SHADER() { // Delete the shaders and the program for( std::deque::iterator it = shaderNumbers.begin(); it != shaderNumbers.end(); - ++it ) + ++it ) { GLuint shader = *it; @@ -92,8 +92,8 @@ void SHADER::ConfigureGeometryShader( GLuint maxVertices, GLuint geometryInputTy GLuint geometryOutputType ) { maximumVertices = maxVertices; - geomInputType = geometryInputType; - geomOutputType = geometryOutputType; + geomInputType = geometryInputType; + geomOutputType = geometryOutputType; } @@ -156,14 +156,14 @@ void SHADER::SetParameter( int parameterNumber, int value ) const void SHADER::SetParameter( int parameterNumber, float f0, float f1, float f2, float f3 ) const { - assert( (unsigned)parameterNumber < parameterLocation.size() ); + assert( (unsigned) parameterNumber < parameterLocation.size() ); float arr[4] = { f0, f1, f2, f3 }; glUniform4fv( parameterLocation[parameterNumber], 1, arr ); } void SHADER::SetParameter( int aParameterNumber, const VECTOR2D& aValue ) const { - assert( (unsigned)aParameterNumber < parameterLocation.size() ); + assert( (unsigned) aParameterNumber < parameterLocation.size() ); glUniform2f( parameterLocation[aParameterNumber], aValue.x, aValue.y ); } @@ -177,7 +177,7 @@ int SHADER::GetAttribute( const std::string& aAttributeName ) const void SHADER::programInfo( GLuint aProgram ) { GLint glInfoLogLength = 0; - GLint writtenChars = 0; + GLint writtenChars = 0; // Get the length of the info string glGetProgramiv( aProgram, GL_INFO_LOG_LENGTH, &glInfoLogLength ); @@ -196,7 +196,7 @@ void SHADER::programInfo( GLuint aProgram ) void SHADER::shaderInfo( GLuint aShader ) { GLint glInfoLogLength = 0; - GLint writtenChars = 0; + GLint writtenChars = 0; // Get the length of the info string glGetShaderiv( aShader, GL_INFO_LOG_LENGTH, &glInfoLogLength ); @@ -216,7 +216,7 @@ std::string SHADER::ReadSource( const std::string& aShaderSourceName ) { // Open the shader source for reading std::ifstream inputFile( aShaderSourceName.c_str(), std::ifstream::in ); - std::string shaderSource; + std::string shaderSource; if( !inputFile ) throw std::runtime_error( "Can't read the shader source: " + aShaderSourceName ); @@ -234,15 +234,14 @@ std::string SHADER::ReadSource( const std::string& aShaderSourceName ) } -bool SHADER::loadShaderFromStringArray( SHADER_TYPE aShaderType, const char** aArray, - size_t aSize ) +bool SHADER::loadShaderFromStringArray( SHADER_TYPE aShaderType, const char** aArray, size_t aSize ) { assert( !isShaderLinked ); // Create the program if( !isProgramCreated ) { - programNumber = glCreateProgram(); + programNumber = glCreateProgram(); isProgramCreated = true; } diff --git a/common/gal/opengl/utils.cpp b/common/gal/opengl/utils.cpp index bdb43b1fa3..53d33dbad9 100644 --- a/common/gal/opengl/utils.cpp +++ b/common/gal/opengl/utils.cpp @@ -2,6 +2,8 @@ * This program source code file is part of KiCad, a free EDA CAD application. * * Copyright (C) 2016-2017 CERN + * Copyright (C) 2021 KiCad Developers, see AUTHORS.txt for contributors. + * * @author Maciej Suminski * * This program is free software; you can redistribute it and/or @@ -22,93 +24,105 @@ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */ -#include // DisplayError +#include // DisplayError -#include // Must be included first +#include // Must be included first #include -#include // wxLogDebug +#include // wxLogDebug int checkGlError( const std::string& aInfo, bool aThrow ) { - int result = glGetError(); + int result = glGetError(); wxString errorMsg; switch( result ) { - case GL_NO_ERROR: - // all good - break; + case GL_NO_ERROR: + // all good + break; - case GL_INVALID_ENUM: - errorMsg = wxString::Format( "Error: %s: invalid enum", aInfo ); - break; + case GL_INVALID_ENUM: + errorMsg = wxString::Format( "Error: %s: invalid enum", aInfo ); + break; - case GL_INVALID_VALUE: - errorMsg = wxString::Format( "Error: %s: invalid value", aInfo ); - break; + case GL_INVALID_VALUE: + errorMsg = wxString::Format( "Error: %s: invalid value", aInfo ); + break; - case GL_INVALID_OPERATION: - errorMsg = wxString::Format( "Error: %s: invalid operation", aInfo ); - break; + case GL_INVALID_OPERATION: + errorMsg = wxString::Format( "Error: %s: invalid operation", aInfo ); + break; - case GL_INVALID_FRAMEBUFFER_OPERATION: + case GL_INVALID_FRAMEBUFFER_OPERATION: + { + GLenum status = glCheckFramebufferStatusEXT( GL_FRAMEBUFFER_EXT ); + + if( status != GL_FRAMEBUFFER_COMPLETE_EXT ) { - GLenum status = glCheckFramebufferStatusEXT( GL_FRAMEBUFFER_EXT ); - - if( status != GL_FRAMEBUFFER_COMPLETE_EXT ) + switch( status ) { - switch( status ) - { - case GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT_EXT: - errorMsg = "The framebuffer attachment points are incomplete."; - break; - case GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT_EXT: - errorMsg = "No images attached to the framebuffer."; - break; - case GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER_EXT: - errorMsg = "The framebuffer does not have at least one image attached to it."; - break; - case GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER_EXT: - errorMsg = "The framebuffer read buffer is incomplete."; - break; - case GL_FRAMEBUFFER_UNSUPPORTED_EXT: - errorMsg = "The combination of internal formats of the attached images violates an implementation-dependent set of restrictions."; - break; - case GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE_EXT: - errorMsg = "GL_RENDERBUFFER_SAMPLES is not the same for all attached renderbuffers."; - break; - case GL_FRAMEBUFFER_INCOMPLETE_LAYER_TARGETS_EXT: - errorMsg = "Framebuffer incomplete layer targets errors."; - break; - case GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS_EXT: - errorMsg = "Framebuffer attachments have different dimensions"; - break; - default: - errorMsg.Printf( "Unknown incomplete framebuffer error id %X", status ); - } + case GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT_EXT: + errorMsg = "The framebuffer attachment points are incomplete."; + break; + + case GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT_EXT: + errorMsg = "No images attached to the framebuffer."; + break; + + case GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER_EXT: + errorMsg = "The framebuffer does not have at least one image attached to it."; + break; + + case GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER_EXT: + errorMsg = "The framebuffer read buffer is incomplete."; + break; + + case GL_FRAMEBUFFER_UNSUPPORTED_EXT: + errorMsg = "The combination of internal formats of the attached images violates an " + "implementation dependent set of restrictions."; + break; + + case GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE_EXT: + errorMsg = + "GL_RENDERBUFFER_SAMPLES is not the same for all attached render buffers."; + break; + + case GL_FRAMEBUFFER_INCOMPLETE_LAYER_TARGETS_EXT: + errorMsg = "Framebuffer incomplete layer targets errors."; + break; + + case GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS_EXT: + errorMsg = "Framebuffer attachments have different dimensions"; + break; + + default: + errorMsg.Printf( "Unknown incomplete framebuffer error id %X", status ); } - else - errorMsg = wxString::Format( "Error: %s: invalid framebuffer operation", aInfo ); } - break; + else + { + errorMsg = wxString::Format( "Error: %s: invalid framebuffer operation", aInfo ); + } + } + break; - case GL_OUT_OF_MEMORY: - errorMsg = wxString::Format( "Error: %s: out of memory", aInfo ); - break; + case GL_OUT_OF_MEMORY: + errorMsg = wxString::Format( "Error: %s: out of memory", aInfo ); + break; - case GL_STACK_UNDERFLOW: - errorMsg = wxString::Format( "Error: %s: stack underflow", aInfo ); - break; + case GL_STACK_UNDERFLOW: + errorMsg = wxString::Format( "Error: %s: stack underflow", aInfo ); + break; - case GL_STACK_OVERFLOW: - errorMsg = wxString::Format( "Error: %s: stack overflow", aInfo ); - break; + case GL_STACK_OVERFLOW: + errorMsg = wxString::Format( "Error: %s: stack overflow", aInfo ); + break; - default: - errorMsg = wxString::Format( "Error: %s: unknown error", aInfo ); - break; + default: + errorMsg = wxString::Format( "Error: %s: unknown error", aInfo ); + break; } if( result != GL_NO_ERROR ) @@ -125,15 +139,16 @@ int checkGlError( const std::string& aInfo, bool aThrow ) // debugMsgCallback is a callback function for glDebugMessageCallback. // It must have the right type ( GLAPIENTRY ) -static void GLAPIENTRY debugMsgCallback( GLenum aSource, GLenum aType, GLuint aId, - GLenum aSeverity, GLsizei aLength, const GLchar* aMessage, const void* aUserParam ) +static void GLAPIENTRY debugMsgCallback( GLenum aSource, GLenum aType, GLuint aId, GLenum aSeverity, + GLsizei aLength, const GLchar* aMessage, + const void* aUserParam ) { switch( aSeverity ) { - case GL_DEBUG_SEVERITY_HIGH: wxLogDebug( "OpenGL ERROR: " ); break; - case GL_DEBUG_SEVERITY_MEDIUM: wxLogDebug( "OpenGL WARNING: " ); break; - case GL_DEBUG_SEVERITY_LOW: wxLogDebug( "OpenGL INFO: " ); break; - case GL_DEBUG_SEVERITY_NOTIFICATION: return; + case GL_DEBUG_SEVERITY_HIGH: wxLogDebug( "OpenGL ERROR: " ); break; + case GL_DEBUG_SEVERITY_MEDIUM: wxLogDebug( "OpenGL WARNING: " ); break; + case GL_DEBUG_SEVERITY_LOW: wxLogDebug( "OpenGL INFO: " ); break; + case GL_DEBUG_SEVERITY_NOTIFICATION: return; } wxLogDebug( "%s\n", aMessage ); diff --git a/common/gal/opengl/vertex_container.cpp b/common/gal/opengl/vertex_container.cpp index 7ade5d415a..8df373f40c 100644 --- a/common/gal/opengl/vertex_container.cpp +++ b/common/gal/opengl/vertex_container.cpp @@ -2,6 +2,8 @@ * This program source code file is part of KiCad, a free EDA CAD application. * * Copyright (C) 2013 CERN + * Copyright (C) 2021 KiCad Developers, see AUTHORS.txt for contributors. + * * @author Maciej Suminski * * This program is free software; you can redistribute it and/or @@ -56,8 +58,12 @@ VERTEX_CONTAINER* VERTEX_CONTAINER::MakeContainer( bool aCached ) VERTEX_CONTAINER::VERTEX_CONTAINER( unsigned int aSize ) : - m_freeSpace( aSize ), m_currentSize( aSize ), m_initialSize( aSize ), - m_vertices( NULL ), m_failed( false ), m_dirty( true ) + m_freeSpace( aSize ), + m_currentSize( aSize ), + m_initialSize( aSize ), + m_vertices( NULL ), + m_failed( false ), + m_dirty( true ) { } diff --git a/common/gal/opengl/vertex_item.cpp b/common/gal/opengl/vertex_item.cpp index a6fd352766..a0cbe96432 100644 --- a/common/gal/opengl/vertex_item.cpp +++ b/common/gal/opengl/vertex_item.cpp @@ -2,6 +2,8 @@ * This program source code file is part of KiCad, a free EDA CAD application. * * Copyright (C) 2013 CERN + * Copyright (C) 2021 KiCad Developers, see AUTHORS.txt for contributors. + * * @author Maciej Suminski * * This program is free software; you can redistribute it and/or @@ -34,7 +36,9 @@ using namespace KIGFX; VERTEX_ITEM::VERTEX_ITEM( const VERTEX_MANAGER& aManager ) : - m_manager( aManager ), m_offset( 0 ), m_size( 0 ) + m_manager( aManager ), + m_offset( 0 ), + m_size( 0 ) { // As the item is created, we are going to modify it, so call to SetItem() is needed m_manager.SetItem( *this ); diff --git a/common/gal/opengl/vertex_manager.cpp b/common/gal/opengl/vertex_manager.cpp index b0e497df70..e297066337 100644 --- a/common/gal/opengl/vertex_manager.cpp +++ b/common/gal/opengl/vertex_manager.cpp @@ -2,6 +2,8 @@ * This program source code file is part of KiCad, a free EDA CAD application. * * Copyright (C) 2013-2016 CERN + * Copyright (C) 2021 KiCad Developers, see AUTHORS.txt for contributors. + * * @author Maciej Suminski * * This program is free software; you can redistribute it and/or @@ -38,7 +40,10 @@ using namespace KIGFX; VERTEX_MANAGER::VERTEX_MANAGER( bool aCached ) : - m_noTransform( true ), m_transform( 1.0f ), m_reserved( NULL ), m_reservedSpace( 0 ) + m_noTransform( true ), + m_transform( 1.0f ), + m_reserved( NULL ), + m_reservedSpace( 0 ) { m_container.reset( VERTEX_CONTAINER::MakeContainer( aCached ) ); m_gpu.reset( GPU_MANAGER::MakeManager( m_container.get() ) ); @@ -174,7 +179,7 @@ void VERTEX_MANAGER::FreeItem( VERTEX_ITEM& aItem ) const void VERTEX_MANAGER::ChangeItemColor( const VERTEX_ITEM& aItem, const COLOR4D& aColor ) const { - unsigned int size = aItem.GetSize(); + unsigned int size = aItem.GetSize(); unsigned int offset = aItem.GetOffset(); VERTEX* vertex = m_container->GetVertices( offset ); @@ -194,7 +199,7 @@ void VERTEX_MANAGER::ChangeItemColor( const VERTEX_ITEM& aItem, const COLOR4D& a void VERTEX_MANAGER::ChangeItemDepth( const VERTEX_ITEM& aItem, GLfloat aDepth ) const { - unsigned int size = aItem.GetSize(); + unsigned int size = aItem.GetSize(); unsigned int offset = aItem.GetOffset(); VERTEX* vertex = m_container->GetVertices( offset );