diff --git a/src/Gui/GLBuffer.cpp b/src/Gui/GLBuffer.cpp index 1d8d0b6763..a00202c527 100644 --- a/src/Gui/GLBuffer.cpp +++ b/src/Gui/GLBuffer.cpp @@ -41,6 +41,8 @@ #include #include +#include + #include "GLBuffer.h" using namespace Gui; @@ -63,6 +65,21 @@ OpenGLBuffer::~OpenGLBuffer() destroy(); } +/*! + * \brief OpenGLBuffer::isVBOSupported returns if the OpenGL driver + * supports the VBO extension. + * When calling this function there must be a current OpenGL context. + * \return + */ +bool OpenGLBuffer::isVBOSupported() +{ + const GLubyte * str = glGetString(GL_EXTENSIONS); + if (!str) + return false; + std::string ext = reinterpret_cast(str); + return (ext.find("GL_ARB_vertex_buffer_object") != std::string::npos); +} + void OpenGLBuffer::setCurrentContext(uint32_t ctx) { currentContext = ctx; @@ -74,6 +91,9 @@ bool OpenGLBuffer::create() if (bufferId > 0) return true; + if (!cc_glglue_has_vertex_buffer_object(glue)) + return false; + cc_glglue_glGenBuffers(glue, 1, &bufferId); context = currentContext; return true; diff --git a/src/Gui/GLBuffer.h b/src/Gui/GLBuffer.h index 7aa1ace66f..5f2283df87 100644 --- a/src/Gui/GLBuffer.h +++ b/src/Gui/GLBuffer.h @@ -34,6 +34,8 @@ public: OpenGLBuffer(GLenum type); ~OpenGLBuffer(); + static bool isVBOSupported(); + void setCurrentContext(uint32_t ctx); bool create(); bool isCreated() const; diff --git a/src/Mod/Mesh/Gui/SoFCIndexedFaceSet.cpp b/src/Mod/Mesh/Gui/SoFCIndexedFaceSet.cpp index c41a381b4d..637302b8a3 100644 --- a/src/Mod/Mesh/Gui/SoFCIndexedFaceSet.cpp +++ b/src/Mod/Mesh/Gui/SoFCIndexedFaceSet.cpp @@ -106,8 +106,11 @@ bool MeshRenderer::Private::canRenderGLArray(SoGLRenderAction *action) const static bool init = false; static bool vboAvailable = false; if (!init) { - std::string ext = (const char*)(glGetString(GL_EXTENSIONS)); - vboAvailable = (ext.find("GL_ARB_vertex_buffer_object") != std::string::npos); + vboAvailable = Gui::OpenGLBuffer::isVBOSupported(); + if (!vboAvailable) { + SoDebugError::postInfo("MeshRenderer", + "GL_ARB_vertex_buffer_object extension not supported"); + } init = true; } @@ -483,7 +486,7 @@ void SoFCIndexedFaceSet::GLRender(SoGLRenderAction *action) // get the VBO status of the viewer SbBool useVBO = true; - //Gui::SoGLVBOActivatedElement::get(state, useVBO); + Gui::SoGLVBOActivatedElement::get(state, useVBO); // Check for a matching OpenGL context if (!render.canRenderGLArray(action))