summaryrefslogtreecommitdiffstats
path: root/src/gui/kernel/qopenglcontext.h
diff options
context:
space:
mode:
authorSean Harmer <sean.harmer@kdab.com>2012-09-22 16:34:21 +0100
committerThe Qt Project <gerrit-noreply@qt-project.org>2013-02-26 16:27:30 +0100
commit10aa64d74c0208ed9f42e88e6deb3000e9cad6df (patch)
tree4fb87da458d75f728c862fd3c34c483438249a14 /src/gui/kernel/qopenglcontext.h
parent4b1332783e16423b3b2c54125b130247ee6bc5b2 (diff)
OpenGL: Add a set of version and context specific OpenGL classes
This commit adds part of the output of utils/glgen and some simple modifications to QOpenGLContext to allow easy access to classes containing functions specific to a given OpenGL context and version. This allows compile-time detection of mis-use of OpenGL features. For example, trying to use glBegin(GL_TRIANGLES) with an OpenGL 3.2 Core Profile context will be detected by the compiler rather than at runtime. These capabilities make it much easier to add functionality to Qt and applications that relies upon core features of OpenGL from specific versions e.g. geometry shaders. Change-Id: Ieb584a489792595f831bc77dee84935c03bb5a64 Reviewed-by: Samuel Rødal <samuel.rodal@digia.com>
Diffstat (limited to 'src/gui/kernel/qopenglcontext.h')
-rw-r--r--src/gui/kernel/qopenglcontext.h63
1 files changed, 63 insertions, 0 deletions
diff --git a/src/gui/kernel/qopenglcontext.h b/src/gui/kernel/qopenglcontext.h
index e8d04d7446..52b4a2da28 100644
--- a/src/gui/kernel/qopenglcontext.h
+++ b/src/gui/kernel/qopenglcontext.h
@@ -58,6 +58,10 @@
#endif
#include <QtGui/qopengl.h>
+#include <QtGui/qopenglversionfunctions.h>
+
+#include <QtCore/qhash.h>
+#include <QtCore/qpair.h>
QT_BEGIN_NAMESPACE
@@ -69,6 +73,50 @@ class QPlatformOpenGLContext;
class QScreen;
class QSurface;
+class QOpenGLVersionProfilePrivate;
+
+class Q_GUI_EXPORT QOpenGLVersionProfile
+{
+public:
+ QOpenGLVersionProfile();
+ explicit QOpenGLVersionProfile(const QSurfaceFormat &format);
+ QOpenGLVersionProfile(const QOpenGLVersionProfile &other);
+ ~QOpenGLVersionProfile();
+
+ QOpenGLVersionProfile &operator=(const QOpenGLVersionProfile &rhs);
+
+ QPair<int, int> version() const;
+ void setVersion(int majorVersion, int minorVersion);
+
+ QSurfaceFormat::OpenGLContextProfile profile() const;
+ void setProfile(QSurfaceFormat::OpenGLContextProfile profile);
+
+ bool hasProfiles() const;
+ bool isLegacyVersion() const;
+ bool isValid() const;
+
+private:
+ QOpenGLVersionProfilePrivate* d;
+};
+
+inline uint qHash(const QOpenGLVersionProfile &v, uint seed)
+{
+ return qHash(static_cast<int>(v.profile() * 1000)
+ + v.version().first * 100 + v.version().second * 10, seed);
+}
+
+inline bool operator==(const QOpenGLVersionProfile &lhs, const QOpenGLVersionProfile &rhs)
+{
+ if (lhs.profile() != rhs.profile())
+ return false;
+ return lhs.version() == rhs.version();
+}
+
+inline bool operator!=(const QOpenGLVersionProfile &lhs, const QOpenGLVersionProfile &rhs)
+{
+ return !operator==(lhs, rhs);
+}
+
class Q_GUI_EXPORT QOpenGLContextGroup : public QObject
{
Q_OBJECT
@@ -127,6 +175,15 @@ public:
QOpenGLFunctions *functions() const;
+ QAbstractOpenGLFunctions *versionFunctions(const QOpenGLVersionProfile &versionProfile = QOpenGLVersionProfile()) const;
+
+ template<class TYPE>
+ TYPE *versionFunctions() const
+ {
+ QOpenGLVersionProfile v = TYPE::versionProfile();
+ return static_cast<TYPE*>(versionFunctions(v));
+ }
+
QSet<QByteArray> extensions() const;
bool hasExtension(const QByteArray &extension) const;
@@ -147,11 +204,17 @@ private:
friend class QOpenGL2PaintEngineExPrivate;
friend class QSGDistanceFieldGlyphCache;
friend class QWidgetPrivate;
+ friend class QAbstractOpenGLFunctionsPrivate;
void *qGLContextHandle() const;
void setQGLContextHandle(void *handle,void (*qGLContextDeleteFunction)(void *));
void deleteQGLContext();
+ QOpenGLVersionFunctionsBackend* functionsBackend(const QOpenGLVersionStatus &v) const;
+ void insertFunctionsBackend(const QOpenGLVersionStatus &v,
+ QOpenGLVersionFunctionsBackend *backend);
+ void removeFunctionsBackend(const QOpenGLVersionStatus &v);
+
void destroy();
};