A few more fixes related to the previous commit.
This commit is contained in:
parent
6e881f51fd
commit
3e3ecccb2b
|
@ -413,7 +413,7 @@ bool CACHED_CONTAINER::defragmentResize( unsigned int aNewSize )
|
||||||
assert( IsMapped() );
|
assert( IsMapped() );
|
||||||
|
|
||||||
wxLogTrace( "GAL_CACHED_CONTAINER",
|
wxLogTrace( "GAL_CACHED_CONTAINER",
|
||||||
wxT( "Resizing container from %d to %d" ), m_currentSize, aNewSize );
|
wxT( "Resizing & defragmenting container from %d to %d" ), m_currentSize, aNewSize );
|
||||||
|
|
||||||
// No shrinking if we cannot fit all the data
|
// No shrinking if we cannot fit all the data
|
||||||
if( aNewSize < m_currentSize && usedSpace() > aNewSize )
|
if( aNewSize < m_currentSize && usedSpace() > aNewSize )
|
||||||
|
@ -426,11 +426,22 @@ bool CACHED_CONTAINER::defragmentResize( unsigned int aNewSize )
|
||||||
|
|
||||||
GLuint newBuffer;
|
GLuint newBuffer;
|
||||||
|
|
||||||
|
// glCopyBufferSubData requires a buffer to be unmapped
|
||||||
|
glUnmapBuffer( GL_ARRAY_BUFFER );
|
||||||
|
|
||||||
|
// Create the destination buffer
|
||||||
glGenBuffers( 1, &newBuffer );
|
glGenBuffers( 1, &newBuffer );
|
||||||
glBindBuffer( GL_COPY_WRITE_BUFFER, newBuffer );
|
|
||||||
glBufferData( GL_COPY_WRITE_BUFFER, aNewSize * VertexSize, NULL, GL_DYNAMIC_DRAW );
|
// It would be best to use GL_COPY_WRITE_BUFFER here,
|
||||||
glBindBuffer( GL_ARRAY_BUFFER, m_glBufferHandle );
|
// but it is not available everywhere
|
||||||
checkGlError( "resizing vertex buffer" );
|
#ifdef __WXDEBUG__
|
||||||
|
GLint eaBuffer = -1;
|
||||||
|
glGetIntegerv( GL_ELEMENT_ARRAY_BUFFER_BINDING, &eaBuffer );
|
||||||
|
assert( eaBuffer == 0 );
|
||||||
|
#endif /* __WXDEBUG__ */
|
||||||
|
glBindBuffer( GL_ELEMENT_ARRAY_BUFFER, newBuffer );
|
||||||
|
glBufferData( GL_ELEMENT_ARRAY_BUFFER, aNewSize * VertexSize, NULL, GL_DYNAMIC_DRAW );
|
||||||
|
checkGlError( "creating buffer during defragmentation" );
|
||||||
|
|
||||||
// Special case: the container is either already defragmented or filled up to its capacity,
|
// Special case: the container is either already defragmented or filled up to its capacity,
|
||||||
// so we just resize it and move the current data
|
// so we just resize it and move the current data
|
||||||
|
@ -439,7 +450,7 @@ bool CACHED_CONTAINER::defragmentResize( unsigned int aNewSize )
|
||||||
{
|
{
|
||||||
assert( aNewSize != m_currentSize );
|
assert( aNewSize != m_currentSize );
|
||||||
|
|
||||||
glCopyBufferSubData( GL_ARRAY_BUFFER, GL_COPY_WRITE_BUFFER,
|
glCopyBufferSubData( GL_ARRAY_BUFFER, GL_ELEMENT_ARRAY_BUFFER,
|
||||||
0, 0, usedSpace() * VertexSize );
|
0, 0, usedSpace() * VertexSize );
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -454,7 +465,7 @@ bool CACHED_CONTAINER::defragmentResize( unsigned int aNewSize )
|
||||||
int itemSize = item->GetSize();
|
int itemSize = item->GetSize();
|
||||||
|
|
||||||
// Move an item to the new container
|
// Move an item to the new container
|
||||||
glCopyBufferSubData( GL_ARRAY_BUFFER, GL_COPY_WRITE_BUFFER,
|
glCopyBufferSubData( GL_ARRAY_BUFFER, GL_ELEMENT_ARRAY_BUFFER,
|
||||||
itemOffset * VertexSize, newOffset * VertexSize, itemSize * VertexSize );
|
itemOffset * VertexSize, newOffset * VertexSize, itemSize * VertexSize );
|
||||||
|
|
||||||
// Update new offset
|
// Update new offset
|
||||||
|
@ -466,15 +477,18 @@ bool CACHED_CONTAINER::defragmentResize( unsigned int aNewSize )
|
||||||
}
|
}
|
||||||
|
|
||||||
// Cleanup
|
// Cleanup
|
||||||
glBindBuffer( GL_COPY_WRITE_BUFFER, 0 );
|
glBindBuffer( GL_ELEMENT_ARRAY_BUFFER, 0 );
|
||||||
glBindBuffer( GL_ARRAY_BUFFER, 0 );
|
glBindBuffer( GL_ARRAY_BUFFER, 0 );
|
||||||
|
// Previously we have unmapped the array buffer, now when it is also
|
||||||
|
// unbound, it may be officially marked as unmapped
|
||||||
|
m_isMapped = false;
|
||||||
glDeleteBuffers( 1, &m_glBufferHandle );
|
glDeleteBuffers( 1, &m_glBufferHandle );
|
||||||
|
|
||||||
// Switch to the new vertex buffer
|
// Switch to the new vertex buffer
|
||||||
m_glBufferHandle = newBuffer;
|
m_glBufferHandle = newBuffer;
|
||||||
glBindBuffer( GL_ARRAY_BUFFER, m_glBufferHandle );
|
glBindBuffer( GL_ARRAY_BUFFER, m_glBufferHandle );
|
||||||
checkGlError( "switching buffers during defragmentation" );
|
|
||||||
Map();
|
Map();
|
||||||
|
checkGlError( "switching buffers during defragmentation" );
|
||||||
|
|
||||||
#ifdef __WXDEBUG__
|
#ifdef __WXDEBUG__
|
||||||
prof_end( &totalTime );
|
prof_end( &totalTime );
|
||||||
|
|
Loading…
Reference in New Issue