diff --git a/common/drawframe.cpp b/common/drawframe.cpp index f3b8263f33..f992f43d3d 100644 --- a/common/drawframe.cpp +++ b/common/drawframe.cpp @@ -941,17 +941,19 @@ void EDA_DRAW_FRAME::AdjustScrollBars( const wxPoint& aCenterPositionIU ) void EDA_DRAW_FRAME::UseGalCanvas( bool aEnable ) { #ifdef KICAD_GAL + KiGfx::VIEW* view = m_galCanvas->GetView(); + KiGfx::GAL* gal = m_galCanvas->GetGAL(); + if( aEnable && m_galCanvasActive ) { // When we switch between GAL based canvases, all we need is a refresh + view->RecacheAllItems( true ); m_galCanvas->Refresh(); } if( !( aEnable ^ m_galCanvasActive ) ) return; - KiGfx::VIEW* view = m_galCanvas->GetView(); - KiGfx::GAL* gal = m_galCanvas->GetGAL(); double zoomFactor = gal->GetWorldScale() / gal->GetZoomFactor(); // Display the same view after canvas switching @@ -979,6 +981,9 @@ void EDA_DRAW_FRAME::UseGalCanvas( bool aEnable ) m_auimgr.GetPane( wxT( "DrawFrameGal" ) ).Show( aEnable ); m_auimgr.Update(); + if( aEnable ) + view->RecacheAllItems( true ); + m_galCanvasActive = aEnable; #endif /* KICAD_GAL */ } diff --git a/common/gal/opengl/opengl_gal.cpp b/common/gal/opengl/opengl_gal.cpp index 6ae5d37f1d..45034592b2 100644 --- a/common/gal/opengl/opengl_gal.cpp +++ b/common/gal/opengl/opengl_gal.cpp @@ -403,7 +403,10 @@ void OPENGL_GAL::BeginDrawing() SetFillColor( fillColor ); SetStrokeColor( strokeColor ); 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 ) 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 glFlush(); blitMainTexture( true ); @@ -521,6 +517,8 @@ void OPENGL_GAL::rebuildVbo() delete verticesBuffer; delete indicesBuffer; + vboNeedsUpdate = false; + #ifdef __WXDEBUG__ prof_end( &totalTime ); @@ -1484,9 +1482,6 @@ void OPENGL_GAL::EndGroup() { vboSize += curVboItem->GetSize(); - // TODO this has to be removed in final version - rebuildVbo(); - isGroupStarted = false; } diff --git a/common/view/view.cpp b/common/view/view.cpp index a81e117e6b..050481e5a6 100644 --- a/common/view/view.cpp +++ b/common/view/view.cpp @@ -209,8 +209,8 @@ void VIEW::SetGAL( GAL* aGal ) m_painter->SetGAL( m_gal ); // items need to be recached after changing GAL - if( m_useGroups ) - recacheAllItems(); + //if( m_useGroups ) + //RecacheAllItems(); // force the new GAL to display the current viewport. SetCenter( m_center ); @@ -387,7 +387,7 @@ struct VIEW::drawItem aItem->setGroup( currentLayer, group ); view->m_painter->Draw( static_cast( aItem ), currentLayer ); gal->EndGroup(); - gal->DrawGroup( group ); + //gal->DrawGroup( group ); } } else if( aItem->ViewIsVisible() ) @@ -453,10 +453,33 @@ struct VIEW::unlinkItem 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 ) { - 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( aItem ), layer ); + gal->EndGroup(); + } } + + VIEW* view; + GAL* gal; + int layer; + bool immediately; }; @@ -571,16 +594,24 @@ void VIEW::clearGroupCache() } -void VIEW::recacheAllItems() +void VIEW::RecacheAllItems( bool aImmediately ) { BOX2I r; r.SetMaximum(); + wxLogDebug( wxT( "RecacheAllItems::immediately: %u" ), aImmediately ); + + if( aImmediately ) + m_gal->BeginDrawing(); + for( LayerMapIter i = m_layers.begin(); i != m_layers.end(); ++i ) { VIEW_LAYER* l = & ( ( *i ).second ); - recacheItem visitor; + recacheItem visitor( this, m_gal, l->id, aImmediately ); l->items->Query( r, visitor ); }; + + if( aImmediately ) + m_gal->EndDrawing(); } diff --git a/include/view/view.h b/include/view/view.h index 4cf09cc5c2..bc30b28a59 100644 --- a/include/view/view.h +++ b/include/view/view.h @@ -294,6 +294,14 @@ public: */ 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() * Tells if the VIEW is dynamic (ie. can be changed, for example displaying PCBs in a window) @@ -350,9 +358,6 @@ private: ///* Clears cached GAL display lists void clearGroupCache(); - ///* Rebuilds GAL display lists - void recacheAllItems(); - /// Determines rendering order of layers. Used in display order sorting function. static bool compareRenderingOrder( VIEW_LAYER* i, VIEW_LAYER* j ) { diff --git a/pcbnew/basepcbframe.cpp b/pcbnew/basepcbframe.cpp index 8de801efa9..e85b87db33 100644 --- a/pcbnew/basepcbframe.cpp +++ b/pcbnew/basepcbframe.cpp @@ -243,7 +243,10 @@ void PCB_BASE_FRAME::SetBoard( BOARD* aBoard ) view->SetTopLayer( m_Pcb->GetLayer() ); if( m_galCanvasActive ) + { + view->RecacheAllItems( true ); m_galCanvas->Refresh(); + } } #endif }