From 46212d657e2e989dddd361a732e65b05748e8e91 Mon Sep 17 00:00:00 2001 From: Sean Harmer Date: Fri, 20 Jul 2012 16:21:47 +0100 Subject: Improve the QOpenGLExtensionMatcher class MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Using a QSet internally means that checking for the presence of an extension no longer uses an O(N) search. This patch also allows users of this class to easily get a list of the supported extensions. Change-Id: I02194e5345573c47be0876f3ea6eb6b69a2ead81 Reviewed-by: Samuel Rødal Reviewed-by: Gunnar Sletta --- src/gui/opengl/qopengl.cpp | 33 ++++----------------------------- 1 file changed, 4 insertions(+), 29 deletions(-) (limited to 'src/gui/opengl/qopengl.cpp') diff --git a/src/gui/opengl/qopengl.cpp b/src/gui/opengl/qopengl.cpp index 290fcb287e..ce6cb8a691 100644 --- a/src/gui/opengl/qopengl.cpp +++ b/src/gui/opengl/qopengl.cpp @@ -46,11 +46,6 @@ QT_BEGIN_NAMESPACE -QOpenGLExtensionMatcher::QOpenGLExtensionMatcher(const char *str) -{ - init(str); -} - typedef const GLubyte * (QOPENGLF_APIENTRYP qt_glGetStringi)(GLenum, GLuint); #ifndef GL_NUM_EXTENSIONS @@ -62,7 +57,9 @@ QOpenGLExtensionMatcher::QOpenGLExtensionMatcher() const char *extensionStr = reinterpret_cast(glGetString(GL_EXTENSIONS)); if (extensionStr) { - init(extensionStr); + QByteArray ba(extensionStr); + QList extensions = ba.split(' '); + m_extensions = extensions.toSet(); } else { // clear error state while (glGetError()) {} @@ -79,32 +76,10 @@ QOpenGLExtensionMatcher::QOpenGLExtensionMatcher() for (int i = 0; i < numExtensions; ++i) { const char *str = reinterpret_cast(glGetStringi(GL_EXTENSIONS, i)); - - m_offsets << m_extensions.size(); - - while (*str != 0) - m_extensions.append(*str++); - m_extensions.append(' '); + m_extensions.insert(str); } } } } -void QOpenGLExtensionMatcher::init(const char *str) -{ - m_extensions = str; - - // make sure extension string ends with a space - if (!m_extensions.endsWith(' ')) - m_extensions.append(' '); - - int index = 0; - int next = 0; - while ((next = m_extensions.indexOf(' ', index)) >= 0) { - m_offsets << index; - index = next + 1; - } -} - - QT_END_NAMESPACE -- cgit v1.2.3