Commit e8f33ac9 authored by Maciej Suminski's avatar Maciej Suminski

Fixed memleak, removed excessive recaching, still there is a problem with Cairo caching

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