2013-06-18 16:20:29 +02:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2013 CERN
|
|
|
|
* @author Maciej Suminski <maciej.suminski@cern.ch>
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, you may find one here:
|
|
|
|
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
|
|
|
* or you may search the http://www.gnu.org website for the version 2 license,
|
|
|
|
* or you may write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @file vbo_container.cpp
|
|
|
|
* @brief Class to store VBO_ITEMs.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <gal/opengl/vbo_container.h>
|
2013-07-17 18:49:38 +02:00
|
|
|
#include <algorithm>
|
|
|
|
#include <list>
|
2013-06-18 16:20:29 +02:00
|
|
|
#include <wx/log.h>
|
|
|
|
#ifdef __WXDEBUG__
|
|
|
|
#include <profile.h>
|
|
|
|
#endif /* __WXDEBUG__ */
|
|
|
|
|
|
|
|
using namespace KiGfx;
|
|
|
|
|
2013-07-05 14:01:33 +02:00
|
|
|
VBO_CONTAINER::VBO_CONTAINER( unsigned int aSize ) :
|
2013-07-17 18:49:38 +02:00
|
|
|
m_freeSpace( aSize ), m_currentSize( aSize ), m_initialSize( aSize ), m_transform( NULL ),
|
2013-07-01 13:20:48 +02:00
|
|
|
m_failed( false )
|
2013-06-18 16:20:29 +02:00
|
|
|
{
|
2013-06-19 10:50:46 +02:00
|
|
|
// By default no shader is used
|
|
|
|
m_shader[0] = 0;
|
|
|
|
|
2013-06-28 10:47:41 +02:00
|
|
|
m_vertices = static_cast<VBO_VERTEX*>( malloc( aSize * sizeof( VBO_VERTEX ) ) );
|
2013-06-18 16:20:29 +02:00
|
|
|
|
|
|
|
// In the beginning there is only free space
|
|
|
|
m_freeChunks.insert( Chunk( aSize, 0 ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
VBO_CONTAINER::~VBO_CONTAINER()
|
|
|
|
{
|
2013-06-28 10:47:41 +02:00
|
|
|
free( m_vertices );
|
2013-06-18 16:20:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-07-17 18:49:38 +02:00
|
|
|
void VBO_CONTAINER::StartItem( VBO_ITEM* aItem )
|
2013-06-18 16:20:29 +02:00
|
|
|
{
|
2013-07-17 18:49:38 +02:00
|
|
|
m_item = aItem;
|
|
|
|
m_itemSize = aItem->GetSize();
|
|
|
|
m_chunkSize = m_itemSize;
|
2013-06-18 16:20:29 +02:00
|
|
|
|
2013-07-17 18:49:38 +02:00
|
|
|
if( m_itemSize == 0 )
|
|
|
|
m_items.insert( m_item ); // The item was not stored before
|
|
|
|
else
|
|
|
|
m_chunkOffset = m_item->GetOffset();
|
2013-06-18 16:20:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void VBO_CONTAINER::EndItem()
|
|
|
|
{
|
2013-07-17 18:49:38 +02:00
|
|
|
if( m_itemSize < m_chunkSize )
|
2013-06-18 16:20:29 +02:00
|
|
|
{
|
2013-07-17 18:49:38 +02:00
|
|
|
// Add the not used memory back to the pool
|
|
|
|
m_freeChunks.insert( Chunk( m_chunkSize - m_itemSize, m_chunkOffset + m_itemSize ) );
|
|
|
|
m_freeSpace += ( m_chunkSize - m_itemSize );
|
2013-06-18 16:20:29 +02:00
|
|
|
}
|
|
|
|
|
2013-07-17 18:49:38 +02:00
|
|
|
m_item = NULL;
|
2013-06-18 16:20:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-07-17 18:49:38 +02:00
|
|
|
void VBO_CONTAINER::Add( const VBO_VERTEX* aVertex, unsigned int aSize )
|
2013-06-18 16:20:29 +02:00
|
|
|
{
|
2013-07-17 18:49:38 +02:00
|
|
|
// Pointer to the vertex that we are currently adding
|
|
|
|
VBO_VERTEX* vertexPtr = allocate( aSize );
|
2013-06-18 16:20:29 +02:00
|
|
|
|
2013-07-17 18:49:38 +02:00
|
|
|
if( vertexPtr == NULL )
|
2013-07-01 13:20:48 +02:00
|
|
|
return;
|
|
|
|
|
2013-06-19 10:50:46 +02:00
|
|
|
for( unsigned int i = 0; i < aSize; ++i )
|
|
|
|
{
|
|
|
|
// Modify the vertex according to the currently used transformations
|
|
|
|
if( m_transform != NULL )
|
|
|
|
{
|
|
|
|
// Apply transformations
|
|
|
|
glm::vec4 vertex( aVertex[i].x, aVertex[i].y, aVertex[i].z, 1.0f );
|
|
|
|
vertex = *m_transform * vertex;
|
|
|
|
|
|
|
|
// Replace only coordinates, leave color as it is
|
|
|
|
vertexPtr->x = vertex.x;
|
|
|
|
vertexPtr->y = vertex.y;
|
|
|
|
vertexPtr->z = vertex.z;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Simply copy coordinates
|
|
|
|
vertexPtr->x = aVertex[i].x;
|
|
|
|
vertexPtr->y = aVertex[i].y;
|
|
|
|
vertexPtr->z = aVertex[i].z;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Apply currently used color
|
|
|
|
vertexPtr->r = m_color[0];
|
|
|
|
vertexPtr->g = m_color[1];
|
|
|
|
vertexPtr->b = m_color[2];
|
|
|
|
vertexPtr->a = m_color[3];
|
|
|
|
|
|
|
|
// Apply currently used shader
|
2013-06-20 16:37:21 +02:00
|
|
|
for( unsigned int j = 0; j < VBO_ITEM::ShaderStride; ++j )
|
2013-06-19 10:50:46 +02:00
|
|
|
{
|
2013-06-20 16:37:21 +02:00
|
|
|
vertexPtr->shader[j] = m_shader[j];
|
2013-06-19 10:50:46 +02:00
|
|
|
}
|
2013-07-17 18:49:38 +02:00
|
|
|
|
|
|
|
vertexPtr++;
|
2013-06-19 10:50:46 +02:00
|
|
|
}
|
|
|
|
|
2013-06-18 16:20:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-07-05 14:01:33 +02:00
|
|
|
void VBO_CONTAINER::Clear()
|
|
|
|
{
|
|
|
|
// Change size to the default one
|
|
|
|
m_vertices = static_cast<VBO_VERTEX*>( realloc( m_vertices,
|
2013-07-17 18:49:38 +02:00
|
|
|
m_initialSize * sizeof( VBO_VERTEX ) ) );
|
|
|
|
|
|
|
|
// Set the size of all the stored VERTEX_ITEMs to 0, so it is clear that they are not held
|
|
|
|
// in the container anymore
|
|
|
|
Items::iterator it;
|
|
|
|
for( it = m_items.begin(); it != m_items.end(); ++it )
|
|
|
|
{
|
|
|
|
( *it )->setSize( 0 );
|
|
|
|
}
|
|
|
|
m_items.clear();
|
2013-07-05 14:01:33 +02:00
|
|
|
|
|
|
|
// Reset state variables
|
|
|
|
m_transform = NULL;
|
|
|
|
m_failed = false;
|
|
|
|
|
|
|
|
// By default no shader is used
|
|
|
|
m_shader[0] = 0;
|
|
|
|
|
|
|
|
// In the beginning there is only free space
|
2013-07-17 18:49:38 +02:00
|
|
|
m_freeSpace = m_initialSize;
|
|
|
|
m_currentSize = m_initialSize;
|
|
|
|
m_freeChunks.clear();
|
2013-07-05 14:01:33 +02:00
|
|
|
m_freeChunks.insert( Chunk( m_freeSpace, 0 ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-07-17 18:49:38 +02:00
|
|
|
void VBO_CONTAINER::Free( VBO_ITEM* aItem )
|
|
|
|
{
|
|
|
|
freeItem( aItem );
|
|
|
|
|
|
|
|
// Dynamic memory freeing, there is no point in holding
|
|
|
|
// a large amount of memory when there is no use for it
|
|
|
|
if( m_freeSpace > ( m_currentSize / 2 ) && m_currentSize > defaultInitSize )
|
|
|
|
{
|
|
|
|
resizeContainer( m_currentSize / 2 );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-06-18 16:20:29 +02:00
|
|
|
VBO_VERTEX* VBO_CONTAINER::GetAllVertices() const
|
|
|
|
{
|
|
|
|
return m_vertices;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-07-17 18:49:38 +02:00
|
|
|
VBO_VERTEX* VBO_CONTAINER::GetVertices( const VBO_ITEM* aItem ) const
|
2013-06-18 16:20:29 +02:00
|
|
|
{
|
2013-07-17 18:49:38 +02:00
|
|
|
int offset = aItem->GetOffset();
|
2013-06-18 16:20:29 +02:00
|
|
|
|
|
|
|
return &m_vertices[offset];
|
|
|
|
}
|
|
|
|
|
2013-07-17 18:49:38 +02:00
|
|
|
VBO_VERTEX* VBO_CONTAINER::allocate( unsigned int aSize )
|
|
|
|
{
|
|
|
|
wxASSERT( m_item != NULL );
|
|
|
|
|
|
|
|
if( m_failed )
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
if( m_itemSize + aSize > m_chunkSize )
|
|
|
|
{
|
|
|
|
// There is not enough space in the currently reserved chunk, so we have to resize it
|
|
|
|
|
|
|
|
// Reserve a bigger memory chunk for the current item
|
|
|
|
m_chunkSize = std::max( ( 2 * m_itemSize ) + aSize, (unsigned) 3 );
|
|
|
|
// Save the current size before reallocating
|
|
|
|
m_chunkOffset = reallocate( m_chunkSize );
|
|
|
|
|
|
|
|
if( m_chunkOffset > m_currentSize )
|
|
|
|
{
|
|
|
|
m_failed = true;
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
VBO_VERTEX* reserved = &m_vertices[m_chunkOffset + m_itemSize];
|
|
|
|
m_itemSize += aSize;
|
|
|
|
m_item->setSize( m_itemSize );
|
|
|
|
|
|
|
|
return reserved;
|
|
|
|
}
|
|
|
|
|
2013-06-18 16:20:29 +02:00
|
|
|
|
2013-07-17 18:49:38 +02:00
|
|
|
unsigned int VBO_CONTAINER::reallocate( unsigned int aSize )
|
2013-06-18 16:20:29 +02:00
|
|
|
{
|
|
|
|
// Is there enough space to store vertices?
|
|
|
|
if( m_freeSpace < aSize )
|
|
|
|
{
|
|
|
|
bool result;
|
|
|
|
|
|
|
|
// Would it be enough to double the current space?
|
|
|
|
if( aSize < m_freeSpace + m_currentSize )
|
|
|
|
{
|
|
|
|
// Yes: exponential growing
|
|
|
|
result = resizeContainer( m_currentSize * 2 );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// No: grow to the nearest bigger power of 2
|
|
|
|
result = resizeContainer( getPowerOf2( m_currentSize * 2 + aSize ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
if( !result )
|
|
|
|
return UINT_MAX;
|
|
|
|
}
|
|
|
|
|
2013-07-17 18:49:38 +02:00
|
|
|
// Look for the free space of at least given size
|
|
|
|
FreeChunkMap::iterator newChunk = m_freeChunks.lower_bound( aSize );
|
2013-06-18 16:20:29 +02:00
|
|
|
|
2013-07-17 18:49:38 +02:00
|
|
|
if( newChunk == m_freeChunks.end() )
|
2013-06-18 16:20:29 +02:00
|
|
|
{
|
2013-07-17 18:49:38 +02:00
|
|
|
// In the case when there is enough space to store the vertices,
|
|
|
|
// but the free space is not continous we should defragment the container
|
2013-06-18 16:20:29 +02:00
|
|
|
if( !defragment() )
|
2013-06-20 13:16:12 +02:00
|
|
|
return UINT_MAX;
|
2013-07-17 18:49:38 +02:00
|
|
|
|
|
|
|
// Update the current offset
|
|
|
|
m_chunkOffset = m_item->GetOffset();
|
2013-06-18 16:20:29 +02:00
|
|
|
|
|
|
|
// We can take the first free chunk, as there is only one after defragmentation
|
|
|
|
// and we can be sure that it provides enough space to store the object
|
2013-07-17 18:49:38 +02:00
|
|
|
newChunk = m_freeChunks.begin();
|
2013-06-18 16:20:29 +02:00
|
|
|
}
|
|
|
|
|
2013-07-17 18:49:38 +02:00
|
|
|
// Parameters of the allocated cuhnk
|
|
|
|
unsigned int chunkSize = newChunk->first;
|
|
|
|
unsigned int chunkOffset = newChunk->second;
|
2013-06-18 16:20:29 +02:00
|
|
|
|
|
|
|
wxASSERT( chunkSize >= aSize );
|
2013-07-17 18:49:38 +02:00
|
|
|
wxASSERT( chunkOffset < m_currentSize );
|
|
|
|
|
|
|
|
// Check if the item was previously stored in the container
|
|
|
|
if( m_itemSize > 0 )
|
|
|
|
{
|
|
|
|
// The item was reallocated, so we have to copy all the old data to the new place
|
|
|
|
memcpy( &m_vertices[chunkOffset], &m_vertices[m_chunkOffset],
|
|
|
|
m_itemSize * VBO_ITEM::VertByteSize );
|
|
|
|
|
|
|
|
// Free the space previously used by the chunk
|
|
|
|
m_freeChunks.insert( Chunk( m_itemSize, m_chunkOffset ) );
|
|
|
|
m_freeSpace += m_itemSize;
|
|
|
|
}
|
|
|
|
// Remove the allocated chunk from the free space pool
|
|
|
|
m_freeChunks.erase( newChunk );
|
|
|
|
m_freeSpace -= chunkSize;
|
2013-06-18 16:20:29 +02:00
|
|
|
|
|
|
|
// If there is some space left, return it to the pool - add an entry for it
|
|
|
|
if( chunkSize > aSize )
|
|
|
|
{
|
|
|
|
m_freeChunks.insert( Chunk( chunkSize - aSize, chunkOffset + aSize ) );
|
2013-07-17 18:49:38 +02:00
|
|
|
m_freeSpace += chunkSize - aSize;
|
2013-06-18 16:20:29 +02:00
|
|
|
}
|
|
|
|
|
2013-07-17 18:49:38 +02:00
|
|
|
m_item->setOffset( chunkOffset );
|
2013-06-18 16:20:29 +02:00
|
|
|
|
|
|
|
return chunkOffset;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool VBO_CONTAINER::defragment( VBO_VERTEX* aTarget )
|
|
|
|
{
|
|
|
|
if( aTarget == NULL )
|
|
|
|
{
|
2013-07-17 18:49:38 +02:00
|
|
|
// No target was specified, so we have to reallocate our own space
|
2013-06-28 10:47:41 +02:00
|
|
|
aTarget = static_cast<VBO_VERTEX*>( malloc( m_currentSize * sizeof( VBO_VERTEX ) ) );
|
2013-06-18 16:20:29 +02:00
|
|
|
if( aTarget == NULL )
|
|
|
|
{
|
|
|
|
wxLogError( wxT( "Run out of memory" ) );
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int newOffset = 0;
|
2013-07-17 18:49:38 +02:00
|
|
|
Items::iterator it, it_end;
|
|
|
|
for( it = m_items.begin(), it_end = m_items.end(); it != it_end; ++it )
|
2013-06-18 16:20:29 +02:00
|
|
|
{
|
2013-07-17 18:49:38 +02:00
|
|
|
VBO_ITEM* item = *it;
|
|
|
|
int itemOffset = item->GetOffset();
|
|
|
|
int itemSize = item->GetSize();
|
2013-06-18 16:20:29 +02:00
|
|
|
|
|
|
|
// Move an item to the new container
|
|
|
|
memcpy( &aTarget[newOffset], &m_vertices[itemOffset], itemSize * VBO_ITEM::VertByteSize );
|
|
|
|
|
2013-07-17 18:49:38 +02:00
|
|
|
// Update its offset
|
|
|
|
item->setOffset( newOffset );
|
2013-06-18 16:20:29 +02:00
|
|
|
|
|
|
|
// Move to the next free space
|
|
|
|
newOffset += itemSize;
|
|
|
|
}
|
|
|
|
|
2013-06-28 10:47:41 +02:00
|
|
|
free( m_vertices );
|
2013-06-18 16:20:29 +02:00
|
|
|
m_vertices = aTarget;
|
|
|
|
|
|
|
|
// Now there is only one big chunk of free memory
|
|
|
|
m_freeChunks.clear();
|
2013-07-17 18:49:38 +02:00
|
|
|
m_freeChunks.insert( Chunk( m_freeSpace, reservedSpace() ) );
|
2013-06-18 16:20:29 +02:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-07-17 18:49:38 +02:00
|
|
|
void VBO_CONTAINER::mergeFreeChunks()
|
2013-06-18 16:20:29 +02:00
|
|
|
{
|
2013-07-17 18:49:38 +02:00
|
|
|
if( m_freeChunks.size() < 2 ) // There are no chunks that can be merged
|
|
|
|
return;
|
2013-06-18 16:20:29 +02:00
|
|
|
|
2013-07-17 18:49:38 +02:00
|
|
|
// Reversed free chunks map - this one stores chunk size with its offset as the key
|
|
|
|
std::list<Chunk> freeChunks;
|
2013-06-18 16:20:29 +02:00
|
|
|
|
2013-07-17 18:49:38 +02:00
|
|
|
FreeChunkMap::const_iterator it, it_end;
|
|
|
|
for( it = m_freeChunks.begin(), it_end = m_freeChunks.end(); it != it_end; ++it )
|
|
|
|
{
|
|
|
|
freeChunks.push_back( std::make_pair( it->second, it->first ) );
|
|
|
|
}
|
|
|
|
m_freeChunks.clear();
|
|
|
|
freeChunks.sort();
|
2013-06-18 16:20:29 +02:00
|
|
|
|
2013-07-17 18:49:38 +02:00
|
|
|
std::list<Chunk>::const_iterator itf, itf_end;
|
|
|
|
unsigned int offset = freeChunks.front().first;
|
|
|
|
unsigned int size = freeChunks.front().second;
|
|
|
|
freeChunks.pop_front();
|
|
|
|
for( itf = freeChunks.begin(), itf_end = freeChunks.end(); itf != itf_end; ++itf )
|
|
|
|
{
|
|
|
|
if( itf->first == offset + size )
|
|
|
|
{
|
|
|
|
// These chunks can be merged, so just increase the current chunk size and go on
|
|
|
|
size += itf->second;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// These chunks cannot be merged
|
|
|
|
// So store the previous one
|
|
|
|
m_freeChunks.insert( std::make_pair( size, offset ) );
|
|
|
|
// and let's check the next chunk
|
|
|
|
offset = itf->first;
|
|
|
|
size = itf->second;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Add the last one
|
|
|
|
m_freeChunks.insert( std::make_pair( size, offset ) );
|
2013-06-18 16:20:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool VBO_CONTAINER::resizeContainer( unsigned int aNewSize )
|
|
|
|
{
|
2013-07-01 13:20:48 +02:00
|
|
|
VBO_VERTEX* newContainer;
|
|
|
|
|
2013-06-18 16:20:29 +02:00
|
|
|
if( aNewSize < m_currentSize )
|
|
|
|
{
|
2013-07-17 18:49:38 +02:00
|
|
|
// Shrinking container
|
2013-06-18 16:20:29 +02:00
|
|
|
// Sanity check, no shrinking if we cannot fit all the data
|
2013-07-17 18:49:38 +02:00
|
|
|
if( reservedSpace() > aNewSize )
|
2013-06-18 16:20:29 +02:00
|
|
|
return false;
|
|
|
|
|
2013-07-01 13:20:48 +02:00
|
|
|
newContainer = static_cast<VBO_VERTEX*>( malloc( aNewSize * sizeof( VBO_VERTEX ) ) );
|
|
|
|
if( newContainer == NULL )
|
|
|
|
{
|
|
|
|
wxLogError( wxT( "Run out of memory" ) );
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Defragment directly to the new, smaller container
|
|
|
|
defragment( newContainer );
|
2013-07-17 18:49:38 +02:00
|
|
|
|
|
|
|
// We have to correct freeChunks after defragmentation
|
|
|
|
m_freeChunks.clear();
|
|
|
|
m_freeChunks.insert( Chunk( aNewSize - reservedSpace(), reservedSpace() ) );
|
2013-06-18 16:20:29 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-07-17 18:49:38 +02:00
|
|
|
// Enlarging container
|
2013-07-01 13:20:48 +02:00
|
|
|
newContainer = static_cast<VBO_VERTEX*>( realloc( m_vertices, aNewSize * sizeof( VBO_VERTEX ) ) );
|
|
|
|
if( newContainer == NULL )
|
|
|
|
{
|
|
|
|
wxLogError( wxT( "Run out of memory" ) );
|
|
|
|
return false;
|
|
|
|
}
|
2013-06-18 16:20:29 +02:00
|
|
|
|
2013-07-17 18:49:38 +02:00
|
|
|
// Add an entry for the new memory chunk at the end of the container
|
|
|
|
m_freeChunks.insert( Chunk( aNewSize - m_currentSize, m_currentSize ) );
|
2013-06-18 16:20:29 +02:00
|
|
|
}
|
|
|
|
|
2013-07-17 18:49:38 +02:00
|
|
|
m_vertices = newContainer;
|
2013-06-18 16:20:29 +02:00
|
|
|
|
|
|
|
m_freeSpace += ( aNewSize - m_currentSize );
|
|
|
|
m_currentSize = aNewSize;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
2013-07-17 18:49:38 +02:00
|
|
|
|
|
|
|
|
|
|
|
void VBO_CONTAINER::freeItem( VBO_ITEM* aItem )
|
|
|
|
{
|
|
|
|
int size = aItem->GetSize();
|
|
|
|
int offset = aItem->GetOffset();
|
|
|
|
|
|
|
|
m_freeChunks.insert( Chunk( size, offset ) );
|
|
|
|
m_freeSpace += size;
|
|
|
|
m_items.erase( aItem );
|
|
|
|
|
|
|
|
// Item size is set to 0, so it means that it is not stored in the container
|
|
|
|
aItem->setSize( 0 );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void VBO_CONTAINER::test() const
|
|
|
|
{
|
|
|
|
unsigned int freeSpace = 0;
|
|
|
|
FreeChunkMap::const_iterator it, it_end;
|
|
|
|
|
|
|
|
// Check if the amount of free memory stored as chunks is the same as reported by m_freeSpace
|
|
|
|
for( it = m_freeChunks.begin(), it_end = m_freeChunks.end(); it != it_end; ++it )
|
|
|
|
freeSpace += it->first;
|
|
|
|
|
|
|
|
wxASSERT( freeSpace == m_freeSpace );
|
|
|
|
}
|