Commit e9e4ed42 authored by Maciej Suminski's avatar Maciej Suminski

Improved recaching (all items when a board is loaded), still needs some fixing (mem leak).

parent 191cb40e
...@@ -941,17 +941,19 @@ void EDA_DRAW_FRAME::AdjustScrollBars( const wxPoint& aCenterPositionIU ) ...@@ -941,17 +941,19 @@ void EDA_DRAW_FRAME::AdjustScrollBars( const wxPoint& aCenterPositionIU )
void EDA_DRAW_FRAME::UseGalCanvas( bool aEnable ) void EDA_DRAW_FRAME::UseGalCanvas( bool aEnable )
{ {
#ifdef KICAD_GAL #ifdef KICAD_GAL
KiGfx::VIEW* view = m_galCanvas->GetView();
KiGfx::GAL* gal = m_galCanvas->GetGAL();
if( aEnable && m_galCanvasActive ) if( aEnable && m_galCanvasActive )
{ {
// When we switch between GAL based canvases, all we need is a refresh // When we switch between GAL based canvases, all we need is a refresh
view->RecacheAllItems( true );
m_galCanvas->Refresh(); m_galCanvas->Refresh();
} }
if( !( aEnable ^ m_galCanvasActive ) ) if( !( aEnable ^ m_galCanvasActive ) )
return; return;
KiGfx::VIEW* view = m_galCanvas->GetView();
KiGfx::GAL* gal = m_galCanvas->GetGAL();
double zoomFactor = gal->GetWorldScale() / gal->GetZoomFactor(); double zoomFactor = gal->GetWorldScale() / gal->GetZoomFactor();
// Display the same view after canvas switching // Display the same view after canvas switching
...@@ -979,6 +981,9 @@ void EDA_DRAW_FRAME::UseGalCanvas( bool aEnable ) ...@@ -979,6 +981,9 @@ void EDA_DRAW_FRAME::UseGalCanvas( bool aEnable )
m_auimgr.GetPane( wxT( "DrawFrameGal" ) ).Show( aEnable ); m_auimgr.GetPane( wxT( "DrawFrameGal" ) ).Show( aEnable );
m_auimgr.Update(); m_auimgr.Update();
if( aEnable )
view->RecacheAllItems( true );
m_galCanvasActive = aEnable; m_galCanvasActive = aEnable;
#endif /* KICAD_GAL */ #endif /* KICAD_GAL */
} }
...@@ -403,7 +403,10 @@ void OPENGL_GAL::BeginDrawing() ...@@ -403,7 +403,10 @@ void OPENGL_GAL::BeginDrawing()
SetFillColor( fillColor ); SetFillColor( fillColor );
SetStrokeColor( strokeColor ); SetStrokeColor( strokeColor );
isDeleteSavedPixels = true; isDeleteSavedPixels = true;
vboNeedsUpdate = false;
// If any of VBO items is dirty - recache everything
if( vboNeedsUpdate )
rebuildVbo();
} }
...@@ -455,13 +458,6 @@ void OPENGL_GAL::blitMainTexture( bool aIsClearFrameBuffer ) ...@@ -455,13 +458,6 @@ void OPENGL_GAL::blitMainTexture( bool aIsClearFrameBuffer )
void OPENGL_GAL::EndDrawing() void OPENGL_GAL::EndDrawing()
{ {
// If any of VBO items is dirty - recache everything
if( vboNeedsUpdate )
{
rebuildVbo();
vboNeedsUpdate = false;
}
// Draw the remaining contents, blit the main texture to the screen, swap the buffers // Draw the remaining contents, blit the main texture to the screen, swap the buffers
glFlush(); glFlush();
blitMainTexture( true ); blitMainTexture( true );
...@@ -521,6 +517,8 @@ void OPENGL_GAL::rebuildVbo() ...@@ -521,6 +517,8 @@ void OPENGL_GAL::rebuildVbo()
delete verticesBuffer; delete verticesBuffer;
delete indicesBuffer; delete indicesBuffer;
vboNeedsUpdate = false;
#ifdef __WXDEBUG__ #ifdef __WXDEBUG__
prof_end( &totalTime ); prof_end( &totalTime );
...@@ -1484,9 +1482,6 @@ void OPENGL_GAL::EndGroup() ...@@ -1484,9 +1482,6 @@ void OPENGL_GAL::EndGroup()
{ {
vboSize += curVboItem->GetSize(); vboSize += curVboItem->GetSize();
// TODO this has to be removed in final version
rebuildVbo();
isGroupStarted = false; isGroupStarted = false;
} }
......
...@@ -209,8 +209,8 @@ void VIEW::SetGAL( GAL* aGal ) ...@@ -209,8 +209,8 @@ void VIEW::SetGAL( GAL* aGal )
m_painter->SetGAL( m_gal ); m_painter->SetGAL( m_gal );
// items need to be recached after changing GAL // items need to be recached after changing GAL
if( m_useGroups ) //if( m_useGroups )
recacheAllItems(); //RecacheAllItems();
// force the new GAL to display the current viewport. // force the new GAL to display the current viewport.
SetCenter( m_center ); SetCenter( m_center );
...@@ -387,7 +387,7 @@ struct VIEW::drawItem ...@@ -387,7 +387,7 @@ struct VIEW::drawItem
aItem->setGroup( currentLayer, group ); aItem->setGroup( currentLayer, group );
view->m_painter->Draw( static_cast<EDA_ITEM*>( aItem ), currentLayer ); view->m_painter->Draw( static_cast<EDA_ITEM*>( aItem ), currentLayer );
gal->EndGroup(); gal->EndGroup();
gal->DrawGroup( group ); //gal->DrawGroup( group );
} }
} }
else if( aItem->ViewIsVisible() ) else if( aItem->ViewIsVisible() )
...@@ -453,10 +453,33 @@ struct VIEW::unlinkItem ...@@ -453,10 +453,33 @@ struct VIEW::unlinkItem
struct VIEW::recacheItem struct VIEW::recacheItem
{ {
recacheItem( VIEW* aView, GAL* aGal, int aLayer, bool aImmediately ) :
view( aView ), gal( aGal ), layer( aLayer ), immediately( aImmediately )
{
}
void operator()( VIEW_ITEM* aItem ) void operator()( VIEW_ITEM* aItem )
{ {
aItem->deleteGroups(); //aItem->deleteGroups();
/*int prevGroup = aItem->getGroup( layer );
if( prevGroup != -1 )
{
gal->DeleteGroup( prevGroup );
}*/
if( immediately )
{
int group = gal->BeginGroup();
aItem->setGroup( layer, group );
view->m_painter->Draw( static_cast<EDA_ITEM*>( aItem ), layer );
gal->EndGroup();
}
} }
VIEW* view;
GAL* gal;
int layer;
bool immediately;
}; };
...@@ -571,16 +594,24 @@ void VIEW::clearGroupCache() ...@@ -571,16 +594,24 @@ void VIEW::clearGroupCache()
} }
void VIEW::recacheAllItems() void VIEW::RecacheAllItems( bool aImmediately )
{ {
BOX2I r; BOX2I r;
r.SetMaximum(); r.SetMaximum();
wxLogDebug( wxT( "RecacheAllItems::immediately: %u" ), aImmediately );
if( aImmediately )
m_gal->BeginDrawing();
for( LayerMapIter i = m_layers.begin(); i != m_layers.end(); ++i ) for( LayerMapIter i = m_layers.begin(); i != m_layers.end(); ++i )
{ {
VIEW_LAYER* l = & ( ( *i ).second ); VIEW_LAYER* l = & ( ( *i ).second );
recacheItem visitor; recacheItem visitor( this, m_gal, l->id, aImmediately );
l->items->Query( r, visitor ); l->items->Query( r, visitor );
}; };
if( aImmediately )
m_gal->EndDrawing();
} }
...@@ -294,6 +294,14 @@ public: ...@@ -294,6 +294,14 @@ public:
*/ */
void PartialRedraw(); void PartialRedraw();
/**
* Function RecacheAllItems()
* Rebuilds GAL display lists.
* @param aForceNow decides if every item should be instantly recached. Otherwise items are
* going to be recached when they become visible.
*/
void RecacheAllItems( bool aForceNow = false );
/** /**
* Function IsDynamic() * Function IsDynamic()
* Tells if the VIEW is dynamic (ie. can be changed, for example displaying PCBs in a window) * Tells if the VIEW is dynamic (ie. can be changed, for example displaying PCBs in a window)
...@@ -350,9 +358,6 @@ private: ...@@ -350,9 +358,6 @@ private:
///* Clears cached GAL display lists ///* Clears cached GAL display lists
void clearGroupCache(); void clearGroupCache();
///* Rebuilds GAL display lists
void recacheAllItems();
/// Determines rendering order of layers. Used in display order sorting function. /// Determines rendering order of layers. Used in display order sorting function.
static bool compareRenderingOrder( VIEW_LAYER* i, VIEW_LAYER* j ) static bool compareRenderingOrder( VIEW_LAYER* i, VIEW_LAYER* j )
{ {
......
...@@ -243,7 +243,10 @@ void PCB_BASE_FRAME::SetBoard( BOARD* aBoard ) ...@@ -243,7 +243,10 @@ void PCB_BASE_FRAME::SetBoard( BOARD* aBoard )
view->SetTopLayer( m_Pcb->GetLayer() ); view->SetTopLayer( m_Pcb->GetLayer() );
if( m_galCanvasActive ) if( m_galCanvasActive )
{
view->RecacheAllItems( true );
m_galCanvas->Refresh(); m_galCanvas->Refresh();
}
} }
#endif #endif
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment