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 )
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 */
}
......@@ -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() );
......
......@@ -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<GLuint>::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<VBO_ITEM*>::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<VBO_ITEM*>::iterator it = vboItems.begin();
std::advance( it, aGroupNumber );
//vboSize -= it->GetSize(); // FIXME?
delete *it;
vboItems.erase( it );
//vboItems.erase( it );
vboNeedsUpdate = true;
}
......
......@@ -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;
......
......@@ -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<EDA_ITEM*>( 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<EDA_ITEM*>( 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<int> groups = aItem->getAllGroups();
for(std::vector<int>::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();
}
......@@ -339,7 +339,6 @@ private:
GLuint displayListsArcs; ///< Arc display list
GLuint displayListCircle; ///< 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
std::deque<VBO_ITEM*> 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;
......
......@@ -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;
......
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