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() );
|
||||
|
||||
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
|
||||
if( aNewSize < m_currentSize && usedSpace() > aNewSize )
|
||||
|
@ -426,11 +426,22 @@ bool CACHED_CONTAINER::defragmentResize( unsigned int aNewSize )
|
|||
|
||||
GLuint newBuffer;
|
||||
|
||||
// glCopyBufferSubData requires a buffer to be unmapped
|
||||
glUnmapBuffer( GL_ARRAY_BUFFER );
|
||||
|
||||
// Create the destination buffer
|
||||
glGenBuffers( 1, &newBuffer );
|
||||
glBindBuffer( GL_COPY_WRITE_BUFFER, newBuffer );
|
||||
glBufferData( GL_COPY_WRITE_BUFFER, aNewSize * VertexSize, NULL, GL_DYNAMIC_DRAW );
|
||||
glBindBuffer( GL_ARRAY_BUFFER, m_glBufferHandle );
|
||||
checkGlError( "resizing vertex buffer" );
|
||||
|
||||
// It would be best to use GL_COPY_WRITE_BUFFER here,
|
||||
// but it is not available everywhere
|
||||
#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,
|
||||
// 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 );
|
||||
|
||||
glCopyBufferSubData( GL_ARRAY_BUFFER, GL_COPY_WRITE_BUFFER,
|
||||
glCopyBufferSubData( GL_ARRAY_BUFFER, GL_ELEMENT_ARRAY_BUFFER,
|
||||
0, 0, usedSpace() * VertexSize );
|
||||
}
|
||||
else
|
||||
|
@ -454,7 +465,7 @@ bool CACHED_CONTAINER::defragmentResize( unsigned int aNewSize )
|
|||
int itemSize = item->GetSize();
|
||||
|
||||
// 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 );
|
||||
|
||||
// Update new offset
|
||||
|
@ -466,15 +477,18 @@ bool CACHED_CONTAINER::defragmentResize( unsigned int aNewSize )
|
|||
}
|
||||
|
||||
// Cleanup
|
||||
glBindBuffer( GL_COPY_WRITE_BUFFER, 0 );
|
||||
glBindBuffer( GL_ELEMENT_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 );
|
||||
|
||||
// Switch to the new vertex buffer
|
||||
m_glBufferHandle = newBuffer;
|
||||
glBindBuffer( GL_ARRAY_BUFFER, m_glBufferHandle );
|
||||
checkGlError( "switching buffers during defragmentation" );
|
||||
Map();
|
||||
checkGlError( "switching buffers during defragmentation" );
|
||||
|
||||
#ifdef __WXDEBUG__
|
||||
prof_end( &totalTime );
|
||||
|
|
Loading…
Reference in New Issue