diff --git a/common/drawframe.cpp b/common/drawframe.cpp index f992f43d3d..eafdf65f41 100644 --- a/common/drawframe.cpp +++ b/common/drawframe.cpp @@ -947,7 +947,6 @@ void EDA_DRAW_FRAME::UseGalCanvas( bool aEnable ) if( aEnable && m_galCanvasActive ) { // When we switch between GAL based canvases, all we need is a refresh - view->RecacheAllItems( true ); m_galCanvas->Refresh(); } @@ -981,9 +980,6 @@ 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/drawpanel_gal.cpp b/common/drawpanel_gal.cpp index bd9fe02b44..0403d60dc6 100644 --- a/common/drawpanel_gal.cpp +++ b/common/drawpanel_gal.cpp @@ -71,7 +71,7 @@ EDA_DRAW_PANEL_GAL::EDA_DRAW_PANEL_GAL( wxWindow* aParentWindow, wxWindowID aWin m_view->SetGAL( m_gal ); // View uses layers to display EDA_ITEMs (item may be displayed on several layers, for example - // pad may be shown on pad, pad hole nad solder paste layers). There are usual copper layers + // pad may be shown on pad, pad hole and solder paste layers). There are usual copper layers // (eg. F.Cu, B.Cu, internal and so on) and layers for displaying objects such as texts, // silkscreen, pads, vias, etc. for( int i = 0; i < TOTAL_LAYER_COUNT; i++ ) @@ -154,7 +154,10 @@ void EDA_DRAW_PANEL_GAL::SwitchBackend( GalType aGalType, bool aUseShaders ) m_gal->ComputeWorldScreenMatrix(); if( m_view ) + { m_view->SetGAL( m_gal ); + m_view->RecacheAllItems( true ); + } wxSize size = GetClientSize(); m_gal->ResizeScreen( size.GetX(), size.GetY() ); diff --git a/common/gal/opengl/opengl_gal.cpp b/common/gal/opengl/opengl_gal.cpp index 45034592b2..bde328fdf6 100644 --- a/common/gal/opengl/opengl_gal.cpp +++ b/common/gal/opengl/opengl_gal.cpp @@ -52,7 +52,7 @@ OPENGL_GAL::OPENGL_GAL( wxWindow* aParent, wxEvtHandler* aMouseListener, wxEXPAND, aName ) { // Create the OpenGL-Context - glContext = new wxGLContext( this ); + glContext = new wxGLContext( this ); parentWindow = aParent; mouseListener = aMouseListener; paintListener = aPaintListener; @@ -68,11 +68,12 @@ OPENGL_GAL::OPENGL_GAL( wxWindow* aParent, wxEvtHandler* aMouseListener, isFrameBufferInitialized = false; isUseShader = isUseShaders; isShaderInitialized = false; - isGroupStarted = false; + isGrouping = false; shaderPath = "../../common/gal/opengl/shader/"; wxSize parentSize = aParent->GetSize(); isVboInitialized = false; + vboNeedsUpdate = false; curVboItem = NULL; vboSize = 0; @@ -110,13 +111,6 @@ OPENGL_GAL::~OPENGL_GAL() { glFlush(); - // Delete the stored display lists - for( std::deque::iterator group = displayListsGroup.begin(); - group != displayListsGroup.end(); group++ ) - { - glDeleteLists( *group, 1 ); - } - // Delete the buffers if( isFrameBufferInitialized ) { @@ -126,6 +120,12 @@ OPENGL_GAL::~OPENGL_GAL() if( isVboInitialized ) { + std::deque::iterator it, end; + for( it = vboItems.begin(), end = vboItems.end(); it != end; it++ ) + { + delete *it; + } + deleteVertexBufferObjects(); } @@ -514,8 +514,8 @@ void OPENGL_GAL::rebuildVbo() glBufferData( GL_ELEMENT_ARRAY_BUFFER, vboSize * VBO_ITEM::IndSize, indicesBuffer, GL_DYNAMIC_DRAW ); glBindBuffer( GL_ELEMENT_ARRAY_BUFFER, 0 ); - delete verticesBuffer; - delete indicesBuffer; + delete[] verticesBuffer; + delete[] indicesBuffer; vboNeedsUpdate = false; @@ -607,7 +607,7 @@ inline void OPENGL_GAL::drawLineQuad( const VECTOR2D& aStartPoint, const VECTOR2 // XXX Should be improved later. double scale = 0.5 * lineWidth / lineLength; double scale1pix = 0.5001 / worldScale / lineLength; - if( lineWidth * worldScale < 1.0002 && !isGroupStarted ) + if( lineWidth * worldScale < 1.0002 && !isGrouping ) { scale = scale1pix; } @@ -637,7 +637,7 @@ void OPENGL_GAL::DrawSegment( const VECTOR2D& aStartPoint, const VECTOR2D& aEndP VECTOR2D startEndVector = aEndPoint - aStartPoint; double lineAngle = atan2( startEndVector.y, startEndVector.x ); - if ( isGroupStarted ) + if ( isGrouping ) { // Angle of a line perpendicular to the segment being drawn double beta = ( M_PI / 2.0 ) - lineAngle; @@ -1464,7 +1464,7 @@ void OPENGL_GAL::Restore() int OPENGL_GAL::BeginGroup() { - isGroupStarted = true; + isGrouping = true; // There is a new group that is not in VBO yet vboNeedsUpdate = true; @@ -1482,17 +1482,25 @@ void OPENGL_GAL::EndGroup() { vboSize += curVboItem->GetSize(); - isGroupStarted = false; + isGrouping = false; } void OPENGL_GAL::DeleteGroup( int aGroupNumber ) { + if( aGroupNumber >= vboItems.size() ) + { + // This should not happen + wxLogDebug( wxT( "Tried to delete not existing group" ) ); + return; + } + std::deque::iterator it = vboItems.begin(); std::advance( it, aGroupNumber ); + //vboSize -= it->GetSize(); // FIXME? delete *it; - vboItems.erase( it ); + //vboItems.erase( it ); vboNeedsUpdate = true; } diff --git a/common/gal/opengl/vbo_item.cpp b/common/gal/opengl/vbo_item.cpp index f853a8cae0..ba6a27c147 100644 --- a/common/gal/opengl/vbo_item.cpp +++ b/common/gal/opengl/vbo_item.cpp @@ -46,6 +46,9 @@ VBO_ITEM::~VBO_ITEM() { if( m_vertices ) delete m_vertices; + + if( m_indices ) + delete m_indices; } @@ -76,7 +79,7 @@ void VBO_ITEM::PushVertex( const GLfloat* aVertex ) m_indices = newIndices; // Add the new vertex - newIndices[m_size] = m_offset + m_size; + m_indices[m_size] = m_offset + m_size; m_size++; m_isDirty = true; diff --git a/common/view/view.cpp b/common/view/view.cpp index 050481e5a6..9302fc1e6d 100644 --- a/common/view/view.cpp +++ b/common/view/view.cpp @@ -208,9 +208,9 @@ void VIEW::SetGAL( GAL* aGal ) if( m_painter ) m_painter->SetGAL( m_gal ); - // items need to be recached after changing GAL - //if( m_useGroups ) - //RecacheAllItems(); + // clear group numbers, so everything is going to be recached + if( m_useGroups ) + clearGroupCache(); // force the new GAL to display the current viewport. SetCenter( m_center ); @@ -387,7 +387,6 @@ struct VIEW::drawItem aItem->setGroup( currentLayer, group ); view->m_painter->Draw( static_cast( aItem ), currentLayer ); gal->EndGroup(); - //gal->DrawGroup( group ); } } else if( aItem->ViewIsVisible() ) @@ -460,20 +459,24 @@ struct VIEW::recacheItem void operator()( VIEW_ITEM* aItem ) { - //aItem->deleteGroups(); - /*int prevGroup = aItem->getGroup( layer ); - if( prevGroup != -1 ) + // Remove previously cached group + int prevGroup = aItem->getGroup( layer ); + if( prevGroup >= 0 ) { gal->DeleteGroup( prevGroup ); - }*/ + } if( immediately ) { int group = gal->BeginGroup(); - aItem->setGroup( layer, group ); view->m_painter->Draw( static_cast( aItem ), layer ); + aItem->setGroup( layer, group ); gal->EndGroup(); } + else + { + aItem->setGroup( layer, -1 ); + } } VIEW* view; @@ -565,12 +568,6 @@ struct VIEW::clearItemCache { if( aItem->storesGroups() ) { - std::vector groups = aItem->getAllGroups(); - for(std::vector::iterator i = groups.begin(); i != groups.end(); i++ ) - { - view->GetGAL()->DeleteGroup( *i ); - } - aItem->deleteGroups(); } } @@ -581,6 +578,9 @@ struct VIEW::clearItemCache void VIEW::clearGroupCache() { + if( !m_useGroups ) + return; + BOX2I r; r.SetMaximum(); @@ -596,22 +596,25 @@ void VIEW::clearGroupCache() void VIEW::RecacheAllItems( bool aImmediately ) { + if( !m_useGroups ) + return; + BOX2I r; r.SetMaximum(); - wxLogDebug( wxT( "RecacheAllItems::immediately: %u" ), aImmediately ); - - if( aImmediately ) + //if( aImmediately ) m_gal->BeginDrawing(); + wxLogDebug( wxT( "RecacheAllItems::immediately: %u" ), aImmediately ); + for( LayerMapIter i = m_layers.begin(); i != m_layers.end(); ++i ) { VIEW_LAYER* l = & ( ( *i ).second ); recacheItem visitor( this, m_gal, l->id, aImmediately ); l->items->Query( r, visitor ); - }; + } - if( aImmediately ) + //if( aImmediately ) m_gal->EndDrawing(); } diff --git a/include/gal/opengl/opengl_gal.h b/include/gal/opengl/opengl_gal.h index b18051a8d4..75941ecacf 100644 --- a/include/gal/opengl/opengl_gal.h +++ b/include/gal/opengl/opengl_gal.h @@ -339,7 +339,6 @@ private: GLuint displayListsArcs; ///< Arc display list GLuint displayListCircle; ///< Circle display list GLuint displayListSemiCircle; ///< Semi circle display list - std::deque displayListsGroup; ///< List of display lists used for groups // Vertex buffer objects related fields std::deque vboItems; ///< Stores informations about VBO objects @@ -382,7 +381,7 @@ private: bool isShaderInitialized; ///< Was the shader initialized? bool isShaderEnabled; ///< Are the shaders enabled? bool isUseShader; ///< Should the shaders be used? - bool isGroupStarted; ///< Was a group started? + bool isGrouping; ///< Was a group started? int currentShader; ///< ID of the shader currently in use std::string shaderPath; diff --git a/include/view/view.h b/include/view/view.h index bc30b28a59..45e7645671 100644 --- a/include/view/view.h +++ b/include/view/view.h @@ -355,14 +355,15 @@ private: ///* Sorts m_orderedLayers when layer rendering order has changed void sortLayers(); - ///* Clears cached GAL display lists + ///* Clears cached GAL group numbers (*ONLY* numbers stored in VIEW_ITEMs, not group objects + ///* used by GAL) void clearGroupCache(); /// Determines rendering order of layers. Used in display order sorting function. static bool compareRenderingOrder( VIEW_LAYER* i, VIEW_LAYER* j ) { return i->renderingOrder > j->renderingOrder; - }; + } /// Contains set of possible displayed layers and its properties LayerMap m_layers;