From 3132690c0b05e0ef25551c5c67928cbabbf2f13e Mon Sep 17 00:00:00 2001 From: Paulo Henrique Silva Date: Sat, 13 Sep 2014 19:31:40 +0200 Subject: [PATCH] Fix slow opengl canvas on Mac OS 10.9. --- common/gal/opengl/gpu_manager.cpp | 8 +++++++- include/gal/opengl/gpu_manager.h | 3 +++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/common/gal/opengl/gpu_manager.cpp b/common/gal/opengl/gpu_manager.cpp index 25cd5fa418..36d66a0f60 100644 --- a/common/gal/opengl/gpu_manager.cpp +++ b/common/gal/opengl/gpu_manager.cpp @@ -94,6 +94,7 @@ GPU_CACHED_MANAGER::~GPU_CACHED_MANAGER() { glBindBuffer( GL_ARRAY_BUFFER, 0 ); glDeleteBuffers( 1, &m_verticesBuffer ); + glDeleteBuffers( 1, &m_indicesBuffer ); } } @@ -105,6 +106,7 @@ void GPU_CACHED_MANAGER::Initialize() if( !m_buffersInitialized ) { glGenBuffers( 1, &m_verticesBuffer ); + glGenBuffers( 1, &m_indicesBuffer ); m_buffersInitialized = true; } } @@ -167,9 +169,13 @@ void GPU_CACHED_MANAGER::EndDrawing() VertexSize, (GLvoid*) ShaderOffset ); } - glDrawElements( GL_TRIANGLES, m_indicesSize, GL_UNSIGNED_INT, (GLvoid*) m_indices.get() ); + glBindBuffer( GL_ELEMENT_ARRAY_BUFFER, m_indicesBuffer ); + glBufferData( GL_ELEMENT_ARRAY_BUFFER, m_indicesSize * sizeof(int), (GLvoid*) m_indices.get(), GL_DYNAMIC_DRAW ); + + glDrawElements( GL_TRIANGLES, m_indicesSize, GL_UNSIGNED_INT, 0 ); glBindBuffer( GL_ARRAY_BUFFER, 0 ); + glBindBuffer( GL_ELEMENT_ARRAY_BUFFER, 0 ); // Deactivate vertex array glDisableClientState( GL_COLOR_ARRAY ); diff --git a/include/gal/opengl/gpu_manager.h b/include/gal/opengl/gpu_manager.h index 7415ac5cfc..870834f253 100644 --- a/include/gal/opengl/gpu_manager.h +++ b/include/gal/opengl/gpu_manager.h @@ -144,6 +144,9 @@ protected: ///> Handle to vertices buffer GLuint m_verticesBuffer; + ///> Handle to indices buffer + GLuint m_indicesBuffer; + ///> Number of indices stored in the indices buffer unsigned int m_indicesSize; };