GAL code cleaning.
This commit is contained in:
parent
0d2ee266a1
commit
e7227a4f21
|
@ -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 <tomasz.wlostowski@cern.ch>
|
||||
* @author Maciej Suminski <maciej.suminski@cern.ch>
|
||||
*
|
||||
|
@ -53,9 +54,8 @@
|
|||
|
||||
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 ),
|
||||
KIGFX::GAL_DISPLAY_OPTIONS& aOptions, GAL_TYPE aGalType ) :
|
||||
wxScrolledCanvas( aParentWindow, aWindowId, aPosition, aSize ),
|
||||
m_edaFrame( nullptr ),
|
||||
m_gal( nullptr ),
|
||||
m_view( nullptr ),
|
||||
|
@ -96,18 +96,27 @@ EDA_DRAW_PANEL_GAL::EDA_DRAW_PANEL_GAL( wxWindow* aParentWindow, wxWindowID aWin
|
|||
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<KIGFX::RENDER_SETTINGS*>( m_painter->GetSettings() );
|
||||
KIGFX::RENDER_SETTINGS* settings =
|
||||
static_cast<KIGFX::RENDER_SETTINGS*>( m_painter->GetSettings() );
|
||||
|
||||
try
|
||||
{
|
||||
|
@ -206,7 +217,7 @@ 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();
|
||||
|
@ -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,7 +426,8 @@ bool EDA_DRAW_PANEL_GAL::SwitchBackend( GAL_TYPE aGalType )
|
|||
if( GAL_FALLBACK != aGalType )
|
||||
{
|
||||
aGalType = GAL_FALLBACK;
|
||||
DisplayInfoMessage( m_parent,
|
||||
DisplayInfoMessage(
|
||||
m_parent,
|
||||
_( "Could not use OpenGL, falling back to software rendering" ),
|
||||
errormsg );
|
||||
new_gal = new KIGFX::CAIRO_GAL( m_options, this, this, this );
|
||||
|
@ -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<wxWindow*>( new_gal );
|
||||
|
@ -499,8 +507,7 @@ 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()
|
||||
bool shouldSetFocus = m_lostFocus && m_stealsFocus && !KIUI::IsInputControlFocused()
|
||||
&& !KIUI::IsModalDialogFocused();
|
||||
|
||||
#if defined( _WIN32 )
|
||||
|
@ -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();
|
||||
}
|
||||
|
||||
|
|
|
@ -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 <maciej.suminski@cern.ch>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
|
@ -35,7 +36,9 @@
|
|||
using namespace KIGFX;
|
||||
|
||||
CAIRO_COMPOSITOR::CAIRO_COMPOSITOR( cairo_t** aMainContext ) :
|
||||
m_current( 0 ), m_currentContext( aMainContext ), m_mainContext( *aMainContext ),
|
||||
m_current( 0 ),
|
||||
m_currentContext( aMainContext ),
|
||||
m_mainContext( *aMainContext ),
|
||||
m_currentAntialiasingMode( CAIRO_ANTIALIAS_DEFAULT )
|
||||
{
|
||||
// Do not have uninitialized members:
|
||||
|
@ -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();
|
||||
|
@ -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;
|
||||
|
|
|
@ -2,8 +2,9 @@
|
|||
* This program source code file is part of KICAD, a free EDA CAD application.
|
||||
*
|
||||
* Copyright (C) 2012 Torsten Hueter, torstenhtr <at> 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 <maciej.suminski@cern.ch>
|
||||
*
|
||||
* CairoGal - Graphics Abstraction Layer for Cairo
|
||||
|
@ -45,9 +46,7 @@
|
|||
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;
|
||||
|
@ -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 );
|
||||
}
|
||||
|
@ -212,7 +212,7 @@ void CAIRO_GAL_BASE::syncLineWidth( bool aForceWidth, double aWidth )
|
|||
{
|
||||
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;
|
||||
|
@ -260,15 +260,16 @@ void CAIRO_GAL_BASE::DrawSegment( const VECTOR2D& aStartPoint, const VECTOR2D& a
|
|||
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();
|
||||
}
|
||||
|
@ -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 )
|
||||
{
|
||||
|
@ -375,7 +377,8 @@ void CAIRO_GAL_BASE::DrawArcSegment( const VECTOR2D& aCenterPoint, double aRadiu
|
|||
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
@ -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,13 +796,13 @@ 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:
|
||||
|
@ -812,18 +812,20 @@ void CAIRO_GAL_BASE::DrawGroup( int aGroupNumber )
|
|||
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 )
|
||||
{
|
||||
|
@ -975,7 +976,7 @@ void CAIRO_GAL_BASE::drawAxes( const VECTOR2D& aStartPoint, const VECTOR2D& aEnd
|
|||
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 );
|
||||
|
@ -1030,12 +1031,12 @@ void CAIRO_GAL_BASE::drawGridPoint( const VECTOR2D& aPoint, double aWidth, doubl
|
|||
cairo_fill( currentContext );
|
||||
}
|
||||
|
||||
|
||||
void CAIRO_GAL_BASE::flushPath()
|
||||
{
|
||||
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 );
|
||||
|
||||
if( isStrokeEnabled )
|
||||
cairo_fill_preserve( currentContext );
|
||||
|
@ -1045,8 +1046,8 @@ void CAIRO_GAL_BASE::flushPath()
|
|||
|
||||
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( 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 );
|
||||
}
|
||||
}
|
||||
|
@ -1110,8 +1112,8 @@ void CAIRO_GAL_BASE::blitCursor( wxMemoryDC& clientDC )
|
|||
const auto cColor = getCursorColor();
|
||||
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 );
|
||||
|
@ -1206,9 +1208,9 @@ 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::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 )
|
||||
{
|
||||
|
@ -1286,14 +1288,15 @@ 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,
|
||||
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 );
|
||||
|
@ -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,7 +1456,9 @@ 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 );
|
||||
|
@ -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();
|
||||
|
@ -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,7 +1625,6 @@ 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
|
||||
|
@ -1659,4 +1656,3 @@ void CAIRO_GAL_BASE::DrawGrid()
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
/*
|
||||
* Copyright (C) 2019 CERN
|
||||
* Copyright (C) 2021 Kicad Developers, see AUTHORS.txt for contributors.
|
||||
*
|
||||
* Author: Maciej Suminski <maciej.suminski@cern.ch>
|
||||
* Author: Tomasz Wlostowski <tomasz.wlostowski@cern.ch>
|
||||
*
|
||||
|
@ -27,8 +29,8 @@
|
|||
|
||||
#ifdef NOMINMAX /* workaround for gdiplus.h */
|
||||
#include <algorithm>
|
||||
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<wxPrinterDC*>( aDC ) )
|
||||
m_gcdc = new wxGCDC( *printerDC );
|
||||
|
@ -69,15 +73,18 @@ CAIRO_PRINT_CTX::CAIRO_PRINT_CTX( wxDC* aDC )
|
|||
#ifdef __WXGTK__
|
||||
m_ctx = static_cast<cairo_t*>( 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__ */
|
||||
|
||||
|
@ -125,8 +132,8 @@ CAIRO_PRINT_CTX::~CAIRO_PRINT_CTX()
|
|||
|
||||
|
||||
CAIRO_PRINT_GAL::CAIRO_PRINT_GAL( GAL_DISPLAY_OPTIONS& aDisplayOptions,
|
||||
std::unique_ptr<CAIRO_PRINT_CTX> aContext )
|
||||
: CAIRO_GAL_BASE( aDisplayOptions )
|
||||
std::unique_ptr<CAIRO_PRINT_CTX> 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;
|
||||
|
|
|
@ -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 <gal/opengl/antialiasing.h>
|
||||
#include <gal/opengl/opengl_compositor.h>
|
||||
|
@ -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,10 +88,10 @@ unsigned int ANTIALIASING_NONE::CreateBuffer()
|
|||
}
|
||||
|
||||
|
||||
namespace {
|
||||
|
||||
void draw_fullscreen_primitive()
|
||||
{
|
||||
namespace
|
||||
{
|
||||
void draw_fullscreen_primitive()
|
||||
{
|
||||
glMatrixMode( GL_MODELVIEW );
|
||||
glPushMatrix();
|
||||
glLoadIdentity();
|
||||
|
@ -119,18 +119,18 @@ namespace {
|
|||
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<SHADER>( );
|
||||
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<SHADER>();
|
||||
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,8 +317,7 @@ 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 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 );
|
||||
|
@ -316,61 +325,85 @@ uniform vec4 SMAA_RT_METRICS;
|
|||
//
|
||||
// Set up pass 1 Shader
|
||||
//
|
||||
pass_1_shader = std::make_unique<SHADER>( );
|
||||
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<SHADER>();
|
||||
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<SHADER>( );
|
||||
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<SHADER>();
|
||||
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<SHADER>( );
|
||||
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<SHADER>();
|
||||
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,9 +493,10 @@ void ANTIALIASING_SMAA::Begin()
|
|||
}
|
||||
|
||||
|
||||
namespace {
|
||||
void draw_fullscreen_triangle()
|
||||
{
|
||||
namespace
|
||||
{
|
||||
void draw_fullscreen_triangle()
|
||||
{
|
||||
glMatrixMode( GL_MODELVIEW );
|
||||
glPushMatrix();
|
||||
glLoadIdentity();
|
||||
|
@ -473,8 +516,8 @@ namespace {
|
|||
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();
|
||||
|
||||
|
|
|
@ -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 <maciej.suminski@cern.ch>
|
||||
*
|
||||
|
@ -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 ) );
|
||||
|
@ -341,7 +345,6 @@ void CACHED_CONTAINER::mergeFreeChunks()
|
|||
// and let's check the next chunk
|
||||
offset = itf->first;
|
||||
size = itf->second;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -389,6 +392,7 @@ void CACHED_CONTAINER::test()
|
|||
// Used space check
|
||||
unsigned int used_space = 0;
|
||||
ITEMS::iterator itr;
|
||||
|
||||
for( itr = m_items.begin(); itr != m_items.end(); ++itr )
|
||||
used_space += ( *itr )->GetSize();
|
||||
|
||||
|
|
|
@ -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 <maciej.suminski@cern.ch>
|
||||
*
|
||||
|
@ -30,10 +30,11 @@
|
|||
#include <gal/opengl/shader.h>
|
||||
#include <gal/opengl/utils.h>
|
||||
|
||||
#include <wx/log.h>
|
||||
|
||||
#include <list>
|
||||
|
||||
#ifdef __WXDEBUG__
|
||||
#include <wx/log.h>
|
||||
#include <profile.h>
|
||||
#endif /* __WXDEBUG__ */
|
||||
|
||||
|
@ -44,11 +45,11 @@ CACHED_CONTAINER_GPU::CACHED_CONTAINER_GPU( unsigned int aSize ) :
|
|||
{
|
||||
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 )
|
||||
|
@ -150,8 +154,8 @@ bool CACHED_CONTAINER_GPU::defragmentResize( unsigned int aNewSize )
|
|||
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 );
|
||||
|
@ -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 )
|
||||
|
@ -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__ */
|
||||
|
||||
|
|
|
@ -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 <maciej.suminski@cern.ch>
|
||||
*
|
||||
* 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__ */
|
||||
|
||||
|
|
|
@ -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 <maciej.suminski@cern.ch>
|
||||
*
|
||||
* 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();
|
||||
}
|
||||
|
@ -175,13 +187,13 @@ void GPU_CACHED_MANAGER::EndDrawing()
|
|||
{
|
||||
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__ */
|
||||
}
|
||||
|
||||
|
@ -276,12 +288,12 @@ void GPU_NONCACHED_MANAGER::EndDrawing()
|
|||
|
||||
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__ */
|
||||
}
|
||||
|
||||
|
|
|
@ -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 <maciej.suminski@cern.ch>
|
||||
*
|
||||
* 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<VERTEX*>( malloc( aSize * sizeof( VERTEX ) ) );
|
||||
memset( m_vertices, 0x00, aSize * sizeof( VERTEX ) );
|
||||
|
@ -60,9 +63,8 @@ VERTEX* NONCACHED_CONTAINER::Allocate( unsigned int aSize )
|
|||
if( m_freeSpace < aSize )
|
||||
{
|
||||
// Double the space
|
||||
VERTEX* newVertices = static_cast<VERTEX*>( realloc( m_vertices,
|
||||
m_currentSize * 2 *
|
||||
sizeof(VERTEX) ) );
|
||||
VERTEX* newVertices =
|
||||
static_cast<VERTEX*>( realloc( m_vertices, m_currentSize * 2 * sizeof( VERTEX ) ) );
|
||||
|
||||
if( newVertices != NULL )
|
||||
{
|
||||
|
|
|
@ -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 <maciej.suminski@cern.ch>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
|
@ -40,8 +42,11 @@
|
|||
using namespace KIGFX;
|
||||
|
||||
OPENGL_COMPOSITOR::OPENGL_COMPOSITOR() :
|
||||
m_initialized( false ), m_curBuffer( 0 ),
|
||||
m_mainFbo( 0 ), m_depthBuffer( 0 ), m_curFbo( DIRECT_RENDERING ),
|
||||
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<ANTIALIASING_NONE>( this );
|
||||
|
@ -87,10 +92,12 @@ void OPENGL_COMPOSITOR::Initialize()
|
|||
m_antialiasing = std::make_unique<ANTIALIASING_SMAA>( this, SMAA_QUALITY::ULTRA );
|
||||
break;
|
||||
case OPENGL_ANTIALIASING_MODE::SUPERSAMPLING_X2:
|
||||
m_antialiasing = std::make_unique<ANTIALIASING_SUPERSAMPLING>( this, SUPERSAMPLING_MODE::X2 );
|
||||
m_antialiasing =
|
||||
std::make_unique<ANTIALIASING_SUPERSAMPLING>( this, SUPERSAMPLING_MODE::X2 );
|
||||
break;
|
||||
case OPENGL_ANTIALIASING_MODE::SUPERSAMPLING_X4:
|
||||
m_antialiasing = std::make_unique<ANTIALIASING_SUPERSAMPLING>( this, SUPERSAMPLING_MODE::X4 );
|
||||
m_antialiasing =
|
||||
std::make_unique<ANTIALIASING_SUPERSAMPLING>( this, SUPERSAMPLING_MODE::X4 );
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -161,7 +168,8 @@ unsigned int OPENGL_COMPOSITOR::CreateBuffer( VECTOR2U aDimensions )
|
|||
|
||||
if( (int) usedBuffers() >= maxBuffers )
|
||||
{
|
||||
throw std::runtime_error( "Cannot create more framebuffers. OpenGL rendering "
|
||||
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." );
|
||||
}
|
||||
|
@ -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 );
|
||||
|
@ -223,7 +231,8 @@ 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;
|
||||
|
||||
|
@ -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 );
|
||||
|
@ -347,18 +356,18 @@ void OPENGL_COMPOSITOR::DrawBuffer( unsigned int aSourceHandle, unsigned int aDe
|
|||
|
||||
glBegin( GL_TRIANGLES );
|
||||
glTexCoord2f( 0.0f, 1.0f );
|
||||
glVertex2f ( -1.0f, 1.0f );
|
||||
glVertex2f( -1.0f, 1.0f );
|
||||
glTexCoord2f( 0.0f, 0.0f );
|
||||
glVertex2f ( -1.0f, -1.0f );
|
||||
glVertex2f( -1.0f, -1.0f );
|
||||
glTexCoord2f( 1.0f, 1.0f );
|
||||
glVertex2f ( 1.0f, 1.0f );
|
||||
glVertex2f( 1.0f, 1.0f );
|
||||
|
||||
glTexCoord2f( 1.0f, 1.0f );
|
||||
glVertex2f ( 1.0f, 1.0f );
|
||||
glVertex2f( 1.0f, 1.0f );
|
||||
glTexCoord2f( 0.0f, 0.0f );
|
||||
glVertex2f ( -1.0f, -1.0f );
|
||||
glVertex2f( -1.0f, -1.0f );
|
||||
glTexCoord2f( 1.0f, 0.0f );
|
||||
glVertex2f ( 1.0f, -1.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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
* This program source code file is part of KICAD, a free EDA CAD application.
|
||||
*
|
||||
* Copyright (C) 2012 Torsten Hueter, torstenhtr <at> 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 <maciej.suminski@cern.ch>
|
||||
*
|
||||
|
@ -83,20 +83,18 @@ 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;
|
||||
|
@ -108,21 +106,21 @@ private:
|
|||
std::map<const BITMAP_BASE*, CACHED_BITMAP> 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,7 +150,7 @@ 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<uint8_t[]>( ( bmp.w + extra_w ) * bmp.h * 4 );
|
||||
|
@ -162,7 +160,7 @@ GLuint GL_BITMAP_CACHE::cacheBitmap( const BITMAP_BASE* aBitmap )
|
|||
{
|
||||
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;
|
||||
|
@ -224,7 +223,7 @@ OPENGL_GAL::OPENGL_GAL( GAL_DISPLAY_OPTIONS& aDisplayOptions, wxWindow* aParent,
|
|||
shader = new SHADER();
|
||||
++instanceCounter;
|
||||
|
||||
bitmapCache = std::make_unique<GL_BITMAP_CACHE>( );
|
||||
bitmapCache = std::make_unique<GL_BITMAP_CACHE>();
|
||||
|
||||
compositor = new OPENGL_COMPOSITOR;
|
||||
compositor->SetAntialiasingMode( options.gl_antialiasing_mode );
|
||||
|
@ -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" );
|
||||
|
@ -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__ */
|
||||
}
|
||||
|
||||
|
@ -663,12 +663,12 @@ void OPENGL_GAL::DrawSegment( const VECTOR2D& aStartPoint, const VECTOR2D& aEndP
|
|||
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;
|
||||
}
|
||||
|
||||
|
@ -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 );
|
||||
|
@ -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 );
|
||||
|
@ -866,10 +864,8 @@ 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 );
|
||||
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 );
|
||||
|
@ -977,13 +973,23 @@ void OPENGL_GAL::DrawRectangle( const VECTOR2D& aStartPoint, const VECTOR2D& aEn
|
|||
|
||||
void OPENGL_GAL::DrawPolyline( const std::deque<VECTOR2D>& 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,7 +1000,12 @@ 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 );
|
||||
}
|
||||
|
||||
|
||||
|
@ -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,7 +1124,6 @@ void OPENGL_GAL::DrawPolygon( const SHAPE_POLY_SET& aPolySet )
|
|||
}
|
||||
|
||||
|
||||
|
||||
void OPENGL_GAL::DrawPolygon( const SHAPE_LINE_CHAIN& aPolygon )
|
||||
{
|
||||
wxCHECK( aPolygon.PointCount() >= 2, /* void */ );
|
||||
|
@ -1163,8 +1173,8 @@ 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 );
|
||||
|
@ -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 );
|
||||
|
||||
|
@ -1241,9 +1251,7 @@ 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() )
|
||||
|
@ -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;
|
||||
|
@ -1391,8 +1398,10 @@ void OPENGL_GAL::DrawGrid()
|
|||
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,7 +1422,6 @@ void OPENGL_GAL::DrawGrid()
|
|||
|
||||
if( gridStyle == GRID_STYLE::SMALL_CROSS )
|
||||
{
|
||||
|
||||
// Vertical positions
|
||||
for( int j = gridStartY; j <= gridEndY; j++ )
|
||||
{
|
||||
|
@ -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 );
|
||||
|
@ -1625,7 +1634,7 @@ void OPENGL_GAL::DeleteGroup( int aGroupNumber )
|
|||
|
||||
void OPENGL_GAL::ClearCache()
|
||||
{
|
||||
bitmapCache = std::make_unique<GL_BITMAP_CACHE>( );
|
||||
bitmapCache = std::make_unique<GL_BITMAP_CACHE>();
|
||||
|
||||
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,7 +1734,8 @@ 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 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();
|
||||
|
||||
|
@ -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<VECTOR2D (int)>& aPointGetter, int aPointCount )
|
||||
void OPENGL_GAL::drawPolyline( const std::function<VECTOR2D( int )>& aPointGetter, int aPointCount )
|
||||
{
|
||||
wxCHECK( aPointCount >= 2, /* return */ );
|
||||
|
||||
|
@ -1934,12 +1937,13 @@ int OPENGL_GAL::drawBitmapChar( unsigned long aChar )
|
|||
- float( glyph->atlas_h - font_information.smooth_pixels * 2 );
|
||||
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 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
|
||||
* +--+
|
||||
|
@ -1983,7 +1987,7 @@ 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 );
|
||||
|
@ -2094,8 +2098,7 @@ void OPENGL_GAL::blitCursor()
|
|||
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,7 +2219,7 @@ 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<GLdouble*>( aVertexPtr );
|
||||
|
@ -2225,9 +2231,8 @@ void CALLBACK VertexCallback( GLvoid* aVertexPtr, void* aData )
|
|||
}
|
||||
|
||||
|
||||
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];
|
||||
OPENGL_GAL::TessParams* param = static_cast<OPENGL_GAL::TessParams*>( aData );
|
||||
|
@ -2235,7 +2240,7 @@ void CALLBACK CombineCallback( GLdouble coords[3],
|
|||
// 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;
|
||||
}
|
||||
|
@ -2256,10 +2261,10 @@ void CALLBACK ErrorCallback( GLenum 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();
|
||||
}
|
||||
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
* This program source code file is part of KICAD, a free EDA CAD application.
|
||||
*
|
||||
* Copyright (C) 2012 Torsten Hueter, torstenhtr <at> 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
|
||||
*
|
||||
|
@ -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 );
|
||||
}
|
||||
|
||||
|
@ -234,8 +234,7 @@ 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 );
|
||||
|
||||
|
|
|
@ -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 <maciej.suminski@cern.ch>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
|
@ -64,34 +66,46 @@ int checkGlError( const std::string& aInfo, bool aThrow )
|
|||
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.";
|
||||
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.";
|
||||
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;
|
||||
|
||||
case GL_OUT_OF_MEMORY:
|
||||
|
@ -125,8 +139,9 @@ 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 )
|
||||
{
|
||||
|
|
|
@ -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 <maciej.suminski@cern.ch>
|
||||
*
|
||||
* 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 )
|
||||
{
|
||||
}
|
||||
|
||||
|
|
|
@ -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 <maciej.suminski@cern.ch>
|
||||
*
|
||||
* 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 );
|
||||
|
|
|
@ -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 <maciej.suminski@cern.ch>
|
||||
*
|
||||
* 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() ) );
|
||||
|
|
Loading…
Reference in New Issue