Upload correct amount of vertex data in CACHED_CONTAINER_RAM
Previous implementation uploaded only vertices with indices less or equal to the number of stored vertices, which is invalid when the container become fragmented. Fixes: lp:1712887 * https://bugs.launchpad.net/kicad/+bug/1712887
This commit is contained in:
parent
342bb2bf78
commit
8c7175b00d
|
@ -45,7 +45,7 @@
|
||||||
using namespace KIGFX;
|
using namespace KIGFX;
|
||||||
|
|
||||||
CACHED_CONTAINER::CACHED_CONTAINER( unsigned int aSize ) :
|
CACHED_CONTAINER::CACHED_CONTAINER( unsigned int aSize ) :
|
||||||
VERTEX_CONTAINER( aSize ), m_item( NULL ), m_chunkSize( 0 ), m_chunkOffset( 0 )
|
VERTEX_CONTAINER( aSize ), m_item( NULL ), m_chunkSize( 0 ), m_chunkOffset( 0 ), m_maxIndex( 0 )
|
||||||
{
|
{
|
||||||
// In the beginning there is only free space
|
// In the beginning there is only free space
|
||||||
m_freeChunks.insert( std::make_pair( aSize, 0 ) );
|
m_freeChunks.insert( std::make_pair( aSize, 0 ) );
|
||||||
|
@ -84,6 +84,8 @@ void CACHED_CONTAINER::FinishItem()
|
||||||
// Add the not used memory back to the pool
|
// Add the not used memory back to the pool
|
||||||
addFreeChunk( itemOffset + itemSize, m_chunkSize - itemSize );
|
addFreeChunk( itemOffset + itemSize, m_chunkSize - itemSize );
|
||||||
// mergeFreeChunks(); // veery slow and buggy
|
// mergeFreeChunks(); // veery slow and buggy
|
||||||
|
|
||||||
|
m_maxIndex = std::max( itemOffset + itemSize, m_maxIndex );
|
||||||
}
|
}
|
||||||
|
|
||||||
if( itemSize > 0 )
|
if( itemSize > 0 )
|
||||||
|
@ -189,6 +191,7 @@ void CACHED_CONTAINER::Delete( VERTEX_ITEM* aItem )
|
||||||
void CACHED_CONTAINER::Clear()
|
void CACHED_CONTAINER::Clear()
|
||||||
{
|
{
|
||||||
m_freeSpace = m_currentSize;
|
m_freeSpace = m_currentSize;
|
||||||
|
m_maxIndex = 0;
|
||||||
m_failed = false;
|
m_failed = false;
|
||||||
|
|
||||||
// Set the size of all the stored VERTEX_ITEMs to 0, so it is clear that they are not held
|
// Set the size of all the stored VERTEX_ITEMs to 0, so it is clear that they are not held
|
||||||
|
@ -305,6 +308,8 @@ void CACHED_CONTAINER::defragment( VERTEX* aTarget )
|
||||||
m_item->setOffset( newOffset );
|
m_item->setOffset( newOffset );
|
||||||
m_chunkOffset = newOffset;
|
m_chunkOffset = newOffset;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
m_maxIndex = usedSpace();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -64,7 +64,7 @@ void CACHED_CONTAINER_RAM::Unmap()
|
||||||
// Upload vertices coordinates and shader types to GPU memory
|
// Upload vertices coordinates and shader types to GPU memory
|
||||||
glBindBuffer( GL_ARRAY_BUFFER, m_verticesBuffer );
|
glBindBuffer( GL_ARRAY_BUFFER, m_verticesBuffer );
|
||||||
checkGlError( "binding vertices buffer" );
|
checkGlError( "binding vertices buffer" );
|
||||||
glBufferData( GL_ARRAY_BUFFER, usedSpace() * VERTEX_SIZE, m_vertices, GL_STREAM_DRAW );
|
glBufferData( GL_ARRAY_BUFFER, m_maxIndex * VERTEX_SIZE, m_vertices, GL_STREAM_DRAW );
|
||||||
checkGlError( "transferring vertices" );
|
checkGlError( "transferring vertices" );
|
||||||
glBindBuffer( GL_ARRAY_BUFFER, 0 );
|
glBindBuffer( GL_ARRAY_BUFFER, 0 );
|
||||||
checkGlError( "unbinding vertices buffer" );
|
checkGlError( "unbinding vertices buffer" );
|
||||||
|
@ -110,6 +110,7 @@ bool CACHED_CONTAINER_RAM::defragmentResize( unsigned int aNewSize )
|
||||||
// Now there is only one big chunk of free memory
|
// Now there is only one big chunk of free memory
|
||||||
m_freeChunks.clear();
|
m_freeChunks.clear();
|
||||||
m_freeChunks.insert( std::make_pair( m_freeSpace, m_currentSize - m_freeSpace ) );
|
m_freeChunks.insert( std::make_pair( m_freeSpace, m_currentSize - m_freeSpace ) );
|
||||||
|
m_dirty = true;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -103,6 +103,9 @@ protected:
|
||||||
unsigned int m_chunkSize;
|
unsigned int m_chunkSize;
|
||||||
unsigned int m_chunkOffset;
|
unsigned int m_chunkOffset;
|
||||||
|
|
||||||
|
///> Maximal vertex index number stored in the container
|
||||||
|
unsigned int m_maxIndex;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Resizes the chunk that stores the current item to the given size. The current item has
|
* Resizes the chunk that stores the current item to the given size. The current item has
|
||||||
* its offset adjusted after the call, and the new chunk parameters are stored
|
* its offset adjusted after the call, and the new chunk parameters are stored
|
||||||
|
|
Loading…
Reference in New Issue