summaryrefslogtreecommitdiff
path: root/src/opengl/qgl.cpp
diff options
context:
space:
mode:
authorSamuel Rødal <sroedal@trolltech.com>2010-05-26 16:39:02 +0200
committerSamuel Rødal <samuel.rodal@nokia.com>2011-04-05 09:10:36 +0200
commit2f59eaeee1fbe33d07b0e7d0747afd8658df95ac (patch)
tree900f0a504d26e901fb7134ed52179ec8617ccbe4 /src/opengl/qgl.cpp
parent07df7ee20a0f3027516ad03465a2fb7b7e38e864 (diff)
downloadqt4-tools-2f59eaeee1fbe33d07b0e7d0747afd8658df95ac.tar.gz
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
Diffstat (limited to 'src/opengl/qgl.cpp')
-rw-r--r--src/opengl/qgl.cpp59
1 files changed, 58 insertions, 1 deletions
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<const char *>(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<const char *>(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<const char *>(glGetString(GL_EXTENSIONS)));
+ QGLExtensionMatcher extensions;
Extensions glExtensions;
if (extensions.match("GL_ARB_texture_rectangle"))