From 6b3786457f5881a752de04150f964de7d4c0398d Mon Sep 17 00:00:00 2001 From: Stephen Just Date: Tue, 19 Aug 2014 16:08:27 -0600 Subject: [PATCH] Fix OpenGL extension detection on Linux/Mesa. Created function in glwrap to test whether a GL extension is available. This required using OpenGL3's glGetStringi. Backwards compat code can be added to function if necessary. --- src/graphics/glwrap.cpp | 16 ++++++++++++++++ src/graphics/glwrap.hpp | 3 +++ src/graphics/irr_driver.cpp | 6 +++--- 3 files changed, 22 insertions(+), 3 deletions(-) diff --git a/src/graphics/glwrap.cpp b/src/graphics/glwrap.cpp index 6cddac011..13da4236b 100644 --- a/src/graphics/glwrap.cpp +++ b/src/graphics/glwrap.cpp @@ -1213,3 +1213,19 @@ void GL32_draw2DRectangle(video::SColor color, const core::rect& position, glGetError(); } + +bool hasGLExtension(const char* extension) { + GLint numExtensions = 0; + glGetIntegerv(GL_NUM_EXTENSIONS, &numExtensions); + Log::debug("GLWrap", "Found %d OpenGL Extensions", numExtensions); + for (GLint i = 0; i < numExtensions; i++) { + const char* foundExtension = + (const char*) glGetStringi(GL_EXTENSIONS, i); + if (foundExtension && strcmp(foundExtension, extension) == 0) { + Log::debug("GLWrap", "Extension %s found", extension); + return true; + } + } + Log::debug("GLWrap", "Extension %s not found", extension); + return false; +} diff --git a/src/graphics/glwrap.hpp b/src/graphics/glwrap.hpp index dea33ae85..20d0f425d 100644 --- a/src/graphics/glwrap.hpp +++ b/src/graphics/glwrap.hpp @@ -162,4 +162,7 @@ void draw2DImage(const irr::video::ITexture* texture, const irr::core::rect void GL32_draw2DRectangle(irr::video::SColor color, const irr::core::rect& position, const irr::core::rect* clip = 0); + +bool hasGLExtension(const char* extension); + #endif diff --git a/src/graphics/irr_driver.cpp b/src/graphics/irr_driver.cpp index 5bcf11334..2ccf581d2 100644 --- a/src/graphics/irr_driver.cpp +++ b/src/graphics/irr_driver.cpp @@ -486,9 +486,9 @@ void IrrDriver::initDevice() // Default false value for hasVSLayer if --no-graphics argument is used if (!ProfileWorld::isNoGraphics()) { - const GLubyte *extensions = glGetString(GL_EXTENSIONS); - if (extensions && strstr((const char*)extensions, "GL_AMD_vertex_shader_layer") != NULL) - hasVSLayer = true; + if (hasGLExtension("GL_AMD_vertex_shader_layer")) { + hasVSLayer = true; + } }