Moved VERTEX_CONTAINERs intialization to the constructors
This commit is contained in:
parent
4ae29aa693
commit
c18d148589
|
@ -39,9 +39,15 @@
|
||||||
using namespace KIGFX;
|
using namespace KIGFX;
|
||||||
|
|
||||||
CACHED_CONTAINER_GPU::CACHED_CONTAINER_GPU( unsigned int aSize ) :
|
CACHED_CONTAINER_GPU::CACHED_CONTAINER_GPU( unsigned int aSize ) :
|
||||||
CACHED_CONTAINER( aSize ), m_isMapped( false ),
|
CACHED_CONTAINER( aSize ), m_isMapped( false ), m_glBufferHandle( -1 )
|
||||||
m_isInitialized( false ), m_glBufferHandle( -1 )
|
|
||||||
{
|
{
|
||||||
|
m_useCopyBuffer = GLEW_ARB_copy_buffer;
|
||||||
|
|
||||||
|
glGenBuffers( 1, &m_glBufferHandle );
|
||||||
|
glBindBuffer( GL_ARRAY_BUFFER, m_glBufferHandle );
|
||||||
|
glBufferData( GL_ARRAY_BUFFER, m_currentSize * VertexSize, NULL, GL_DYNAMIC_DRAW );
|
||||||
|
glBindBuffer( GL_ARRAY_BUFFER, 0 );
|
||||||
|
checkGlError( "allocating video memory for cached container" );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -50,8 +56,7 @@ CACHED_CONTAINER_GPU::~CACHED_CONTAINER_GPU()
|
||||||
if( m_isMapped )
|
if( m_isMapped )
|
||||||
Unmap();
|
Unmap();
|
||||||
|
|
||||||
if( m_isInitialized )
|
glDeleteBuffers( 1, &m_glBufferHandle );
|
||||||
glDeleteBuffers( 1, &m_glBufferHandle );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -59,9 +64,6 @@ void CACHED_CONTAINER_GPU::Map()
|
||||||
{
|
{
|
||||||
assert( !IsMapped() );
|
assert( !IsMapped() );
|
||||||
|
|
||||||
if( !m_isInitialized )
|
|
||||||
init();
|
|
||||||
|
|
||||||
glBindBuffer( GL_ARRAY_BUFFER, m_glBufferHandle );
|
glBindBuffer( GL_ARRAY_BUFFER, m_glBufferHandle );
|
||||||
m_vertices = static_cast<VERTEX*>( glMapBuffer( GL_ARRAY_BUFFER, GL_READ_WRITE ) );
|
m_vertices = static_cast<VERTEX*>( glMapBuffer( GL_ARRAY_BUFFER, GL_READ_WRITE ) );
|
||||||
checkGlError( "mapping vertices buffer" );
|
checkGlError( "mapping vertices buffer" );
|
||||||
|
@ -84,20 +86,6 @@ void CACHED_CONTAINER_GPU::Unmap()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void CACHED_CONTAINER_GPU::init()
|
|
||||||
{
|
|
||||||
m_useCopyBuffer = GLEW_ARB_copy_buffer;
|
|
||||||
|
|
||||||
glGenBuffers( 1, &m_glBufferHandle );
|
|
||||||
glBindBuffer( GL_ARRAY_BUFFER, m_glBufferHandle );
|
|
||||||
glBufferData( GL_ARRAY_BUFFER, m_currentSize * VertexSize, NULL, GL_DYNAMIC_DRAW );
|
|
||||||
glBindBuffer( GL_ARRAY_BUFFER, 0 );
|
|
||||||
checkGlError( "allocating video memory for cached container" );
|
|
||||||
|
|
||||||
m_isInitialized = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
bool CACHED_CONTAINER_GPU::defragmentResize( unsigned int aNewSize )
|
bool CACHED_CONTAINER_GPU::defragmentResize( unsigned int aNewSize )
|
||||||
{
|
{
|
||||||
if( !m_useCopyBuffer )
|
if( !m_useCopyBuffer )
|
||||||
|
|
|
@ -40,17 +40,18 @@
|
||||||
using namespace KIGFX;
|
using namespace KIGFX;
|
||||||
|
|
||||||
CACHED_CONTAINER_RAM::CACHED_CONTAINER_RAM( unsigned int aSize ) :
|
CACHED_CONTAINER_RAM::CACHED_CONTAINER_RAM( unsigned int aSize ) :
|
||||||
CACHED_CONTAINER( aSize ), m_isInitialized( false ), m_verticesBuffer( 0 )
|
CACHED_CONTAINER( aSize ), m_verticesBuffer( 0 )
|
||||||
{
|
{
|
||||||
|
glGenBuffers( 1, &m_verticesBuffer );
|
||||||
|
checkGlError( "generating vertices buffer" );
|
||||||
|
|
||||||
m_vertices = static_cast<VERTEX*>( malloc( aSize * VertexSize ) );
|
m_vertices = static_cast<VERTEX*>( malloc( aSize * VertexSize ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
CACHED_CONTAINER_RAM::~CACHED_CONTAINER_RAM()
|
CACHED_CONTAINER_RAM::~CACHED_CONTAINER_RAM()
|
||||||
{
|
{
|
||||||
if( m_isInitialized )
|
glDeleteBuffers( 1, &m_verticesBuffer );
|
||||||
glDeleteBuffers( 1, &m_verticesBuffer );
|
|
||||||
|
|
||||||
free( m_vertices );
|
free( m_vertices );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -60,13 +61,6 @@ void CACHED_CONTAINER_RAM::Unmap()
|
||||||
if( !m_dirty )
|
if( !m_dirty )
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if( !m_isInitialized )
|
|
||||||
{
|
|
||||||
glGenBuffers( 1, &m_verticesBuffer );
|
|
||||||
checkGlError( "generating vertices buffer" );
|
|
||||||
m_isInitialized = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
// 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" );
|
||||||
|
|
|
@ -60,22 +60,12 @@ protected:
|
||||||
///> Flag saying if vertex buffer is currently mapped
|
///> Flag saying if vertex buffer is currently mapped
|
||||||
bool m_isMapped;
|
bool m_isMapped;
|
||||||
|
|
||||||
///> Flag saying if the vertex buffer is initialized
|
|
||||||
bool m_isInitialized;
|
|
||||||
|
|
||||||
///> Vertex buffer handle
|
///> Vertex buffer handle
|
||||||
unsigned int m_glBufferHandle;
|
unsigned int m_glBufferHandle;
|
||||||
|
|
||||||
///> Flag saying whether it is safe to use glCopyBufferSubData
|
///> Flag saying whether it is safe to use glCopyBufferSubData
|
||||||
bool m_useCopyBuffer;
|
bool m_useCopyBuffer;
|
||||||
|
|
||||||
/**
|
|
||||||
* Function init()
|
|
||||||
* performs the GL vertex buffer initialization. It can be invoked only when an OpenGL context
|
|
||||||
* is bound.
|
|
||||||
*/
|
|
||||||
void init();
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Function defragmentResize()
|
* Function defragmentResize()
|
||||||
* removes empty spaces between chunks and optionally resizes the container.
|
* removes empty spaces between chunks and optionally resizes the container.
|
||||||
|
|
|
@ -66,9 +66,6 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
///> Flag saying if the vertex buffer is initialized
|
|
||||||
bool m_isInitialized;
|
|
||||||
|
|
||||||
///> Handle to vertices buffer
|
///> Handle to vertices buffer
|
||||||
GLuint m_verticesBuffer;
|
GLuint m_verticesBuffer;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue