From 2f59eaeee1fbe33d07b0e7d0747afd8658df95ac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Samuel=20R=C3=B8dal?= Date: Wed, 26 May 2010 16:39:02 +0200 Subject: Made extension resolving work with Core profile. The Core profile was introduced in OpenGL 3.2 and if chosen removes all deprecated functionality from the OpenGL API. In the Core profile glGetString(GL_EXTENSIONS) is unsupported, so instead we need to use glGetStringi(GL_EXTENSIONS, index) together with glGetIntegerv(GL_NUM_EXTENSIONS). Also optimized the QGLExtensionMatcher to not have to recompute the split positions all the time. Preliminary support to prevent non-core-functions to be called in the GL 2 engine has also been added. Reviewed-by: Kim --- src/opengl/qgl.cpp | 59 +++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 58 insertions(+), 1 deletion(-) (limited to 'src/opengl/qgl.cpp') diff --git a/src/opengl/qgl.cpp b/src/opengl/qgl.cpp index 684116c8b0..b3b459ddca 100644 --- a/src/opengl/qgl.cpp +++ b/src/opengl/qgl.cpp @@ -5359,12 +5359,69 @@ QGLWidget::QGLWidget(QGLContext *context, QWidget *parent, #endif // QT3_SUPPORT +typedef GLubyte * (*qt_glGetStringi)(GLenum, GLuint); + +#ifndef GL_NUM_EXTENSIONS +#define GL_NUM_EXTENSIONS 0x821D +#endif + +QGLExtensionMatcher::QGLExtensionMatcher(const char *str) +{ + init(str); +} + +QGLExtensionMatcher::QGLExtensionMatcher() +{ + const char *extensionStr = reinterpret_cast(glGetString(GL_EXTENSIONS)); + + if (extensionStr) { + init(extensionStr); + } else { + // clear error state + while (glGetError()) {} + + const QGLContext *ctx = QGLContext::currentContext(); + if (ctx) { + qt_glGetStringi glGetStringi = (qt_glGetStringi)ctx->getProcAddress(QLatin1String("glGetStringi")); + + GLint numExtensions; + glGetIntegerv(GL_NUM_EXTENSIONS, &numExtensions); + + 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(' '); + } + } + } +} + +void QGLExtensionMatcher::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; + } +} + /* Returns the GL extensions for the current context. */ QGLExtensions::Extensions QGLExtensions::currentContextExtensions() { - QGLExtensionMatcher extensions(reinterpret_cast(glGetString(GL_EXTENSIONS))); + QGLExtensionMatcher extensions; Extensions glExtensions; if (extensions.match("GL_ARB_texture_rectangle")) -- cgit v1.2.1