From c18d148589724515cae4c513addb3cb5416589fd Mon Sep 17 00:00:00 2001 From: Maciej Suminski Date: Tue, 8 Aug 2017 15:33:57 +0200 Subject: [PATCH] Moved VERTEX_CONTAINERs intialization to the constructors --- common/gal/opengl/cached_container_gpu.cpp | 30 +++++++--------------- common/gal/opengl/cached_container_ram.cpp | 16 ++++-------- include/gal/opengl/cached_container_gpu.h | 10 -------- include/gal/opengl/cached_container_ram.h | 3 --- 4 files changed, 14 insertions(+), 45 deletions(-) diff --git a/common/gal/opengl/cached_container_gpu.cpp b/common/gal/opengl/cached_container_gpu.cpp index 68a625a397..9ccf972b64 100644 --- a/common/gal/opengl/cached_container_gpu.cpp +++ b/common/gal/opengl/cached_container_gpu.cpp @@ -39,9 +39,15 @@ using namespace KIGFX; CACHED_CONTAINER_GPU::CACHED_CONTAINER_GPU( unsigned int aSize ) : - CACHED_CONTAINER( aSize ), m_isMapped( false ), - m_isInitialized( false ), m_glBufferHandle( -1 ) + CACHED_CONTAINER( aSize ), m_isMapped( 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 ) Unmap(); - if( m_isInitialized ) - glDeleteBuffers( 1, &m_glBufferHandle ); + glDeleteBuffers( 1, &m_glBufferHandle ); } @@ -59,9 +64,6 @@ void CACHED_CONTAINER_GPU::Map() { assert( !IsMapped() ); - if( !m_isInitialized ) - init(); - glBindBuffer( GL_ARRAY_BUFFER, m_glBufferHandle ); m_vertices = static_cast( glMapBuffer( GL_ARRAY_BUFFER, GL_READ_WRITE ) ); 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 ) { if( !m_useCopyBuffer ) diff --git a/common/gal/opengl/cached_container_ram.cpp b/common/gal/opengl/cached_container_ram.cpp index a980d5a1ec..a7109545cb 100644 --- a/common/gal/opengl/cached_container_ram.cpp +++ b/common/gal/opengl/cached_container_ram.cpp @@ -40,17 +40,18 @@ using namespace KIGFX; 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( malloc( aSize * VertexSize ) ); } CACHED_CONTAINER_RAM::~CACHED_CONTAINER_RAM() { - if( m_isInitialized ) - glDeleteBuffers( 1, &m_verticesBuffer ); - + glDeleteBuffers( 1, &m_verticesBuffer ); free( m_vertices ); } @@ -60,13 +61,6 @@ void CACHED_CONTAINER_RAM::Unmap() if( !m_dirty ) return; - if( !m_isInitialized ) - { - glGenBuffers( 1, &m_verticesBuffer ); - checkGlError( "generating vertices buffer" ); - m_isInitialized = true; - } - // Upload vertices coordinates and shader types to GPU memory glBindBuffer( GL_ARRAY_BUFFER, m_verticesBuffer ); checkGlError( "binding vertices buffer" ); diff --git a/include/gal/opengl/cached_container_gpu.h b/include/gal/opengl/cached_container_gpu.h index 7278e58456..7d85d4e23d 100644 --- a/include/gal/opengl/cached_container_gpu.h +++ b/include/gal/opengl/cached_container_gpu.h @@ -60,22 +60,12 @@ protected: ///> Flag saying if vertex buffer is currently mapped bool m_isMapped; - ///> Flag saying if the vertex buffer is initialized - bool m_isInitialized; - ///> Vertex buffer handle unsigned int m_glBufferHandle; ///> Flag saying whether it is safe to use glCopyBufferSubData 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() * removes empty spaces between chunks and optionally resizes the container. diff --git a/include/gal/opengl/cached_container_ram.h b/include/gal/opengl/cached_container_ram.h index 474fe75b2e..b4180ca50c 100644 --- a/include/gal/opengl/cached_container_ram.h +++ b/include/gal/opengl/cached_container_ram.h @@ -66,9 +66,6 @@ public: } protected: - ///> Flag saying if the vertex buffer is initialized - bool m_isInitialized; - ///> Handle to vertices buffer GLuint m_verticesBuffer;